mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 16:22:39 +10:00
feat: import of custom platforms & file extensions
This commit is contained in:
@ -14,16 +14,6 @@ export default defineEventHandler(async (h3) => {
|
||||
},
|
||||
include: {
|
||||
versions: {
|
||||
where: {
|
||||
gameVersion: {
|
||||
isNot: null,
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
gameVersion: {
|
||||
versionIndex: "asc",
|
||||
},
|
||||
},
|
||||
omit: {
|
||||
dropletManifest: true,
|
||||
},
|
||||
|
||||
@ -16,7 +16,7 @@ export const ImportRedist = type({
|
||||
"platform?": type({
|
||||
name: "string",
|
||||
icon: "string",
|
||||
fileExts: type("string").pipe.try((s) => JSON.parse(s), type("string[]")),
|
||||
fileExts: type("string").pipe.try((s) => JSON.parse(s), type("string.alphanumeric").array()),
|
||||
}),
|
||||
});
|
||||
|
||||
@ -78,7 +78,7 @@ export default defineEventHandler(async (h3) => {
|
||||
create: {
|
||||
platformName: options.platform.name,
|
||||
iconSvg: svgContent,
|
||||
fileExtensions: options.platform.fileExts,
|
||||
fileExtensions: options.platform.fileExts.map((v) => `.${v}`),
|
||||
},
|
||||
}
|
||||
: undefined),
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
import { type } from "arktype";
|
||||
import { Platform } from "~/prisma/client/enums";
|
||||
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import libraryManager from "~/server/internal/library";
|
||||
import { convertIDToLink } from "~/server/internal/platform/link";
|
||||
|
||||
export const LaunchCommands = type({
|
||||
name: "string > 0",
|
||||
description: "string = ''",
|
||||
launchCommand: "string > 0",
|
||||
launchArgs: "string = ''",
|
||||
}).array();
|
||||
name: "string > 0",
|
||||
description: "string = ''",
|
||||
launchCommand: "string > 0",
|
||||
launchArgs: "string = ''",
|
||||
}).array();
|
||||
|
||||
export const ImportVersion = type({
|
||||
id: "string",
|
||||
version: "string",
|
||||
name: "string?",
|
||||
|
||||
platform: type.valueOf(Platform),
|
||||
platform: "string",
|
||||
setup: "string = ''",
|
||||
setupArgs: "string = ''",
|
||||
onlySetup: "boolean = false",
|
||||
@ -33,11 +33,18 @@ export default defineEventHandler(async (h3) => {
|
||||
|
||||
const body = await readDropValidatedBody(h3, ImportVersion);
|
||||
|
||||
const platform = await convertIDToLink(body.platform);
|
||||
if (!platform)
|
||||
throw createError({ statusCode: 400, message: "Invalid platform." });
|
||||
|
||||
if (body.delta) {
|
||||
const validOverlayVersions = await prisma.gameVersion.count({
|
||||
where: {
|
||||
version: { gameId: body.id, platform: body.platform },
|
||||
version: {
|
||||
gameId: body.id,
|
||||
},
|
||||
delta: false,
|
||||
platform,
|
||||
},
|
||||
});
|
||||
if (validOverlayVersions == 0)
|
||||
|
||||
11
server/api/v1/admin/import/version/platforms.get.ts
Normal file
11
server/api/v1/admin/import/version/platforms.get.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import aclManager from "~/server/internal/acls"
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["import:version:read"]);
|
||||
if(!allowed) throw createError({statusCode: 403});
|
||||
|
||||
const userPlatforms = await prisma.userPlatform.findMany({});
|
||||
|
||||
return userPlatforms;
|
||||
})
|
||||
@ -1,5 +1,6 @@
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import { convertIDsToPlatforms } from "~/server/internal/platform/link";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const userId = await aclManager.getUserIdACL(h3, ["store:read"]);
|
||||
@ -17,7 +18,11 @@ export default defineEventHandler(async (h3) => {
|
||||
include: {
|
||||
versions: {
|
||||
include: {
|
||||
userPlatform: true,
|
||||
gameVersions: {
|
||||
include: {
|
||||
platform: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
publishers: {
|
||||
@ -40,8 +45,7 @@ export default defineEventHandler(async (h3) => {
|
||||
},
|
||||
});
|
||||
|
||||
if (!game)
|
||||
throw createError({ statusCode: 404, message: "Game not found" });
|
||||
if (!game) throw createError({ statusCode: 404, message: "Game not found" });
|
||||
|
||||
const rating = await prisma.gameRating.aggregate({
|
||||
where: {
|
||||
@ -55,5 +59,18 @@ export default defineEventHandler(async (h3) => {
|
||||
},
|
||||
});
|
||||
|
||||
return { game, rating };
|
||||
const platformIDs = game.versions
|
||||
.map((e) => e.gameVersions)
|
||||
.flat()
|
||||
.map((e) => e.platform)
|
||||
.flat()
|
||||
.map((e) => e.id)
|
||||
.filter((e) => e !== null)
|
||||
.filter((v, index, arr) => arr.findIndex((k) => k == v) == index);
|
||||
|
||||
const platforms = await convertIDsToPlatforms(platformIDs);
|
||||
|
||||
const noVersionsGame = { ...game, versions: undefined };
|
||||
|
||||
return { game: noVersionsGame, rating, platforms };
|
||||
});
|
||||
|
||||
@ -2,7 +2,6 @@ import { ArkErrors, type } from "arktype";
|
||||
import type { Prisma } from "~/prisma/client/client";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import { parsePlatform } from "~/server/internal/utils/parseplatform";
|
||||
|
||||
const StoreRead = type({
|
||||
skip: type("string")
|
||||
@ -45,18 +44,19 @@ export default defineEventHandler(async (h3) => {
|
||||
}
|
||||
: undefined;
|
||||
const platformFilter = options.platform
|
||||
? {
|
||||
? ({
|
||||
versions: {
|
||||
some: {
|
||||
platform: {
|
||||
in: options.platform
|
||||
.split(",")
|
||||
.map(parsePlatform)
|
||||
.filter((e) => e !== undefined),
|
||||
},
|
||||
gameVersions: {
|
||||
some: {
|
||||
platform: {
|
||||
id: options.platform
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
} satisfies Prisma.GameWhereInput)
|
||||
: undefined;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user