// Giithub @BlueSkyXN // Code https://gist.github.com/BlueSkyXN/cf009388660348915be2166f6080e02d // 仅供学习CloudFlare Worker开发使用,违规使用后果自负 // License @GPLv3 // 目前该地址经过实验不需要认证,不需要UA、Cookie、Content-Type、Authorization: Bearer等信息,直接上传都行 // 思路来源 https://tencentsb.xyz/md/ 和出处(需要登录或者用谷歌爬虫UA/快照访问) https://jike.info/topic/22192/ // 参考资料 https://www.freebuf.com/articles/system/227532.html // 参考资料 https://github.com/yuolvv/Poor_image_upload 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 response = await fetch("https://www.freebuf.com/fapi/frontend/upload/image", { method: 'POST', headers: { "Accept": "application/json, text/plain, */*", "Referer": "https://www.freebuf.com/write", "User-Agent": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" }, body: formData }) const data = await response.json() let imageUrl = data.data.url.replace(/\\/g, "").replace('!small', ''); // 使用正则确保URL的开头是https:,并且没有重复的斜线 imageUrl = imageUrl.replace(/^https?:/, 'https:'); imageUrl = imageUrl.replace(/([^:]\/)\/+/g, "$1"); return new Response(JSON.stringify({ imageUrl }), { headers: { 'Content-Type': 'application/json' } }) } } const html = `
建议上传10M以内的JPG/PNG/JPEG/ICO/WEBP/GIF文件,注意不兼容视频和其他非图像文件
兼容格式:xbm/tif/jfif/ico/tiff/gif/svg/jpeg/svgz/jpg/webp/png/bmp/pjp/apng/pjpeg/avif
该源码开源,仅供学习JS使用,违规使用后果自负