TGPH临时修复方案,来自
https://www.nodeseek.com/post-159355-1
This commit is contained in:
BlueSkyXN 2024-09-12 22:16:19 +08:00
parent 844e84baa2
commit 22bfbd6e44
4 changed files with 41 additions and 2 deletions

View File

@ -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)

View File

@ -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>

View File

@ -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, {

View File

@ -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;
@ -616,4 +619,39 @@ async function handleRequest(request) {
return new Response('Internal Server Error', { status: 500 }); return new Response('Internal Server Error', { status: 500 });
} }
} }
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 });
}
}