generated from pot-app/pot-app-collection-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
58 lines (54 loc) · 1.7 KB
/
main.js
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
async function collection(source, target, options = {}) {
const { config, utils } = options;
const { tauriFetch: fetch } = utils;
const { auth_token: authToken } = config;
if (authToken === undefined || authToken.length === 0) {
throw "authToken not found";
}
let body = {
business_id: 6,
words: [source],
};
let res = await fetch(
"https://apiv3.shanbay.com/wordscollection/words_bulk_upload",
{
method: "POST",
headers: {
Cookie: `auth_token=${authToken}`,
"Content-Type": "application/json;charset=UTF-8",
},
body: {
type: "Json",
payload: body,
},
},
);
if (res.ok) {
const result = res.data;
if (result.msg) {
throw result.msg;
} else if (result["task_id"]) {
let check_res = await fetch(
"https://apiv3.shanbay.com/wordscollection/words_bulk_upload",
{
method: "GET",
query: { business_id: "6", task_id: result["task_id"] },
headers: {
Cookie: `auth_token=${authToken}`,
},
},
);
const check_result = check_res.data;
const { failed_count } = check_result;
if (failed_count > 0) {
throw "Failed to add words";
} else {
return true;
}
} else {
throw JSON.stringify(result);
}
} else {
throw `Http Request Error\nHttp Status: ${res.status}\n${JSON.stringify(res.data)}`;
}
}