From 8df935347c2f67eaafebd97c60a35a27910a9297 Mon Sep 17 00:00:00 2001 From: mehbark Date: Fri, 26 Apr 2024 20:30:46 -0400 Subject: [PATCH] artist alley json dump --- caar/get.ts | 41 +++++++++++++++++++++++++++++++++++++++++ name.txt | 1 + 2 files changed, 42 insertions(+) create mode 100644 caar/get.ts create mode 100644 name.txt diff --git a/caar/get.ts b/caar/get.ts new file mode 100644 index 0000000..f808387 --- /dev/null +++ b/caar/get.ts @@ -0,0 +1,41 @@ +// TODO: types (don't even sweat validation) +// TODO: do sweat error handling +type Cursor = { refSnowflake: string; offset: number; sortOrder: string }; + +export const get = ( + cursor?: Cursor, +): Promise<{ listings: any[]; nextCursor: Cursor | undefined }> => + fetch( + `https://cohost.org/api/v1/trpc/artistAlley.getListingsForDisplay?batch=1&input=${ + encodeURI( + JSON.stringify({ + "0": { + adultDisplayMode: "include", + categories: [], + categoryMatch: "all", + sortOrder: "newest", + cursor, + }, + }), + ) + }`, + ).then(async (r) => { + const json = (await r.json())[0]; + if (json.error) throw json.error; + + const j = json.result.data; + return { + listings: j.listings.map((l: any) => ({ + ...l, + author: j.relevantProjects[l.projectId], + })), + nextCursor: j.nextCursor, + }; + }); + +export const get_all = async (cursor?: Cursor): Promise => { + const { listings, nextCursor } = await get(cursor); + return nextCursor ? [...listings, ...(await get_all(nextCursor))] : listings; +}; + +if (import.meta.main) console.log(await get_all()); diff --git a/name.txt b/name.txt new file mode 100644 index 0000000..67a61c6 --- /dev/null +++ b/name.txt @@ -0,0 +1 @@ +Cohost Artist Alley Repository