// Github @BlueSkyXN // Code https://gist.github.com/BlueSkyXN/8d261d13d79e7a7672999f9935acdfe9 // 仅供学习CloudFlare Worker开发使用,违规使用后果自负 // License @GPLv3 addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)) }) async function handleRequest(request) { if (request.method === 'GET') { return new Response(html, { headers: { 'content-type': 'text/html;charset=UTF-8', }, }) } else if (request.method === 'POST') { const formData = await request.formData() const file = formData.get('file') const apiOption = formData.get('apiOption') || 'api-tgph-official'; let apiUrl = 'https://telegra.ph/upload'; if (apiOption === 'api-tgph-cachefly') { apiUrl = 'https://telegraph.cachefly.net/upload'; } else if (apiOption === 'api-tgph-other') { apiUrl = 'https://telegra.ph/upload'; } const response = await fetch(apiUrl, { method: 'POST', body: formData }) const data = await response.json() let imageUrl = 'https://telegra.ph' + data[0].src; return new Response(JSON.stringify({ imageUrl }), { headers: { 'Content-Type': 'application/json' } }) } } const html = `