diff --git a/cloudflare-page/OneAPI-imgbed-MIX.html b/cloudflare-page/OneAPI-imgbed-MIX.html index dc98300..f345aae 100644 --- a/cloudflare-page/OneAPI-imgbed-MIX.html +++ b/cloudflare-page/OneAPI-imgbed-MIX.html @@ -68,6 +68,7 @@
diff --git a/cloudflare-worker-js-api/API_IMG_aisbtop.js b/cloudflare-worker-js-api/API_IMG_aisbtop.js new file mode 100644 index 0000000..64f1a65 --- /dev/null +++ b/cloudflare-worker-js-api/API_IMG_aisbtop.js @@ -0,0 +1,55 @@ +addEventListener('fetch', event => { + event.respondWith(handleaisbtopRequest(event.request)); + }) + + async function handleaisbtopRequest(request) { + if (request.method !== 'POST' || !request.headers.get('Content-Type').includes('multipart/form-data')) { + return new Response('Invalid request', { status: 400 }); + } + + const formData = await request.formData(); + const imageFile = formData.get('image'); + if (!imageFile) return new Response('Image file not found', { status: 400 }); + + const buffer = await imageFile.arrayBuffer(); + const base64Image = btoa(String.fromCharCode(...new Uint8Array(buffer))); + + const body = JSON.stringify({ src: base64Image }); + const headers = { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br, zstd", + "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7", + "Authorization": AISBTOP_TOKEN, // 从环境变量中读取 + "Cache-Control": "no-cache", + "Content-Type": "application/json", + "DNT": "1", + "Origin": "https://aisb.top", + "Pragma": "no-cache", + "Referer": "https://aisb.top/", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-origin", + "sec-ch-ua": "\"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"", + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": "\"Windows\"", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36" + }; + + const response = await fetch("https://aisb.top/api/upload", { + method: 'POST', + body: body, + headers: headers + }); + + if (response.ok) { + const result = await response.json(); + if (result && result.url) { + return new Response(result.url); + } else { + return new Response('Error: Unexpected response format', { status: 500 }); + } + } else { + return new Response('Error: ' + await response.text(), { status: response.status }); + } + } + \ No newline at end of file diff --git a/cloudflare-worker-js-api/worker.js b/cloudflare-worker-js-api/worker.js index fd7da5a..0749c8a 100644 --- a/cloudflare-worker-js-api/worker.js +++ b/cloudflare-worker-js-api/worker.js @@ -41,6 +41,9 @@ async function handleRequest(request) { case '/upload/tgphimg': response = await handleTgphimgRequest(request); break; + case '/upload/aisbtop': + response = await handleaisbtopRequest(request); + break; default: response = new Response('Not Found', { status: 404 }); break; @@ -158,6 +161,57 @@ async function handleRequest(request) { return new Response('Error: ' + await response.text(), { status: response.status }); } } + async function handleaisbtopRequest(request) { + if (request.method !== 'POST' || !request.headers.get('Content-Type').includes('multipart/form-data')) { + return new Response('Invalid request', { status: 400 }); + } + + const formData = await request.formData(); + const imageFile = formData.get('image'); + if (!imageFile) return new Response('Image file not found', { status: 400 }); + + const buffer = await imageFile.arrayBuffer(); + const base64Image = btoa(String.fromCharCode(...new Uint8Array(buffer))); + + const body = JSON.stringify({ src: base64Image }); + const headers = { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br, zstd", + "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7", + "Authorization": AISBTOP_TOKEN, // 从环境变量中读取 + "Cache-Control": "no-cache", + "Content-Type": "application/json", + "DNT": "1", + "Origin": "https://aisb.top", + "Pragma": "no-cache", + "Referer": "https://aisb.top/", + "Sec-Fetch-Dest": "empty", + "Sec-Fetch-Mode": "cors", + "Sec-Fetch-Site": "same-origin", + "sec-ch-ua": "\"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"", + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": "\"Windows\"", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36" + }; + + const response = await fetch("https://aisb.top/api/upload", { + method: 'POST', + body: body, + headers: headers + }); + + if (response.ok) { + const result = await response.json(); + if (result && result.url) { + return new Response(result.url); + } else { + return new Response('Error: Unexpected response format', { status: 500 }); + } + } else { + return new Response('Error: ' + await response.text(), { status: response.status }); + } + } + // 复制自 API_IMG_58img.js 的辅助函数 function bufferToBase64(buf) {