Introduce a new `getMinecraftVersions` function to fetch Minecraft versions from CurseForge with caching, along with its Zod schema and exports. Refactor the publishing system to use a unified `PlatformAdaptor` interface, replace the old `PlatformContext` type, and update the publish flow to compute version ranges and pass files as structured objects. Improve `resolveVersionName` to accept a full config object and rework `buildJarPath` to use a Template instance. Add server functions to retrieve filtered MC version lists for both Modrinth and CurseForge.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { curseforgeClient } from "@/services/clients";
|
|
import { uploadFile, getGameVersions } from "@/lib/curseforge";
|
|
import { resolveVersionName } from "@/lib/utils/format";
|
|
import type { UploadMetadata } from "@/types";
|
|
import { PlatformPublishFn } from "../publish.schemas";
|
|
|
|
export const publishCurseForgeVersion: PlatformPublishFn = async (ctx, mcVersion, files) => {
|
|
const { input, config } = ctx;
|
|
|
|
const displayName = resolveVersionName(config.curseforge.version_name, config, input.version, mcVersion);
|
|
|
|
const gameVersions = await getGameVersions(curseforgeClient);
|
|
|
|
const resolveId = (name: string): number => {
|
|
const found = gameVersions.find((v) => v.name === name);
|
|
if (!found) throw new Error(`Game version "${name}" not found in CurseForge`);
|
|
return found.id;
|
|
};
|
|
|
|
const metadata: UploadMetadata = {
|
|
changelog: input.changelog,
|
|
changelogType: "markdown",
|
|
displayName,
|
|
releaseType: input.versionType,
|
|
gameVersions: [
|
|
...config.curseforge.loaders.map(resolveId),
|
|
...config.curseforge.environment.map(resolveId),
|
|
...mcVersion.range.map(resolveId),
|
|
],
|
|
relations: config.curseforge.relations,
|
|
};
|
|
|
|
await uploadFile(
|
|
curseforgeClient,
|
|
config.curseforge.project_id,
|
|
metadata,
|
|
files.primary,
|
|
);
|
|
}
|