Change function to const for internal helpers
This commit is contained in:
@ -1,24 +1,13 @@
|
|||||||
import { error } from "@sveltejs/kit";
|
import { error } from "@sveltejs/kit";
|
||||||
import StreamZip, { StreamZipAsync } from "node-stream-zip";
|
import StreamZip, { StreamZipAsync } from "node-stream-zip";
|
||||||
|
|
||||||
async function _getZip(zipName: string) {
|
const _getZip = async (zipName: string) => new StreamZip.async({ file: `./zip/${zipName}` });
|
||||||
let zip = null;
|
const _getFile = async (zip: StreamZipAsync, entryName: string) => await zip.entryData(entryName);
|
||||||
try {
|
const _getMetadata = async (zip: StreamZipAsync) => {
|
||||||
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 metadataContent = await _getFile(zip, 'album.json');
|
const metadataContent = await _getFile(zip, 'album.json');
|
||||||
return JSON.parse(metadataContent.toString());
|
return JSON.parse(metadataContent.toString());
|
||||||
}
|
}
|
||||||
async function _close(zip: StreamZipAsync, keepOpen: boolean) {
|
const _close = async (zip: StreamZipAsync, keepOpen: boolean) => {
|
||||||
if (!keepOpen)
|
if (!keepOpen)
|
||||||
await zip.close();
|
await zip.close();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user