This commit is contained in:
Nathan Rashleigh
2026-02-10 10:46:45 +11:00
parent 31a2ac82d0
commit bcf798a5f9
7 changed files with 99 additions and 11 deletions
+2
View File
@@ -0,0 +1,2 @@
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
+8
View File
@@ -0,0 +1,8 @@
server {
listen 80;
root /srv;
location /cstrike/maps/ {
alias /srv/maps/;
autoindex off;
}
}
+22 -9
View File
@@ -156,8 +156,8 @@ export async function getLocalMaps(mapsDir: string): Promise<Set<string>> {
try {
for await (const entry of Deno.readDir(mapsDir)) {
if (entry.isFile && entry.name.endsWith(".bsp")) {
const mapName = entry.name.replace(/\.bsp$/, "");
if (entry.isFile && entry.name.endsWith(".bsp.bz2")) {
const mapName = entry.name.replace(/\.bsp\.bz2$/, "");
localMaps.add(mapName);
}
}
@@ -317,29 +317,32 @@ export async function downloadAndExtractMaps(
console.log(`[${completed}/${mapsToDownload.size}] Downloading ${mapName}...`);
const archivePath = join(config.tempDir, gdriveFile.name);
const bspPath = join(config.mapsDir, `${mapName}.bsp`);
const tempBspPath = join(config.tempDir, `${mapName}.bsp`);
const bz2Path = join(config.mapsDir, `${mapName}.bsp.bz2`);
await client.downloadFile(gdriveFile.id, archivePath);
if (gdriveFile.name.endsWith(".rar")) {
await extractRAR(archivePath, mapName, config.mapsDir, config.tempDir);
await extractRAR(archivePath, mapName, config.tempDir, config.tempDir);
await Deno.remove(archivePath);
} else if (gdriveFile.name.endsWith(".bz2")) {
await decompressBZ2(archivePath, bspPath);
await decompressBZ2(archivePath, tempBspPath);
await Deno.remove(archivePath);
} else if (gdriveFile.name.endsWith(".zip")) {
await extractZIP(archivePath, mapName, config.mapsDir, config.tempDir);
await extractZIP(archivePath, mapName, config.tempDir, config.tempDir);
await Deno.remove(archivePath);
} else if (gdriveFile.name.endsWith(".bsp")) {
await moveFile(archivePath, bspPath);
await moveFile(archivePath, tempBspPath);
} else {
throw new Error(`Unknown archive format: ${gdriveFile.name}`);
}
await verifyBSP(bspPath);
await verifyBSP(tempBspPath);
await compressBSP(tempBspPath, bz2Path);
await Deno.remove(tempBspPath);
stats.success++;
console.log(` [OK] ${mapName} downloaded and extracted`);
console.log(` [OK] ${mapName} downloaded and compressed`);
} catch (error) {
stats.failed++;
console.error(` [X] Failed to download ${mapName}: ${(error as Error).message}`);
@@ -459,3 +462,13 @@ export async function verifyBSP(bspPath: string): Promise<void> {
file.close();
}
}
export async function compressBSP(bspPath: string, bz2Path: string): Promise<void> {
const process = new Deno.Command("bzip2", {
args: ["-c", bspPath],
stdout: "piped",
});
const { code, stdout } = await process.output();
if (code !== 0) throw new Error(`bzip2 failed with exit code ${code}`);
await Deno.writeFile(bz2Path, stdout);
}