-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharing.mjs
62 lines (55 loc) · 1.34 KB
/
sharing.mjs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* /api/share
* @module share
* @param {!string} text - Text
* @param {!string} author - Author
* @param {?string} image - Image
* @return {object} - Result item
*/
export async function share(text, author, image = null) {
const data = {
text: text,
author: author
};
if (image !== null) {
data["image"] = image;
}
const response = await fetch("https://milchchan.com/api/share", {
mode: "cors",
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
});
if (response.ok) {
return await response.json();
} else {
throw new Error(response.statusText);
}
}
/**
* /api/recent
* @module recent
* @param {!number} offset - Offset
* @param {?number} limit - Limit
* @return {!Array<object>} - Result items
*/
export async function recent(offset = 0, limit = null) {
let url = `https://milchchan.com/api/recent?offset=${offset}`;
if (limit !== null) {
url += `&limit=${limit}`;
}
const response = await fetch(url, {
mode: "cors",
method: "GET",
headers: {
"Content-Type": "application/json"
}
});
if (response.ok) {
return await response.json();
} else {
throw new Error(response.statusText);
}
}