-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
34 lines (27 loc) · 858 Bytes
/
Copy pathapi.js
File metadata and controls
34 lines (27 loc) · 858 Bytes
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
const { load_env } = require("./utils");
if (!process.env.IS_VERCEL) load_env();
const BASE_URL = "https://api.are.na/v3";
async function fetch_json(url) {
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.DANGER_ARENA_TOKEN}`,
},
});
if (!response.ok) throw new Error("Network response was not ok");
return response.json();
}
async function load_user() {
return fetch_json(`${BASE_URL}/me`);
}
async function get_channel_contents(id) {
const result = await fetch_json(
`${BASE_URL}/channels/${id}/contents?page=1&per=100&sort=created_at_desc`,
);
return result.data;
}
async function get_channel_info(id) {
return fetch_json(`${BASE_URL}/channels/${id}`);
}
module.exports = { fetch_json, load_user, get_channel_contents, get_channel_info };