mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-21 04:01:10 +10:00
38 lines
994 B
TypeScript
38 lines
994 B
TypeScript
import { ArkErrors, type } from "arktype";
|
|
import aclManager from "~/server/internal/acls";
|
|
import libraryManager from "~/server/internal/library";
|
|
|
|
const Query = type({
|
|
id: "string",
|
|
version: "string",
|
|
});
|
|
|
|
/**
|
|
* Fetch recommendations for version import.
|
|
*/
|
|
export default defineEventHandler<{ query: typeof Query.infer }>(async (h3) => {
|
|
const allowed = await aclManager.allowSystemACL(h3, ["import:version:read"]);
|
|
if (!allowed) throw createError({ statusCode: 403 });
|
|
|
|
const query = Query(await getQuery(h3));
|
|
if (query instanceof ArkErrors)
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: "Invalid query: " + query.summary,
|
|
});
|
|
const gameId = query.id;
|
|
const versionName = query.version;
|
|
|
|
const preload = await libraryManager.fetchUnimportedVersionInformation(
|
|
gameId,
|
|
versionName,
|
|
);
|
|
if (!preload)
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: "Invalid game or version id/name",
|
|
});
|
|
|
|
return preload;
|
|
});
|