Dynamically map platform results in publish endpoint
This commit is contained in:
parent
ffcfa9c4f5
commit
b5555d5635
@ -51,10 +51,9 @@ export const PlatformResultSchema = z.object({
|
|||||||
errors: z.array(z.string()),
|
errors: z.array(z.string()),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const PublishResultSchema = z.object({
|
export const PublishResultSchema = z.object(Object.fromEntries(platforms.map(platform => [
|
||||||
modrinth: PlatformResultSchema,
|
platform, PlatformResultSchema
|
||||||
curseforge: PlatformResultSchema,
|
])));
|
||||||
});
|
|
||||||
|
|
||||||
// ── Inferred types ─────────────────────────────────────
|
// ── Inferred types ─────────────────────────────────────
|
||||||
|
|
||||||
|
|||||||
@ -134,19 +134,19 @@ export const appRouter = t.router({
|
|||||||
|
|
||||||
const ctx: PlatformContext = { input, config };
|
const ctx: PlatformContext = { input, config };
|
||||||
|
|
||||||
const [modrinthSettled, curseforgeSettled] = await Promise.allSettled(
|
const results = await Promise.all(platforms.map(async (platform) => {
|
||||||
platforms.map(platform => runPlatform(platform, input.mcVersions[platform], ctx))
|
try {
|
||||||
);
|
const result = await runPlatform(platform, input.mcVersions[platform], ctx);
|
||||||
|
return {platform, result};
|
||||||
|
} catch (err) {
|
||||||
|
return {
|
||||||
|
platform,
|
||||||
|
result: { success: 0, fail: 0, errors: [errorMessage(err)] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
const modrinth: PlatformResult = modrinthSettled.status === "fulfilled"
|
return Object.fromEntries(results.map(result => [result.platform, result.result]));
|
||||||
? modrinthSettled.value
|
|
||||||
: { success: 0, fail: 0, errors: [errorMessage(modrinthSettled.reason)] };
|
|
||||||
|
|
||||||
const curseforge: PlatformResult = curseforgeSettled.status === "fulfilled"
|
|
||||||
? curseforgeSettled.value
|
|
||||||
: { success: 0, fail: 0, errors: [errorMessage(curseforgeSettled.reason)] };
|
|
||||||
|
|
||||||
return { modrinth, curseforge };
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
progress: t.procedure.subscription(async function* (opts) {
|
progress: t.procedure.subscription(async function* (opts) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user