mirror of
https://github.com/BillyOutlast/drop.git
synced 2026-02-04 08:41:17 +01:00
Game specialisation & delta versions (#323)
* feat: game specialisation, auto-guess extensions * fix: enforce specialisation specific schema at API level * fix: lint * feat: partial work on depot endpoints * feat: bump torrential * feat: dummy version creation for depot uploads * fix: lint * fix: types * fix: lint * feat: depot version import * fix: lint * fix: remove any type * fix: lint * fix: push update interval * fix: cpu usage calculation * feat: delta version support * feat: style tweaks for selectlaunch.vue * fix: lint
This commit is contained in:
11
server/api/v1/admin/depot/index.get.ts
Normal file
11
server/api/v1/admin/depot/index.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, ["depot:read"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const depots = await prisma.depot.findMany({});
|
||||
|
||||
return depots;
|
||||
});
|
||||
@@ -6,7 +6,6 @@ import { castManifest } from "~/server/internal/library/manifest";
|
||||
const AUTHORIZATION_HEADER_PREFIX = "Bearer ";
|
||||
|
||||
const Query = type({
|
||||
game: "string",
|
||||
version: "string",
|
||||
});
|
||||
|
||||
@@ -31,10 +30,7 @@ export default defineEventHandler(async (h3) => {
|
||||
|
||||
const version = await prisma.gameVersion.findUnique({
|
||||
where: {
|
||||
gameId_versionId: {
|
||||
gameId: query.game,
|
||||
versionId: query.version,
|
||||
},
|
||||
versionId: query.version,
|
||||
},
|
||||
select: {
|
||||
dropletManifest: true,
|
||||
@@ -11,6 +11,11 @@ export default defineEventHandler(async (h3) => {
|
||||
select: {
|
||||
versionId: true,
|
||||
},
|
||||
where: {
|
||||
versionPath: {
|
||||
not: null
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
51
server/api/v1/admin/depot/upload.post.ts
Normal file
51
server/api/v1/admin/depot/upload.post.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { type } from "arktype";
|
||||
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
|
||||
const UploadManifest = type({
|
||||
gameId: "string",
|
||||
versionName: "string",
|
||||
|
||||
manifest: type({
|
||||
version: "'2'",
|
||||
size: "number",
|
||||
key: "16 <= number[] <= 16",
|
||||
chunks: type({
|
||||
["string"]: {
|
||||
checksum: "string",
|
||||
iv: "16 <= number[] <= 16",
|
||||
files: type({
|
||||
filename: "string",
|
||||
start: "number",
|
||||
length: "number",
|
||||
permissions: "number",
|
||||
}).array(),
|
||||
},
|
||||
}),
|
||||
}),
|
||||
fileList: "string[]",
|
||||
}).configure(throwingArktype);
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["depot:upload:new"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const { gameId, versionName, manifest, fileList } =
|
||||
await readDropValidatedBody(h3, UploadManifest);
|
||||
|
||||
const version = await prisma.unimportedGameVersion.create({
|
||||
data: {
|
||||
game: {
|
||||
connect: {
|
||||
id: gameId,
|
||||
},
|
||||
},
|
||||
versionName,
|
||||
manifest,
|
||||
fileList,
|
||||
},
|
||||
});
|
||||
|
||||
return { id: version.id };
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { GameVersion, Prisma } from "~/prisma/client/client";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import type { UnimportedVersionInformation } from "~/server/internal/library";
|
||||
import libraryManager from "~/server/internal/library";
|
||||
|
||||
async function getGameVersionSize<
|
||||
@@ -59,7 +60,7 @@ export default defineEventHandler<
|
||||
{ body: never },
|
||||
Promise<{
|
||||
game: AdminFetchGameType;
|
||||
unimportedVersions: string[] | undefined;
|
||||
unimportedVersions: UnimportedVersionInformation[] | undefined;
|
||||
}>
|
||||
>(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["game:read"]);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { type } from "arktype";
|
||||
import { GameType } from "~/prisma/client/enums";
|
||||
import { readDropValidatedBody, throwingArktype } from "~/server/arktype";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import libraryManager from "~/server/internal/library";
|
||||
@@ -7,6 +8,7 @@ import metadataHandler from "~/server/internal/metadata";
|
||||
const ImportGameBody = type({
|
||||
library: "string",
|
||||
path: "string",
|
||||
type: type.valueOf(GameType),
|
||||
["metadata?"]: {
|
||||
id: "string",
|
||||
sourceId: "string",
|
||||
@@ -19,7 +21,7 @@ export default defineEventHandler<{ body: typeof ImportGameBody.infer }>(
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["import:game:new"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const { library, path, metadata } = await readDropValidatedBody(
|
||||
const { library, path, metadata, type } = await readDropValidatedBody(
|
||||
h3,
|
||||
ImportGameBody,
|
||||
);
|
||||
@@ -38,8 +40,8 @@ export default defineEventHandler<{ body: typeof ImportGameBody.infer }>(
|
||||
});
|
||||
|
||||
const taskId = metadata
|
||||
? await metadataHandler.createGame(metadata, library, path)
|
||||
: await metadataHandler.createGameWithoutMetadata(library, path);
|
||||
? await metadataHandler.createGame(metadata, library, path, type)
|
||||
: await metadataHandler.createGameWithoutMetadata(library, path, type);
|
||||
|
||||
if (!taskId)
|
||||
throw createError({
|
||||
|
||||
@@ -16,7 +16,7 @@ export default defineEventHandler(async (h3) => {
|
||||
|
||||
const game = await prisma.game.findUnique({
|
||||
where: { id: gameId },
|
||||
select: { libraryId: true, libraryPath: true },
|
||||
select: { libraryId: true, libraryPath: true, type: true },
|
||||
});
|
||||
if (!game || !game.libraryId)
|
||||
throw createError({ statusCode: 404, statusMessage: "Game not found" });
|
||||
@@ -28,5 +28,5 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!unimportedVersions)
|
||||
throw createError({ statusCode: 400, statusMessage: "Invalid game ID" });
|
||||
|
||||
return unimportedVersions;
|
||||
return { versions: unimportedVersions, type: game.type };
|
||||
});
|
||||
|
||||
@@ -7,7 +7,11 @@ import libraryManager from "~/server/internal/library";
|
||||
|
||||
export const ImportVersion = type({
|
||||
id: "string",
|
||||
version: "string",
|
||||
version: type({
|
||||
type: "'depot' | 'local'",
|
||||
identifier: "string",
|
||||
name: "string",
|
||||
}),
|
||||
displayName: "string?",
|
||||
|
||||
launches: type({
|
||||
@@ -16,6 +20,7 @@ export const ImportVersion = type({
|
||||
launch: "string",
|
||||
umuId: "string?",
|
||||
executorId: "string?",
|
||||
suggestions: "string[]?",
|
||||
}).array(),
|
||||
|
||||
setups: type({
|
||||
@@ -25,6 +30,10 @@ export const ImportVersion = type({
|
||||
|
||||
onlySetup: "boolean = false",
|
||||
delta: "boolean = false",
|
||||
|
||||
requiredContent: type("string")
|
||||
.array()
|
||||
.default(() => []),
|
||||
}).configure(throwingArktype);
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
@@ -47,7 +56,7 @@ export default defineEventHandler(async (h3) => {
|
||||
if (validOverlayVersions == 0)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Update mode requires a pre-existing version.",
|
||||
statusMessage: `Update mode requires a pre-existing version for platform: ${platformObject.platform}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,43 @@
|
||||
import { ArkErrors, type } from "arktype";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import libraryManager from "~/server/internal/library";
|
||||
|
||||
const Query = type({
|
||||
id: "string",
|
||||
type: "'depot' | 'local'",
|
||||
version: "string",
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["import:version:read"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const query = await getQuery(h3);
|
||||
const gameId = query.id?.toString();
|
||||
const versionName = query.version?.toString();
|
||||
if (!gameId || !versionName)
|
||||
const query = Query(getQuery(h3));
|
||||
if (query instanceof ArkErrors)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing id or version in request params",
|
||||
message: query.summary,
|
||||
});
|
||||
|
||||
try {
|
||||
const preload = await libraryManager.fetchUnimportedVersionInformation(
|
||||
gameId,
|
||||
versionName,
|
||||
query.id,
|
||||
{
|
||||
type: query.type,
|
||||
identifier: query.version,
|
||||
},
|
||||
);
|
||||
if (!preload)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid game or version id/name",
|
||||
message: "Invalid game or version id/name",
|
||||
});
|
||||
|
||||
return preload;
|
||||
} catch (e) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: `Failed to fetch preload information for ${gameId}: ${e}`,
|
||||
message: `Failed to fetch preload information for ${query.id}: ${e}`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import { ArkErrors, type } from "arktype";
|
||||
import { GameType } from "~/prisma/client/enums";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import type { GameMetadataSearchResult } from "~/server/internal/metadata/types";
|
||||
|
||||
const Query = type({
|
||||
q: "string",
|
||||
type: type.valueOf(GameType).optional(),
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["game:read"]);
|
||||
const allowed = await aclManager.allowSystemACL(h3, [
|
||||
"game:read",
|
||||
"depot:read",
|
||||
]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const query = Query(getQuery(h3));
|
||||
@@ -22,7 +27,7 @@ export default defineEventHandler(async (h3) => {
|
||||
mShortDescription: string;
|
||||
mReleased: string;
|
||||
}[] =
|
||||
await prisma.$queryRaw`SELECT id, "mName", "mIconObjectId", "mShortDescription", "mReleased" FROM "Game" WHERE SIMILARITY("mName", ${query.q}) > 0.2 ORDER BY SIMILARITY("mName", ${query.q}) DESC;`;
|
||||
await prisma.$queryRaw`SELECT id, "mName", "mIconObjectId", "mShortDescription", "mReleased" FROM "Game" WHERE SIMILARITY("mName", ${query.q}) > 0.2 AND (${query.type || "undefined"} = 'undefined' OR type::text = ${query.type}) ORDER BY SIMILARITY("mName", ${query.q}) DESC;`;
|
||||
|
||||
const resultsMapped = results.map(
|
||||
(v) =>
|
||||
|
||||
@@ -13,15 +13,24 @@ export default defineClientEventHandler(async (h3) => {
|
||||
|
||||
const gameVersion = await prisma.gameVersion.findUnique({
|
||||
where: {
|
||||
gameId_versionId: {
|
||||
gameId: id,
|
||||
versionId: version,
|
||||
},
|
||||
versionId: version,
|
||||
},
|
||||
include: {
|
||||
launches: {
|
||||
include: {
|
||||
executor: true,
|
||||
executor: {
|
||||
include: {
|
||||
gameVersion: {
|
||||
select: {
|
||||
game: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
setups: true,
|
||||
@@ -34,8 +43,22 @@ export default defineClientEventHandler(async (h3) => {
|
||||
statusMessage: "Game version not found",
|
||||
});
|
||||
|
||||
return {
|
||||
const gameVersionMapped = {
|
||||
...gameVersion,
|
||||
launches: gameVersion.launches.map((launch) => ({
|
||||
...launch,
|
||||
executor: launch.executor
|
||||
? {
|
||||
...launch.executor,
|
||||
gameVersion: undefined,
|
||||
gameId: launch.executor.gameVersion.game.id,
|
||||
}
|
||||
: undefined,
|
||||
})),
|
||||
};
|
||||
|
||||
return {
|
||||
...gameVersionMapped,
|
||||
size: libraryManager.getGameVersionSize(id, version),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,24 +1,15 @@
|
||||
import { defineClientEventHandler } from "~/server/internal/clients/event-handler";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import { createDownloadManifestDetails } from "~/server/internal/library/manifest/index";
|
||||
|
||||
export default defineClientEventHandler(async (h3) => {
|
||||
const query = getQuery(h3);
|
||||
const id = query.id?.toString();
|
||||
const version = query.version?.toString();
|
||||
if (!id || !version)
|
||||
if (!version)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Missing id or version in query",
|
||||
statusMessage: "Missing version ID in query",
|
||||
});
|
||||
|
||||
const manifest = await prisma.gameVersion.findUnique({
|
||||
where: { gameId_versionId: { gameId: id, versionId: version } },
|
||||
select: { dropletManifest: true },
|
||||
});
|
||||
if (!manifest)
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: "Invalid game or version, or no versions added.",
|
||||
});
|
||||
return manifest.dropletManifest;
|
||||
const result = await createDownloadManifestDetails(version);
|
||||
return result;
|
||||
});
|
||||
|
||||
@@ -5,8 +5,8 @@ import gameSizeManager from "~/server/internal/gamesize";
|
||||
|
||||
type VersionDownloadOption = {
|
||||
versionId: string;
|
||||
displayName?: string;
|
||||
versionPath: string;
|
||||
displayName?: string | undefined;
|
||||
versionPath?: string | undefined;
|
||||
platform: Platform;
|
||||
size: number;
|
||||
requiredContent: Array<{
|
||||
@@ -106,7 +106,8 @@ export default defineClientEventHandler(async (h3) => {
|
||||
([platform, requiredContent]) =>
|
||||
({
|
||||
versionId: v.versionId,
|
||||
versionPath: v.versionPath,
|
||||
displayName: v.displayName || undefined,
|
||||
versionPath: v.versionPath || undefined,
|
||||
platform,
|
||||
requiredContent,
|
||||
size: size!,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ArkErrors, type } from "arktype";
|
||||
import type { Prisma } from "~/prisma/client/client";
|
||||
import { GameType } from "~/prisma/client/enums";
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import prisma from "~/server/internal/db/database";
|
||||
import { parsePlatform } from "~/server/internal/utils/parseplatform";
|
||||
@@ -100,6 +101,7 @@ export default defineEventHandler(async (h3) => {
|
||||
...tagFilter,
|
||||
...platformFilter,
|
||||
...companyFilter,
|
||||
type: GameType.Game,
|
||||
};
|
||||
|
||||
const sort: Prisma.GameOrderByWithRelationInput = {};
|
||||
|
||||
Reference in New Issue
Block a user