mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 08:12:40 +10:00
* feat: start of library backends * feat: update backend routes and create initializer * feat: add legacy library creation * fix: resolve frontend type errors * fix: runtime errors * fix: lint
This commit is contained in:
64
server/internal/library/provider.ts
Normal file
64
server/internal/library/provider.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import type { Readable } from "stream";
|
||||
import type { LibraryBackend } from "~/prisma/client";
|
||||
|
||||
export abstract class LibraryProvider<CFG> {
|
||||
constructor(_config: CFG, _id: string) {
|
||||
throw new Error("Library doesn't have a proper constructor");
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns ID of the current library provider (fs, smb, s3, etc)
|
||||
*/
|
||||
abstract type(): LibraryBackend;
|
||||
|
||||
/**
|
||||
* @returns the specific ID of this current provider
|
||||
*/
|
||||
abstract id(): string;
|
||||
|
||||
/**
|
||||
* @returns list of (usually) top-level game folder names
|
||||
*/
|
||||
abstract listGames(): Promise<string[]>;
|
||||
|
||||
/**
|
||||
* @param game folder name of the game to list versions for
|
||||
* @returns list of version folder names
|
||||
*/
|
||||
abstract listVersions(game: string): Promise<string[]>;
|
||||
|
||||
/**
|
||||
* @param game folder name of the game
|
||||
* @param version folder name of the version
|
||||
* @returns recursive list of all files in version, relative to the version folder (e.g. ./setup.exe)
|
||||
*/
|
||||
abstract versionReaddir(game: string, version: string): Promise<string[]>;
|
||||
|
||||
/**
|
||||
* @param game folder name of the game
|
||||
* @param version folder name of the version
|
||||
* @returns string of JSON of the droplet manifest
|
||||
*/
|
||||
abstract generateDropletManifest(
|
||||
game: string,
|
||||
version: string,
|
||||
progress: (err: Error | null, v: number) => void,
|
||||
log: (err: Error | null, v: string) => void,
|
||||
): Promise<string>;
|
||||
|
||||
abstract peekFile(
|
||||
game: string,
|
||||
version: string,
|
||||
filename: string,
|
||||
): Promise<{ size: number } | undefined>;
|
||||
|
||||
abstract readFile(
|
||||
game: string,
|
||||
version: string,
|
||||
filename: string,
|
||||
options?: { start?: number; end?: number },
|
||||
): Promise<Readable | undefined>;
|
||||
}
|
||||
|
||||
export class GameNotFoundError extends Error {}
|
||||
export class VersionNotFoundError extends Error {}
|
||||
Reference in New Issue
Block a user