Merge pull request #9 from SkyDream01/main

添加返回图片
This commit is contained in:
叁月柒
2024-08-09 14:09:55 +08:00
committed by GitHub
+11 -1
View File
@@ -33,10 +33,20 @@ export async function onRequest(context) {
randomUrl = protocol + '//' + domain + randomPath;
}
}
// if param 'type' is set to 'img', return the image
if (randomType === 'img') {
// Return an image response
randomUrl = protocol + '//' + domain + ':' + port + randomPath;
return new Response(await fetch(randomUrl).then(res => res.blob()), {
headers: { 'Content-Type': 'image/jpeg' },
status: 200
});
}
if (resType == 'text') {
return new Response(randomUrl, { status: 200 });
} else {
return new Response(JSON.stringify({ url: randomUrl }), { status: 200 });
}
}
}
}