mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-15 17:21:13 +10:00
added download chunk endpoint
This commit is contained in:
@ -22,6 +22,10 @@ class LibraryManager {
|
||||
this.basePath = process.env.LIBRARY ?? "./.data/library";
|
||||
}
|
||||
|
||||
fetchLibraryPath() {
|
||||
return this.basePath;
|
||||
}
|
||||
|
||||
async fetchAllUnimportedGames() {
|
||||
const dirs = fs.readdirSync(this.basePath).filter((e) => {
|
||||
const fullDir = path.join(this.basePath, e);
|
||||
@ -45,13 +49,13 @@ class LibraryManager {
|
||||
|
||||
async fetchUnimportedGameVersions(
|
||||
libraryBasePath: string,
|
||||
versions: Array<GameVersion>
|
||||
versions: Array<GameVersion>,
|
||||
) {
|
||||
const gameDir = path.join(this.basePath, libraryBasePath);
|
||||
const versionsDirs = fs.readdirSync(gameDir);
|
||||
const importedVersionDirs = versions.map((e) => e.versionName);
|
||||
const unimportedVersions = versionsDirs.filter(
|
||||
(e) => !importedVersionDirs.includes(e)
|
||||
(e) => !importedVersionDirs.includes(e),
|
||||
);
|
||||
|
||||
return unimportedVersions;
|
||||
@ -79,10 +83,10 @@ class LibraryManager {
|
||||
noVersions: e.versions.length == 0,
|
||||
unimportedVersions: await this.fetchUnimportedGameVersions(
|
||||
e.libraryBasePath,
|
||||
e.versions
|
||||
e.versions,
|
||||
),
|
||||
},
|
||||
}))
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
@ -103,13 +107,13 @@ class LibraryManager {
|
||||
const targetDir = path.join(this.basePath, game.libraryBasePath);
|
||||
if (!fs.existsSync(targetDir))
|
||||
throw new Error(
|
||||
"Game in database, but no physical directory? Something is very very wrong..."
|
||||
"Game in database, but no physical directory? Something is very very wrong...",
|
||||
);
|
||||
const versions = fs.readdirSync(targetDir);
|
||||
const currentVersions = game.versions.map((e) => e.versionName);
|
||||
|
||||
const unimportedVersions = versions.filter(
|
||||
(e) => !currentVersions.includes(e)
|
||||
(e) => !currentVersions.includes(e),
|
||||
);
|
||||
return unimportedVersions;
|
||||
}
|
||||
@ -123,7 +127,7 @@ class LibraryManager {
|
||||
const targetDir = path.join(
|
||||
this.basePath,
|
||||
game.libraryBasePath,
|
||||
versionName
|
||||
versionName,
|
||||
);
|
||||
if (!fs.existsSync(targetDir)) return undefined;
|
||||
|
||||
@ -171,7 +175,7 @@ class LibraryManager {
|
||||
const finalChoice = sortedOptions[0];
|
||||
const finalChoiceRelativePath = path.relative(
|
||||
targetDir,
|
||||
finalChoice.filename
|
||||
finalChoice.filename,
|
||||
);
|
||||
startupGuess = finalChoiceRelativePath;
|
||||
platformGuess = finalChoice.platform;
|
||||
@ -196,7 +200,7 @@ class LibraryManager {
|
||||
gameId: string,
|
||||
versionName: string,
|
||||
metadata: { platform: string; setup: string; startup: string },
|
||||
delta = false
|
||||
delta = false,
|
||||
) {
|
||||
const taskId = `import:${gameId}:${versionName}`;
|
||||
|
||||
@ -233,7 +237,7 @@ class LibraryManager {
|
||||
(err, manifest) => {
|
||||
if (err) return reject(err);
|
||||
resolve(manifest);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user