新增 https://mlw10086.serv00.net/
This commit is contained in:
BlueSkyXN 2024-09-07 19:26:50 +08:00
parent b2e3f088e3
commit 2c23a9ae44
3 changed files with 125 additions and 2 deletions

View File

@ -69,8 +69,9 @@
<div class="form-group"> <div class="form-group">
<label for="apiSelect">Select Endpoint</label> <label for="apiSelect">Select Endpoint</label>
<select class="form-control" id="apiSelect"> <select class="form-control" id="apiSelect">
<option value="58img">api-58img</option> <option value="58img">58img</option>
<option value="aagmoe">ihs.aag.moe</option> <option value="aagmoe">ihs.aag.moe</option>
<option value="10086">10086</option>
</select> </select>
</div> </div>
<div class="form-check mb-2"> <div class="form-check mb-2">

View File

@ -0,0 +1,61 @@
addEventListener('fetch', event => {
event.respondWith(handlemlw10086Request(event.request));
})
async function handlemlw10086Request(request) {
try {
// 确认请求方法为 POST 并且内容类型正确
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'); // 假设字段名为 'image'
if (!imageFile) return new Response('Image file not found', { status: 400 });
// 创建新的 FormData 对象,并将 'image' 字段重命名为 'file'
const newFormData = new FormData();
newFormData.append('file', imageFile); // 使用目标接口的字段名 'file'
// mlw10086.serv00.net 的上传接口
const targetUrl = 'https://mlw10086.serv00.net/upload.php';
// 为了与 mlw10086.serv00.net 接口兼容,我们保留表单数据的格式并直接转发
const response = await fetch(targetUrl, {
method: 'POST',
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',
'Origin': 'https://mlw10086.serv00.net',
'Pragma': 'no-cache',
'Referer': 'https://mlw10086.serv00.net/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
'Sec-CH-UA': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
'Sec-CH-UA-Mobile': '?0',
'Sec-CH-UA-Platform': '"Windows"',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'DNT': '1'
}
});
// 处理响应
if (response.ok) {
const result = await response.json();
if (result && result.success && result.file_url) {
return new Response(result.file_url, { status: 200 });
} else {
return new Response('Error: Unexpected response format or upload failed', { status: 500 });
}
} else {
return new Response('Error: ' + await response.text(), { status: response.status });
}
} catch (error) {
console.error('Caught an error:', error);
return new Response('Server Error', { status: 500 });
}
}

View File

@ -41,6 +41,9 @@ async function handleRequest(request) {
case '/upload/aagmoe': case '/upload/aagmoe':
response = await handleaagmoeRequest(request); response = await handleaagmoeRequest(request);
break; break;
case '/upload/10086':
response = await handlemlw10086Request(request);
break;
default: default:
response = new Response('Not Found', { status: 404 }); response = new Response('Not Found', { status: 404 });
break; break;
@ -193,4 +196,62 @@ async function handleRequest(request) {
return new Response('Server Error', { status: 500 }); return new Response('Server Error', { status: 500 });
} }
} }
async function handlemlw10086Request(request) {
try {
// 确认请求方法为 POST 并且内容类型正确
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'); // 假设字段名为 'image'
if (!imageFile) return new Response('Image file not found', { status: 400 });
// 创建新的 FormData 对象,并将 'image' 字段重命名为 'file'
const newFormData = new FormData();
newFormData.append('file', imageFile); // 使用目标接口的字段名 'file'
// mlw10086.serv00.net 的上传接口
const targetUrl = 'https://mlw10086.serv00.net/upload.php';
// 为了与 mlw10086.serv00.net 接口兼容,我们保留表单数据的格式并直接转发
const response = await fetch(targetUrl, {
method: 'POST',
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',
'Origin': 'https://mlw10086.serv00.net',
'Pragma': 'no-cache',
'Referer': 'https://mlw10086.serv00.net/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
'Sec-CH-UA': '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"',
'Sec-CH-UA-Mobile': '?0',
'Sec-CH-UA-Platform': '"Windows"',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'DNT': '1'
}
});
// 处理响应
if (response.ok) {
const result = await response.json();
if (result && result.success && result.file_url) {
return new Response(result.file_url, { status: 200 });
} else {
return new Response('Error: Unexpected response format or upload failed', { status: 500 });
}
} else {
return new Response('Error: ' + await response.text(), { status: response.status });
}
} catch (error) {
console.error('Caught an error:', error);
return new Response('Server Error', { status: 500 });
}
}