From 890ba28d1177ddceabb3494be6c85a485fe68f5d Mon Sep 17 00:00:00 2001 From: man90 Date: Mon, 20 May 2024 19:27:44 +0200 Subject: [PATCH] Implement adding an ID to any entity --- src/modules/filesystem.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/modules/filesystem.ts b/src/modules/filesystem.ts index e589ed1a..0b36e493 100644 --- a/src/modules/filesystem.ts +++ b/src/modules/filesystem.ts @@ -12,10 +12,11 @@ import chalk from 'chalk'; const cache = new keyv(); -export async function containsFolders(path: string):Promise -{ +export async function containsFolders(path: string): Promise { try { - return (await fs.readdir(`assets/data/${path}`, { withFileTypes: true }))[0].isDirectory(); + return ( + await fs.readdir(`assets/data/${path}`, { withFileTypes: true }) + )[0].isDirectory(); } catch (e) { return false; } @@ -80,7 +81,12 @@ export async function getEntity( const file = await fs.readFile(filePath); try { - const entity = JSON.parse(file.toString('utf-8')); + const entity = { + ...JSON.parse(file.toString('utf-8')), + // Add ID to every entity so that after requesting an (...)/all endpoint + // client can request individual images for any of returned entities + id, + }; await cache.set(cacheId, entity); console.log( chalk.blue('[Cache-Data]'),