Skip to content

Commit

Permalink
Write sizes and shiggy file every page, less downtime
Browse files Browse the repository at this point in the history
  • Loading branch information
lillithkt committed Sep 15, 2023
1 parent c0205f5 commit 9c232e0
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/shiggyGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ export default async function getShiggies(limit = 50): Promise<void> {
console.info("Cleaning up old shiggies..");

const blacklistFile = Bun.file(join(SHIGGY_DIR, "blacklist.json"));
const sizesFile = Bun.file(join(SHIGGY_DIR, "sizes.json"));
const shiggyFile = Bun.file(join(SHIGGY_DIR, "shiggies.json"));

const blacklist = new Set<string>(
(await blacklistFile.exists()) ? await blacklistFile.json() : [],
);

await rm(SHIGGY_DIR, { recursive: true, force: true });
await rm(join(PUBLIC_DIR, ZIP_NAME), { force: true });
await rm(join(PUBLIC_DIR, "sizes.json"), { force: true });

await mkdir(SHIGGY_DIR, { recursive: true });

Expand Down Expand Up @@ -113,24 +114,22 @@ export default async function getShiggies(limit = 50): Promise<void> {
}),
);

const sizes = Object.fromEntries(
Object.entries(posts).map(([id, post]) => [
id,
{
width: post.width,
height: post.height,
},
]),
);

Bun.write(sizesFile, JSON.stringify(sizes));
Bun.write(shiggyFile, JSON.stringify(Object.keys(posts)));

page = await page.nextPage();
}

const sizes = Object.fromEntries(
Object.entries(posts).map(([id, post]) => [
id,
{
width: post.width,
height: post.height,
},
]),
);
Bun.write(join(PUBLIC_DIR, "sizes.json"), JSON.stringify(sizes, null));

Bun.write(
join(SHIGGY_DIR, "shiggies.json"),
JSON.stringify(Object.keys(posts), null),
);
console.info(
`Fetched ${didFetch.size} posts out of ${Object.keys(posts).length} total`,
);
Expand Down

0 comments on commit 9c232e0

Please sign in to comment.