API optimisations (#343)
* feat: api optimisation * feat: emulator rename
This commit is contained in:
@@ -20,7 +20,7 @@ export type AdminFetchGameType = Prisma.GameGetPayload<{
|
||||
setups: true;
|
||||
launches: {
|
||||
include: {
|
||||
executor: {
|
||||
emulator: {
|
||||
include: {
|
||||
gameVersion: {
|
||||
select: {
|
||||
@@ -38,7 +38,7 @@ export type AdminFetchGameType = Prisma.GameGetPayload<{
|
||||
};
|
||||
};
|
||||
};
|
||||
executions: {
|
||||
emulations: {
|
||||
select: {
|
||||
launchId: true;
|
||||
};
|
||||
@@ -77,7 +77,7 @@ export default defineEventHandler<
|
||||
setups: true,
|
||||
launches: {
|
||||
include: {
|
||||
executor: {
|
||||
emulator: {
|
||||
include: {
|
||||
gameVersion: {
|
||||
select: {
|
||||
@@ -95,7 +95,7 @@ export default defineEventHandler<
|
||||
},
|
||||
},
|
||||
},
|
||||
executions: {
|
||||
emulations: {
|
||||
select: {
|
||||
launchId: true,
|
||||
},
|
||||
|
||||
@@ -19,7 +19,7 @@ export const ImportVersion = type({
|
||||
name: "string",
|
||||
launch: "string",
|
||||
umuId: "string?",
|
||||
executorId: "string?",
|
||||
emulatorId: "string?",
|
||||
suggestions: "string[]?",
|
||||
}).array(),
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ export default defineClientEventHandler(async (h3) => {
|
||||
include: {
|
||||
launches: {
|
||||
include: {
|
||||
executor: {
|
||||
emulator: {
|
||||
include: {
|
||||
gameVersion: {
|
||||
select: {
|
||||
@@ -46,11 +46,11 @@ export default defineClientEventHandler(async (h3) => {
|
||||
...gameVersion,
|
||||
launches: gameVersion.launches.map((launch) => ({
|
||||
...launch,
|
||||
executor: launch.executor
|
||||
emulator: launch.emulator
|
||||
? {
|
||||
...launch.executor,
|
||||
...launch.emulator,
|
||||
gameVersion: undefined,
|
||||
gameId: launch.executor.gameVersion.game.id,
|
||||
gameId: launch.emulator.gameVersion.game.id,
|
||||
}
|
||||
: undefined,
|
||||
})),
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { GameVersionSize } from "~/server/internal/gamesize";
|
||||
import gameSizeManager from "~/server/internal/gamesize";
|
||||
|
||||
type VersionDownloadOption = {
|
||||
gameId: string;
|
||||
versionId: string;
|
||||
displayName?: string | undefined;
|
||||
versionPath?: string | undefined;
|
||||
@@ -43,7 +44,7 @@ export default defineClientEventHandler(async (h3) => {
|
||||
launches: {
|
||||
select: {
|
||||
platform: true,
|
||||
executor: {
|
||||
emulator: {
|
||||
select: {
|
||||
gameVersion: {
|
||||
select: {
|
||||
@@ -78,18 +79,16 @@ export default defineClientEventHandler(async (h3) => {
|
||||
if (!platformOptions.has(launch.platform))
|
||||
platformOptions.set(launch.platform, []);
|
||||
|
||||
if ("executor" in launch && launch.executor) {
|
||||
if ("emulator" in launch && launch.emulator) {
|
||||
const old = platformOptions.get(launch.platform)!;
|
||||
const gv = launch.emulator.gameVersion;
|
||||
old.push({
|
||||
gameId: launch.executor.gameVersion.game.id,
|
||||
versionId: launch.executor.gameVersion.versionId,
|
||||
name: launch.executor.gameVersion.game.mName,
|
||||
iconObjectId: launch.executor.gameVersion.game.mIconObjectId,
|
||||
shortDescription:
|
||||
launch.executor.gameVersion.game.mShortDescription,
|
||||
size: (await gameSizeManager.getVersionSize(
|
||||
launch.executor.gameVersion.versionId,
|
||||
))!,
|
||||
gameId: gv.game.id,
|
||||
versionId: gv.versionId,
|
||||
name: gv.game.mName,
|
||||
iconObjectId: gv.game.mIconObjectId,
|
||||
shortDescription: gv.game.mShortDescription,
|
||||
size: (await gameSizeManager.getVersionSize(gv.versionId))!,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -101,6 +100,7 @@ export default defineClientEventHandler(async (h3) => {
|
||||
.map(
|
||||
([platform, requiredContent]) =>
|
||||
({
|
||||
gameId: v.gameId,
|
||||
versionId: v.versionId,
|
||||
displayName: v.displayName || undefined,
|
||||
versionPath: v.versionPath || undefined,
|
||||
|
||||
@@ -21,6 +21,12 @@ export default defineEventHandler(async (h3) => {
|
||||
launches: true,
|
||||
setups: true,
|
||||
},
|
||||
omit: {
|
||||
dropletManifest: true,
|
||||
},
|
||||
orderBy: {
|
||||
versionIndex: "desc",
|
||||
},
|
||||
},
|
||||
publishers: {
|
||||
select: {
|
||||
@@ -57,7 +63,30 @@ export default defineEventHandler(async (h3) => {
|
||||
},
|
||||
});
|
||||
|
||||
const size = (await gameSizeManager.getGameBreakdown(gameId))!;
|
||||
const sizes = await Promise.all(
|
||||
game.versions!.map(
|
||||
async (v) => (await gameSizeManager.getVersionSize(v.versionId))!,
|
||||
),
|
||||
);
|
||||
|
||||
return { game, rating, size };
|
||||
const platforms = new Set(
|
||||
game
|
||||
.versions!.map((v) => [
|
||||
...v.setups.map((v) => v.platform),
|
||||
...v.launches.map((v) => v.platform),
|
||||
])
|
||||
.flat(),
|
||||
);
|
||||
|
||||
const gameV: Omit<typeof game, "versions"> = game;
|
||||
|
||||
// @ts-expect-error value exists at runtime
|
||||
delete gameV.versions;
|
||||
|
||||
return {
|
||||
game: gameV,
|
||||
rating,
|
||||
sizes,
|
||||
platforms: platforms.values().toArray(),
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user