Change function to const for internal helpers

This commit is contained in:
Luca Bosin
2023-08-28 08:41:01 +02:00
parent 342b586ab9
commit 382e682487

View File

@ -1,24 +1,13 @@
import { error } from "@sveltejs/kit";
import StreamZip, { StreamZipAsync } from "node-stream-zip";
async function _getZip(zipName: string) {
let zip = null;
try {
zip = new StreamZip.async({ file: `./zip/${zipName}` });
} catch (err: any) {
console.error(`${err.stack}`.replaceAll('/home/sveltekit', '.'));
throw error(404, `Album not found.`);
}
return zip;
}
async function _getFile(zip: StreamZipAsync, entryName: string) {
return await zip.entryData(entryName);
}
async function _getMetadata(zip: StreamZipAsync) {
const _getZip = async (zipName: string) => new StreamZip.async({ file: `./zip/${zipName}` });
const _getFile = async (zip: StreamZipAsync, entryName: string) => await zip.entryData(entryName);
const _getMetadata = async (zip: StreamZipAsync) => {
const metadataContent = await _getFile(zip, 'album.json');
return JSON.parse(metadataContent.toString());
}
async function _close(zip: StreamZipAsync, keepOpen: boolean) {
const _close = async (zip: StreamZipAsync, keepOpen: boolean) => {
if (!keepOpen)
await zip.close();
}