From 9c232e05ab7c314719d90a73071a47d08b130acc Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 15 Sep 2023 12:06:58 -0400 Subject: [PATCH] Write sizes and shiggy file every page, less downtime --- src/shiggyGetter.ts | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/shiggyGetter.ts b/src/shiggyGetter.ts index a67b946..b9798e6 100644 --- a/src/shiggyGetter.ts +++ b/src/shiggyGetter.ts @@ -42,6 +42,8 @@ export default async function getShiggies(limit = 50): Promise { 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( (await blacklistFile.exists()) ? await blacklistFile.json() : [], @@ -49,7 +51,6 @@ export default async function getShiggies(limit = 50): Promise { 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 }); @@ -113,24 +114,22 @@ export default async function getShiggies(limit = 50): Promise { }), ); + 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`, );