-
Notifications
You must be signed in to change notification settings - Fork 52
/
ArtitalkSafe.worker.js
56 lines (47 loc) · 2.24 KB
/
ArtitalkSafe.worker.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
//此脚本由MHuiG - MiniValine写成,ChenYFan将其做少量修改制成,此脚本仅适用于Artitalk
async function handleRequest(event) {
AppId = (function () { try { return APPID } catch (e) { return "" } })()
AppKey = (function () { try { return APPKEY } catch (e) { return "" } })()
if (AppId == "" || AppKey == "") { return new Response('Artitalk-Safe异常:您没有设定appid和appkey') }
ServerDomain = (function () { try { return SERVERDOMAIN } catch (e) { return `${(AppId.substr(0, 8)).toLowerCase()}.api.lncldglobal.com` } })()
atComment = (function () { try { return ATCOMMENT == "true" ? true : false } catch (e) { return true } })()
CORS = (function () { try { return CORS } catch (e) { return '*' } })()
const request = event.request
const url = new URL(request.url)
const urlObj = new URL(url)
const path = urlObj.href.substr(urlObj.origin.length)
const classac = l(rp(path).split('/'))
if (classac == "atComment" && !atComment) { return new Response('{"code":101,"error":"Artitalk-Safe:评论功能未开启"}', { headers: { "content-type": "application/json;charset=utf-8" } }) }
if (classac == "_File" || classac == "_Followee" || classac == "_Follower" || classac == "_Installation" || classac == "_Role") { return new Response('{"code":101,"error":"Artitalk-Safe:操作是禁止的"}', { headers: { "content-type": "application/json;charset=utf-8" } }) }
url.hostname = ServerDomain
reqHEDNew = new Headers(request.headers)
if (reqHEDNew.get("X-LC-Id")) {
reqHEDNew.set("X-LC-Id", AppId)
reqHEDNew.set("X-LC-Key", AppKey)
}
if (reqHEDNew.get("x-lc-sign")) {
reqHEDNew.delete("X-LC-Sign")
}
reqNew = new Request(request, { headers: reqHEDNew })
responsefetch = await fetch(url.toString(), reqNew)
resHEDNew = new Headers(responsefetch.headers)
resHEDNew.set("Access-Control-Allow-Origin", CORS)
response = new Response(responsefetch.body, { headers: resHEDNew })
return response
}
function rp(p) {
return p.split("?")[0]
}
function l(p) {
return p[getJsonLength(p) - 1]
}
function getJsonLength(jsonData) {
var jsonLength = 0;
for (var item in jsonData) {
jsonLength++;
}
return jsonLength;
}
addEventListener("fetch", event => {
event.respondWith(handleRequest(event))
})