mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-16 17:51:17 +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;
|
||||
|
||||
/**
|
||||
|
||||
@ -20,7 +20,7 @@ class DownloadContextManager {
|
||||
where: {
|
||||
gameId: game,
|
||||
versionPath,
|
||||
gameVersion: {
|
||||
game: {
|
||||
isNot: null,
|
||||
},
|
||||
},
|
||||
|
||||
@ -55,47 +55,64 @@ class ManifestGenerator {
|
||||
async generateManifest(versionId: string) {
|
||||
const versions = [];
|
||||
|
||||
const baseVersion = await prisma.version.findUnique({
|
||||
const baseVersion = await prisma.gameVersion.findUnique({
|
||||
where: {
|
||||
versionId,
|
||||
version: {
|
||||
gameId: {
|
||||
not: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
include: {
|
||||
gameVersion: true,
|
||||
platform: true,
|
||||
version: {
|
||||
select: {
|
||||
gameId: true,
|
||||
dropletManifest: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!baseVersion) return undefined;
|
||||
versions.push(baseVersion);
|
||||
|
||||
// Collect other versions if this is a delta
|
||||
if (baseVersion.gameVersion?.delta) {
|
||||
if (baseVersion.delta) {
|
||||
// Start at the same index minus one, and keep grabbing them
|
||||
// until we run out or we hit something that isn't a delta
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
for (let i = baseVersion.gameVersion.versionIndex - 1; true; i--) {
|
||||
const currentVersion = await prisma.version.findFirst({
|
||||
for (let i = baseVersion.versionIndex - 1; true; i--) {
|
||||
const currentVersion = await prisma.gameVersion.findFirst({
|
||||
where: {
|
||||
gameId: baseVersion.gameId,
|
||||
platform: baseVersion.platform,
|
||||
gameVersion: {
|
||||
versionIndex: i,
|
||||
version: {
|
||||
gameId: baseVersion.version.gameId!,
|
||||
},
|
||||
platform: {
|
||||
id: baseVersion.platform.id,
|
||||
},
|
||||
versionIndex: i,
|
||||
},
|
||||
include: {
|
||||
gameVersion: true,
|
||||
version: {
|
||||
select: {
|
||||
dropletManifest: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!currentVersion) return undefined;
|
||||
versions.push(currentVersion);
|
||||
if (!currentVersion.gameVersion?.delta) break;
|
||||
if (!currentVersion?.delta) break;
|
||||
}
|
||||
}
|
||||
versions.reverse();
|
||||
const metadata: DropManifestMetadata[] = versions.map((version) => {
|
||||
const metadata: DropManifestMetadata[] = versions.map((gameVersion) => {
|
||||
return {
|
||||
manifest: JSON.parse(
|
||||
version.dropletManifest?.toString() ?? "{}",
|
||||
gameVersion.version.dropletManifest?.toString() ?? "{}",
|
||||
) as DropManifest,
|
||||
versionId: version.versionId,
|
||||
versionId: gameVersion.versionId,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@ -9,13 +9,12 @@ import path from "path";
|
||||
import prisma from "../db/database";
|
||||
import { fuzzy } from "fast-fuzzy";
|
||||
import taskHandler from "../tasks";
|
||||
import { parsePlatform } from "../utils/parseplatform";
|
||||
import notificationSystem from "../notifications";
|
||||
import { GameNotFoundError, type LibraryProvider } from "./provider";
|
||||
import { logger } from "../logging";
|
||||
import { createHash } from "node:crypto";
|
||||
import type { ImportVersion } from "~/server/api/v1/admin/import/version/index.post";
|
||||
import type { LaunchOptionCreateManyGameVersionInput } from "~/prisma/client/models";
|
||||
import type { LaunchOptionCreateManyInput } from "~/prisma/client/models";
|
||||
|
||||
export function createGameImportTaskId(libraryId: string, libraryPath: string) {
|
||||
return createHash("md5")
|
||||
@ -221,6 +220,8 @@ class LibraryManager {
|
||||
const library = this.libraries.get(game.libraryId);
|
||||
if (!library) return undefined;
|
||||
|
||||
const userPlatforms = await prisma.userPlatform.findMany({});
|
||||
|
||||
const fileExts: { [key: string]: string[] } = {
|
||||
Linux: [
|
||||
// Ext for Unity games
|
||||
@ -239,6 +240,12 @@ class LibraryManager {
|
||||
],
|
||||
};
|
||||
|
||||
for (const platform of userPlatforms) {
|
||||
fileExts[platform.id] = platform.fileExtensions;
|
||||
}
|
||||
|
||||
console.log(fileExts);
|
||||
|
||||
const options: Array<{
|
||||
filename: string;
|
||||
platform: string;
|
||||
@ -299,9 +306,6 @@ class LibraryManager {
|
||||
) {
|
||||
const taskId = createVersionImportTaskId(gameId, versionPath);
|
||||
|
||||
const platform = parsePlatform(metadata.platform);
|
||||
if (!platform) return undefined;
|
||||
|
||||
const game = await prisma.game.findUnique({
|
||||
where: { id: gameId },
|
||||
select: { mName: true, libraryId: true, libraryPath: true },
|
||||
@ -345,17 +349,14 @@ class LibraryManager {
|
||||
versionPath: versionPath,
|
||||
versionName: metadata.name ?? versionPath,
|
||||
dropletManifest: manifest,
|
||||
platform: platform,
|
||||
|
||||
gameVersion: {
|
||||
gameVersions: {
|
||||
create: {
|
||||
versionIndex: currentIndex,
|
||||
delta: metadata.delta,
|
||||
umuIdOverride: metadata.umuId,
|
||||
|
||||
onlySetup: metadata.onlySetup,
|
||||
setupCommand: metadata.setup,
|
||||
setupArgs: metadata.setupArgs,
|
||||
|
||||
launches: {
|
||||
createMany: {
|
||||
@ -364,12 +365,27 @@ class LibraryManager {
|
||||
({
|
||||
name: v.name,
|
||||
description: v.description,
|
||||
launchCommand: v.launchCommand,
|
||||
launchArgs: v.launchArgs,
|
||||
}) satisfies LaunchOptionCreateManyGameVersionInput,
|
||||
command: v.launchCommand,
|
||||
args: v.launchArgs,
|
||||
}) satisfies LaunchOptionCreateManyInput,
|
||||
),
|
||||
},
|
||||
},
|
||||
|
||||
install: {
|
||||
create: {
|
||||
name: "",
|
||||
description: "",
|
||||
command: metadata.setup,
|
||||
args: metadata.setupArgs,
|
||||
},
|
||||
},
|
||||
|
||||
platform: {
|
||||
connect: {
|
||||
id: metadata.platform,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
47
server/internal/platform/link.ts
Normal file
47
server/internal/platform/link.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { Platform, type HardwarePlatform } from "~/prisma/client/enums";
|
||||
import prisma from "../db/database";
|
||||
import type { PlatformLink } from "~/prisma/client/client";
|
||||
|
||||
export async function convertIDsToPlatforms(platformIDs: string[]) {
|
||||
const userPlatforms = await prisma.userPlatform.findMany({
|
||||
where: {
|
||||
id: {
|
||||
in: platformIDs,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const platforms = platformIDs.map(
|
||||
(e) => userPlatforms.find((v) => v.id === e) ?? (e as HardwarePlatform),
|
||||
);
|
||||
|
||||
return platforms;
|
||||
}
|
||||
|
||||
export async function convertIDToLink(
|
||||
id: string,
|
||||
): Promise<PlatformLink | undefined> {
|
||||
const link = await prisma.platformLink.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
if (link) return link;
|
||||
|
||||
if (Platform[id as Platform]) {
|
||||
return await prisma.platformLink.create({
|
||||
data: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const userPlatform = await prisma.userPlatform.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!userPlatform) return undefined;
|
||||
return await prisma.platformLink.create({
|
||||
data: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user