import { blob } from "https://esm.town/v/std/blob";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
const PAGE_SIZE = 50;
export let arenaChannelContents = async ({ channelId }: {
channelId: string;
}) => {
const baseUrl = `https://api.are.na/v2/channels/${channelId}/contents`;
let allContents = [];
let hasMore = true;
let currentPage = 1;
while (hasMore) {
const pagePromises = [];
for (let i = 0; i < 5 && hasMore; i++) {
pagePromises.push(
fetch(`${baseUrl}?page=${currentPage + i}&per=${PAGE_SIZE}`)
.then(res => res.json()),
);
}
const results = await Promise.all(pagePromises);
for (const result of results) {
if (result.contents && result.contents.length > 0) {
allContents = allContents.concat(result.contents);
currentPage++;
} else {
hasMore = false;
break;
}
}
}
return allContents;
};