Posts made by MrXiaoM
-
RE: [教程] 使用 cloud flare worker 实现免费接口代理
之前写的一个脚本,反向代理一个网站,还可以替换内容中的原链接为新链接。
// API地址 const api = 'https://lolibooru.moe/'; // 替换地址 (改为空值不替换) const referTo = ''; async function handleRequest(request, origin, pathname, searchParams) { const apiUrl = new URL(api); apiUrl.pathname = pathname; for (const [key, value] of searchParams) { apiUrl.searchParams.append(key, value); } request = new Request(apiUrl, request); request.headers.set('Origin', apiUrl.origin); let response = await fetch(request, { method: 'GET' }); if(response.status == 200 || response.status == 301 || response.status == 302) { let changed = false; if (referTo.length > 0) { const type = response.headers.get("Content-Type"); if (type != null && ( type.includes("text") || type.includes("javascript") || type.includes("json") )) { let body = await response.text(); body = body.replace(api, referTo); response = new Response(body, response); changed = true; } } if (!changed) response = new Response(response.body, response); response.headers.set('Access-Control-Allow-Origin', origin); response.headers.append('Vary', 'Origin'); } return response; } addEventListener('fetch', (event) => { const request = event.request; const url = new URL(request.url); const origin = request.headers.get('Origin'); const pathname = url.pathname; const searchParams = url.searchParams; return event.respondWith(handleRequest(request, origin, pathname, searchParams)); });
-
RE: Overflow —— 将 mirai 实现换成 Onebot,机器人的又一个解决方案
现已可在官网 https://mirai.mrxiaom.top/ 下载 Overflow+mirai-console 整合包