mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-01-31 15:37:09 +01:00
* feat: nginx + torrential basics & services system * fix: lint + i18n * fix: update torrential to remove openssl * feat: add torrential to Docker build * feat: move to self hosted runner * fix: move off self-hosted runner * fix: update nginx.conf * feat: torrential cache invalidation * fix: update torrential for cache invalidation * feat: integrity check task * fix: lint * feat: move to version ids * fix: client fixes and client-side checks * feat: new depot apis and version id fixes * feat: update torrential * feat: droplet bump and remove unsafe update functions * fix: lint * feat: v4 featureset: emulators, multi-launch commands * fix: lint * fix: mobile ui for game editor * feat: launch options * fix: lint * fix: remove axios, use $fetch * feat: metadata and task api improvements * feat: task actions * fix: slight styling issue * feat: fix style and lints * feat: totp backend routes * feat: oidc groups * fix: update drop-base * feat: creation of passkeys & totp * feat: totp signin * feat: webauthn mfa/signin * feat: launch selecting ui * fix: manually running tasks * feat: update add company game modal to use new SelectorGame * feat: executor selector * fix(docker): update rust to rust nightly for torrential build (#305) * feat: new version ui * feat: move package lookup to build time to allow for deno dev * fix: lint * feat: localisation cleanup * feat: apply localisation cleanup * feat: potential i18n refactor logic * feat: remove args from commands * fix: lint * fix: lockfile --------- Co-authored-by: Aden Lindsay <140392385+AdenMGB@users.noreply.github.com>
122 lines
3.4 KiB
TypeScript
122 lines
3.4 KiB
TypeScript
import { ArkErrors, type } from "arktype";
|
|
import {
|
|
GameNotFoundError,
|
|
VersionNotFoundError,
|
|
type LibraryProvider,
|
|
} from "../provider";
|
|
import { LibraryBackend } from "~/prisma/client/enums";
|
|
import fs from "fs";
|
|
import path from "path";
|
|
import droplet, {
|
|
hasBackendForPath,
|
|
listFiles,
|
|
peekFile,
|
|
readFile,
|
|
} from "@drop-oss/droplet";
|
|
import { fsStats } from "~/server/internal/utils/files";
|
|
|
|
export const FilesystemProviderConfig = type({
|
|
baseDir: "string",
|
|
});
|
|
|
|
export class FilesystemProvider
|
|
implements LibraryProvider<typeof FilesystemProviderConfig.infer>
|
|
{
|
|
private config: typeof FilesystemProviderConfig.infer;
|
|
private myId: string;
|
|
|
|
constructor(rawConfig: unknown, id: string) {
|
|
const config = FilesystemProviderConfig(rawConfig);
|
|
if (config instanceof ArkErrors) {
|
|
throw new Error(
|
|
`Failed to create filesystem provider: ${config.summary}`,
|
|
);
|
|
}
|
|
|
|
this.myId = id;
|
|
this.config = config;
|
|
|
|
if (!fs.existsSync(this.config.baseDir))
|
|
throw "Base directory does not exist.";
|
|
}
|
|
|
|
id(): string {
|
|
return this.myId;
|
|
}
|
|
|
|
type(): LibraryBackend {
|
|
return LibraryBackend.Filesystem;
|
|
}
|
|
|
|
async listGames(): Promise<string[]> {
|
|
const dirs = fs.readdirSync(this.config.baseDir);
|
|
const folderDirs = dirs.filter((e) => {
|
|
const fullDir = path.join(this.config.baseDir, e);
|
|
return fs.lstatSync(fullDir).isDirectory();
|
|
});
|
|
return folderDirs;
|
|
}
|
|
|
|
async listVersions(
|
|
game: string,
|
|
ignoredVersions?: string[],
|
|
): Promise<string[]> {
|
|
const gameDir = path.join(this.config.baseDir, game);
|
|
if (!fs.existsSync(gameDir)) throw new GameNotFoundError();
|
|
const versionDirs = fs.readdirSync(gameDir);
|
|
const validVersionDirs = versionDirs.filter((e) => {
|
|
if (ignoredVersions && ignoredVersions.includes(e)) return false;
|
|
const fullDir = path.join(this.config.baseDir, game, e);
|
|
return hasBackendForPath(fullDir);
|
|
});
|
|
return validVersionDirs;
|
|
}
|
|
|
|
async versionReaddir(game: string, version: string): Promise<string[]> {
|
|
const versionDir = path.join(this.config.baseDir, game, version);
|
|
if (!fs.existsSync(versionDir)) throw new VersionNotFoundError();
|
|
return await listFiles(versionDir);
|
|
}
|
|
|
|
async generateDropletManifest(
|
|
game: string,
|
|
version: string,
|
|
progress: (err: Error | null, v: number) => void,
|
|
log: (err: Error | null, v: string) => void,
|
|
): Promise<string> {
|
|
const versionDir = path.join(this.config.baseDir, game, version);
|
|
if (!fs.existsSync(versionDir)) throw new VersionNotFoundError();
|
|
const manifest = await droplet.generateManifest(versionDir, progress, log);
|
|
return manifest;
|
|
}
|
|
|
|
async peekFile(game: string, version: string, filename: string) {
|
|
const filepath = path.join(this.config.baseDir, game, version);
|
|
if (!fs.existsSync(filepath)) return undefined;
|
|
const stat = await peekFile(filepath, filename);
|
|
return { size: Number(stat) };
|
|
}
|
|
|
|
async readFile(
|
|
game: string,
|
|
version: string,
|
|
filename: string,
|
|
options?: { start?: number; end?: number },
|
|
) {
|
|
const filepath = path.join(this.config.baseDir, game, version);
|
|
if (!fs.existsSync(filepath)) return undefined;
|
|
const stream = await readFile(
|
|
filepath,
|
|
filename,
|
|
options?.start ? BigInt(options.start) : undefined,
|
|
options?.end ? BigInt(options.end) : undefined,
|
|
);
|
|
|
|
return stream;
|
|
}
|
|
|
|
fsStats() {
|
|
return fsStats(this.config.baseDir);
|
|
}
|
|
}
|