Artitalk官网
配置LeanCloud
(教程来自:https://artitalk.js.org/doc.html#🌈-leancloud-的相关准备)
配置CFWorker
1.创建Worker
(名称随意,点击下方“创建服务”)
2.编辑Worker
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
|
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)) })
|
(其实就是复制ArtitalkSafe.worker.js里面的内容)
点击“保存并部署”
3.设置变量
点击“变量”----->“添加变量”
4.将“路由”下面的“xxx.worker.dev”复制下来
配置Artitalk
https://artitalk.js.org/settings.html
https://artitalk.js.org/doc.html#🌼-开始使用