diff --git a/cloudflare-worker-js-api/API_IMG_aagmoe.js b/cloudflare-worker-js-api/API_IMG_aagmoe.js index b180776..8cea704 100644 --- a/cloudflare-worker-js-api/API_IMG_aagmoe.js +++ b/cloudflare-worker-js-api/API_IMG_aagmoe.js @@ -14,18 +14,21 @@ async function handleaagmoeRequest(request) { const imageFile = formData.get('image'); // 假设字段名为 'image' if (!imageFile) return new Response('Image file not found', { status: 400 }); + // 创建新的 FormData 对象,并将 'image' 字段重命名为 'file' + const newFormData = new FormData(); + newFormData.append('file', imageFile); // 使用目标接口的字段名 'file' + // ihs.aag.moe 的上传接口 const targetUrl = 'https://ihs.aag.moe/upload.php'; // 为了与 ihs.aag.moe 接口兼容,我们保留表单数据的格式并直接转发 const response = await fetch(targetUrl, { method: 'POST', - body: formData, + body: newFormData, // 使用新的 FormData 对象 headers: { 'Accept': '*/*', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7', 'Cache-Control': 'no-cache', - 'Content-Type': request.headers.get('Content-Type'), 'Origin': 'https://ihs.aag.moe', 'Pragma': 'no-cache', 'Referer': 'https://ihs.aag.moe/', diff --git a/cloudflare-worker-js-api/worker.js b/cloudflare-worker-js-api/worker.js index cfb802f..861f4a6 100644 --- a/cloudflare-worker-js-api/worker.js +++ b/cloudflare-worker-js-api/worker.js @@ -124,9 +124,17 @@ async function handleRequest(request) { } } - addEventListener('fetch', event => { - event.respondWith(handleaagmoeRequest(event.request)); - }) + // 复制自 API_IMG_58img.js 的辅助函数 + function bufferToBase64(buf) { + var binary = ''; + var bytes = new Uint8Array(buf); + var len = bytes.byteLength; + for (var i = 0; i < len; i++) { + binary += String.fromCharCode(bytes[i]); + } + // 使用 btoa 进行 Base64 编码 + return btoa(binary); + } async function handleaagmoeRequest(request) { try { @@ -140,18 +148,21 @@ async function handleRequest(request) { const imageFile = formData.get('image'); // 假设字段名为 'image' if (!imageFile) return new Response('Image file not found', { status: 400 }); + // 创建新的 FormData 对象,并将 'image' 字段重命名为 'file' + const newFormData = new FormData(); + newFormData.append('file', imageFile); // 使用目标接口的字段名 'file' + // ihs.aag.moe 的上传接口 const targetUrl = 'https://ihs.aag.moe/upload.php'; // 为了与 ihs.aag.moe 接口兼容,我们保留表单数据的格式并直接转发 const response = await fetch(targetUrl, { method: 'POST', - body: formData, + body: newFormData, // 使用新的 FormData 对象 headers: { 'Accept': '*/*', 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7', 'Cache-Control': 'no-cache', - 'Content-Type': request.headers.get('Content-Type'), 'Origin': 'https://ihs.aag.moe', 'Pragma': 'no-cache', 'Referer': 'https://ihs.aag.moe/', @@ -182,18 +193,4 @@ async function handleRequest(request) { return new Response('Server Error', { status: 500 }); } } - - - - // 复制自 API_IMG_58img.js 的辅助函数 - function bufferToBase64(buf) { - var binary = ''; - var bytes = new Uint8Array(buf); - var len = bytes.byteLength; - for (var i = 0; i < len; i++) { - binary += String.fromCharCode(bytes[i]); - } - // 使用 btoa 进行 Base64 编码 - return btoa(binary); - } \ No newline at end of file diff --git a/python-uploader/test.py b/python-uploader/test.py new file mode 100644 index 0000000..02a0679 --- /dev/null +++ b/python-uploader/test.py @@ -0,0 +1,36 @@ +import requests + +def upload_image(file_path): + url = "https://ihs.aag.moe/upload.php" + headers = { + 'accept': '*/*', + 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7', + 'cache-control': 'no-cache', + 'dnt': '1', + 'origin': 'https://ihs.aag.moe', + 'pragma': 'no-cache', + 'referer': 'https://ihs.aag.moe/', + 'sec-ch-ua': '"Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"', + 'sec-ch-ua-mobile': '?0', + 'sec-ch-ua-platform': '"Windows"', + 'sec-fetch-dest': 'empty', + 'sec-fetch-mode': 'cors', + 'sec-fetch-site': 'same-origin', + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36', + } + + # 打开图片文件并使用 multipart/form-data 发送 + with open(file_path, 'rb') as image_file: + files = {'file': image_file} # 上传文件的字段名为 'file' + response = requests.post(url, headers=headers, files=files) + + # 输出响应信息 + print(f"响应体: {response}") + print(f"HTTP 状态码: {response.status_code}") + print(f"响应内容: {response.text}") + +# 本地图片文件路径 +file_path = "F:\\Download\\b52d18627d2ce06dcf22b0b777b51fde410fb4da.jpg@100Q.jpg" + +# 执行上传 +upload_image(file_path)