diff --git a/src/lib/util/album.ts b/src/lib/util/album.ts index b9b0ff0..2c82c5c 100644 --- a/src/lib/util/album.ts +++ b/src/lib/util/album.ts @@ -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(); }