mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-15 01:01:20 +10:00
feat: import of custom platforms & file extensions
This commit is contained in:
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