Refactor type-safe constants and extract utility helpers

This commit is contained in:
CPTProgrammer
2026-07-13 09:29:00 +08:00
parent 77b7db9dd1
commit 7aa84fd41e
10 changed files with 81 additions and 50 deletions
+6 -3
View File
@@ -10,6 +10,9 @@ import {
platforms,
type PlatformContext,
type PlatformAdaptor,
type PublishInput,
PublishResultSchema,
ProgressEventSchema,
} from "./publish.schemas";
import { publishModrinthVersion } from "./platforms/modrinth";
import { publishCurseForgeVersion } from "./platforms/curseforge";
@@ -44,7 +47,7 @@ const ee = new EventEmitter();
async function runPlatform(
platform: typeof platforms[number],
mcVersions: { mc_version: string }[],
mcVersions: PublishInput["mcVersions"][keyof PublishInput["mcVersions"]],
ctx: PlatformContext,
): Promise<PlatformResult> {
const result: PlatformResult = { success: 0, fail: 0, errors: [] };
@@ -146,14 +149,14 @@ export const appRouter = t.router({
}
}));
return Object.fromEntries(results.map(result => [result.platform, result.result]));
return PublishResultSchema.parse(Object.fromEntries(results.map(result => [result.platform, result.result])));
}),
progress: t.procedure.subscription(async function* (opts) {
for await (const [data] of on(ee, "progress", {
signal: opts.signal,
})) {
yield data as ProgressEvent;
yield ProgressEventSchema.parse(data);
}
}),
});