Readme

Get all content ("blocks") from an Are.na channel https://dev.are.na/documentation/channels

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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;
// Iterate through pages, since the Are.na API seems to be missing info on total pages
while (hasMore) {
const pagePromises = [];
for (let i = 0; i < 5 && hasMore; i++) { // Fetch 5 pages at a time
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;
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
August 14, 2024