mirror of
https://github.com/BlueSkyXN/WorkerJS_CloudFlare_ImageBed.git
synced 2024-11-16 03:32:26 +08:00
parent
844e84baa2
commit
22bfbd6e44
|
@ -20,4 +20,4 @@
|
||||||
- 20240906 TG创始人被抓后开始降本增效,停用了TGPH上传
|
- 20240906 TG创始人被抓后开始降本增效,停用了TGPH上传
|
||||||
- 20240907 新增10086和TX2个渠道
|
- 20240907 新增10086和TX2个渠道
|
||||||
- 20240908 新增 da8m,qts8,vviptuangou三个,均来自之前的10086,今天发现他改版了
|
- 20240908 新增 da8m,qts8,vviptuangou三个,均来自之前的10086,今天发现他改版了
|
||||||
- 20240912 新增 ipfs-img对接,来自 [https://www.nodeseek.com/post-158028-1](https://www.nodeseek.com/post-158028-1)
|
- 20240912 新增 ipfs-img对接,来自 [https://www.nodeseek.com/post-158028-1](https://www.nodeseek.com/post-158028-1),TGPH临时修复方案,来自 [https://www.nodeseek.com/post-159355-1](https://www.nodeseek.com/post-159355-1)
|
||||||
|
|
|
@ -70,6 +70,7 @@
|
||||||
<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="10086">10086</option>
|
<option value="10086">10086</option>
|
||||||
|
<option value="tgphimg">tgph-official</option>
|
||||||
<option value="ipfs">IPFS</option>
|
<option value="ipfs">IPFS</option>
|
||||||
<option value="58img">58img</option>
|
<option value="58img">58img</option>
|
||||||
<option value="tencent">Tencent</option>
|
<option value="tencent">Tencent</option>
|
||||||
|
|
|
@ -14,7 +14,7 @@ async function handleTgphimgRequest(request) {
|
||||||
if (!imageFile) return new Response('Image file not found', { status: 400 });
|
if (!imageFile) return new Response('Image file not found', { status: 400 });
|
||||||
|
|
||||||
// Telegra.ph 的上传接口
|
// Telegra.ph 的上传接口
|
||||||
const targetUrl = 'https://telegra.ph/upload';
|
const targetUrl = 'https://telegra.ph/upload?source=bugtracker';
|
||||||
|
|
||||||
// 为了与 Telegra.ph 接口兼容,我们保留表单数据的格式并直接转发
|
// 为了与 Telegra.ph 接口兼容,我们保留表单数据的格式并直接转发
|
||||||
const response = await fetch(targetUrl, {
|
const response = await fetch(targetUrl, {
|
||||||
|
|
|
@ -59,6 +59,9 @@ async function handleRequest(request) {
|
||||||
case '/upload/ipfs':
|
case '/upload/ipfs':
|
||||||
response = await handleimg2ipfsRequest(request);
|
response = await handleimg2ipfsRequest(request);
|
||||||
break;
|
break;
|
||||||
|
case '/upload/tgphimg':
|
||||||
|
response = await handleTgphimgRequest(request);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
response = new Response('Not Found', { status: 404 });
|
response = new Response('Not Found', { status: 404 });
|
||||||
break;
|
break;
|
||||||
|
@ -617,3 +620,38 @@ async function handleRequest(request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleTgphimgRequest(request) {
|
||||||
|
// 确认请求方法为 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 });
|
||||||
|
|
||||||
|
// Telegra.ph 的上传接口
|
||||||
|
const targetUrl = 'https://telegra.ph/upload?source=bugtracker';
|
||||||
|
|
||||||
|
// 为了与 Telegra.ph 接口兼容,我们保留表单数据的格式并直接转发
|
||||||
|
const response = await fetch(targetUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
|
||||||
|
// 处理响应
|
||||||
|
if (response.ok) {
|
||||||
|
const result = await response.json();
|
||||||
|
if (result && result[0] && result[0].src) {
|
||||||
|
const imageUrl = `https://telegra.ph${result[0].src}`;
|
||||||
|
// 直接返回图片 URL 而不是 JSON 对象
|
||||||
|
return new Response(imageUrl);
|
||||||
|
} else {
|
||||||
|
return new Response('Error: Unexpected response format', { status: 500 });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return new Response('Error: ' + await response.text(), { status: response.status });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user