mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-11 13:02:07 +10:00
Compare commits
1 Commits
67de1f6c02
...
nativefs
| Author | SHA1 | Date | |
|---|---|---|---|
| 973e8fdd71 |
@ -8,6 +8,7 @@ import { LibraryBackend } from "~/prisma/client/enums";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import droplet, { DropletHandler } from "@drop-oss/droplet";
|
import droplet, { DropletHandler } from "@drop-oss/droplet";
|
||||||
|
import { Readable } from "stream";
|
||||||
|
|
||||||
export const FilesystemProviderConfig = type({
|
export const FilesystemProviderConfig = type({
|
||||||
baseDir: "string",
|
baseDir: "string",
|
||||||
@ -59,7 +60,7 @@ export class FilesystemProvider
|
|||||||
const versionDirs = fs.readdirSync(gameDir);
|
const versionDirs = fs.readdirSync(gameDir);
|
||||||
const validVersionDirs = versionDirs.filter((e) => {
|
const validVersionDirs = versionDirs.filter((e) => {
|
||||||
const fullDir = path.join(this.config.baseDir, game, e);
|
const fullDir = path.join(this.config.baseDir, game, e);
|
||||||
return DROPLET_HANDLER.hasBackendForPath(fullDir);
|
return fs.lstatSync(fullDir).isDirectory(); //DROPLET_HANDLER.hasBackendForPath(fullDir);
|
||||||
});
|
});
|
||||||
return validVersionDirs;
|
return validVersionDirs;
|
||||||
}
|
}
|
||||||
@ -67,7 +68,7 @@ export class FilesystemProvider
|
|||||||
async versionReaddir(game: string, version: string): Promise<string[]> {
|
async versionReaddir(game: string, version: string): Promise<string[]> {
|
||||||
const versionDir = path.join(this.config.baseDir, game, version);
|
const versionDir = path.join(this.config.baseDir, game, version);
|
||||||
if (!fs.existsSync(versionDir)) throw new VersionNotFoundError();
|
if (!fs.existsSync(versionDir)) throw new VersionNotFoundError();
|
||||||
return DROPLET_HANDLER.listFiles(versionDir);
|
return fs.readdirSync(versionDir); //DROPLET_HANDLER.listFiles(versionDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateDropletManifest(
|
async generateDropletManifest(
|
||||||
@ -96,8 +97,8 @@ export class FilesystemProvider
|
|||||||
async peekFile(game: string, version: string, filename: string) {
|
async peekFile(game: string, version: string, filename: string) {
|
||||||
const filepath = path.join(this.config.baseDir, game, version);
|
const filepath = path.join(this.config.baseDir, game, version);
|
||||||
if (!fs.existsSync(filepath)) return undefined;
|
if (!fs.existsSync(filepath)) return undefined;
|
||||||
const stat = DROPLET_HANDLER.peekFile(filepath, filename);
|
const stat = fs.lstatSync(path.join(filepath, filename)); //DROPLET_HANDLER.peekFile(filepath, filename);
|
||||||
return { size: Number(stat) };
|
return { size: Number(stat.size) };
|
||||||
}
|
}
|
||||||
|
|
||||||
async readFile(
|
async readFile(
|
||||||
@ -108,6 +109,12 @@ export class FilesystemProvider
|
|||||||
) {
|
) {
|
||||||
const filepath = path.join(this.config.baseDir, game, version);
|
const filepath = path.join(this.config.baseDir, game, version);
|
||||||
if (!fs.existsSync(filepath)) return undefined;
|
if (!fs.existsSync(filepath)) return undefined;
|
||||||
|
return await Readable.toWeb(fs.createReadStream(path.join(filepath, filename), {
|
||||||
|
start: options?.start,
|
||||||
|
end: options?.end,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
})) as any;
|
||||||
|
/*
|
||||||
let stream;
|
let stream;
|
||||||
while (!(stream instanceof ReadableStream)) {
|
while (!(stream instanceof ReadableStream)) {
|
||||||
const v = DROPLET_HANDLER.readFile(
|
const v = DROPLET_HANDLER.readFile(
|
||||||
@ -121,5 +128,6 @@ export class FilesystemProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user