-
Notifications
You must be signed in to change notification settings - Fork 12
/
api.js
56 lines (48 loc) · 1.18 KB
/
api.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
// get info of the searched urls from query
async function getSearchData(query, time, instruction) {
// format query
const url = "https://phantom-ghost-writer.vercel.app/api/youtube";
const headers = new Headers({
Origin: "https://chat.openai.com",
"content-type": "application/json",
});
try {
const response = await fetch(url, {
method: "POST",
body: JSON.stringify({
query: query.replace(/\s/g, "+"),
time,
instruction,
}),
headers,
});
const result = await response.text();
return result;
} catch (error) {
showErrorMessage(error);
return "";
}
}
async function getUrlData(videoId, instruction) {
// format query
const url = "https://phantom-ghost-writer.vercel.app/api/youtube-link";
const headers = new Headers({
Origin: "https://chat.openai.com",
"content-type": "application/json",
});
try {
const response = await fetch(url, {
method: "POST",
body: JSON.stringify({
videoId,
instruction,
}),
headers,
});
const result = await response.text();
return result;
} catch (error) {
showErrorMessage(error);
return "";
}
}