Skip to content

Commit

Permalink
Merge pull request #279 from genshindev/feature/entity-ids
Browse files Browse the repository at this point in the history
Implement adding an ID to every entity
  • Loading branch information
M4GICB authored May 20, 2024
2 parents 9ba4f7b + 890ba28 commit aea4650
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/modules/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import chalk from 'chalk';

const cache = new keyv();

export async function containsFolders(path: string):Promise<boolean>
{
export async function containsFolders(path: string): Promise<boolean> {
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;
}
Expand Down Expand Up @@ -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]'),
Expand Down

0 comments on commit aea4650

Please sign in to comment.