Skip to content

Commit

Permalink
fix(api): rewrite if catalogs-v2 nonexistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed May 13, 2024
1 parent d4a9c2f commit 325fe46
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions api/src/catalog/catalog.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ function processCatalog(listing: CatalogBySeasonQuery['listings'][number]) {
};
}

const exists = (p: string) =>
fs.access(p).then(
() => true,
() => false,
);

async function fetchData(
seasonCode: string,
type: 'evals' | 'public',
Expand All @@ -88,13 +94,8 @@ async function fetchData(
const filePath = `${STATIC_FILE_DIR}/catalogs/${type}/${seasonCode}.json`;
const v2FilePath = `${STATIC_FILE_DIR}/catalogs-v2/${type}/${seasonCode}.json`;
await fs.mkdir(path.dirname(filePath), { recursive: true });
if (
!overwrite &&
(await fs.access(filePath).then(
() => true,
() => false,
))
) {
await fs.mkdir(path.dirname(v2FilePath), { recursive: true });
if (!overwrite && (await exists(filePath)) && (await exists(v2FilePath))) {
winston.info(`Skipping ${type} data for ${seasonCode}`);
return;
}
Expand Down

0 comments on commit 325fe46

Please sign in to comment.