Files
drop/server/plugins/05.library-init.ts
DecDuck 251ddb8ff8 Rearchitecture for v0.4.0 (#197)
* feat: database redist support

* feat: rearchitecture of database schemas, migration reset, and #180

* feat: import redists

* fix: giantbomb logging bug

* feat: partial user platform support + statusMessage -> message

* feat: add user platform filters to store view

* fix: sanitize svg uploads

... copilot suggested this

I feel dirty.

* feat: beginnings of platform & redist management

* feat: add server side redist patching

* fix: update drop-base commit

* feat: import of custom platforms & file extensions

* fix: redelete platform

* fix: remove platform

* feat: uninstall commands, new R UI

* checkpoint: before migrating to nuxt v4

* update to nuxt 4

* fix: fixes for Nuxt v4 update

* fix: remaining type issues

* feat: initial feedback to import other kinds of versions

* working commit

* fix: lint

* feat: redist import
2025-11-10 10:36:13 +11:00

53 lines
1.6 KiB
TypeScript

import type { LibraryBackend } from "~~/prisma/client/enums";
import prisma from "../internal/db/database";
import type { JsonValue } from "@prisma/client/runtime/library";
import type { LibraryProvider } from "../internal/library/provider";
import { FilesystemProvider } from "../internal/library/providers/filesystem";
import libraryManager from "../internal/library";
import { FlatFilesystemProvider } from "../internal/library/providers/flat";
import { logger } from "~~/server/internal/logging";
export const libraryConstructors: {
[key in LibraryBackend]: (
value: JsonValue,
id: string,
) => LibraryProvider<unknown>;
} = {
Filesystem: function (
value: JsonValue,
id: string,
): LibraryProvider<unknown> {
return new FilesystemProvider(value, id);
},
FlatFilesystem: function (
value: JsonValue,
id: string,
): LibraryProvider<unknown> {
return new FlatFilesystemProvider(value, id);
},
};
export default defineNitroPlugin(async () => {
let successes = 0;
const libraries = await prisma.library.findMany({});
for (const library of libraries) {
const constructor = libraryConstructors[library.backend];
try {
const provider = constructor(library.options, library.id);
libraryManager.addLibrary(provider);
successes++;
} catch (e) {
logger.warn(
`Failed to create library (${library.id}) of type ${library.backend}:\n ${e}`,
);
}
}
if (successes == 0) {
logger.warn(
"No library was successfully initialised. Please check for errors. If you have just set up an instance, this is normal.",
);
}
});