···
async fetch(request, env) {
+
// Helper function to generate a color from a string
+
const stringToColor = (str) => {
+
for (let i = 0; i < str.length; i++) {
+
hash = str.charCodeAt(i) + ((hash << 5) - hash);
+
for (let i = 0; i < 3; i++) {
+
const value = (hash >> (i * 8)) & 0xff;
+
color += ("00" + value.toString(16)).substr(-2);
const url = new URL(request.url);
const { pathname, searchParams } = url;
···
const profile = await profileResponse.json();
const avatar = profile.avatar;
+
let avatarUrl = profile.avatar;
+
// Generate a random color based on the actor string
+
const bgColor = stringToColor(actor);
+
const size = resizeToTiny ? 32 : 128;
+
const svg = `<svg width="${size}" height="${size}" viewBox="0 0 ${size} ${size}" xmlns="http://www.w3.org/2000/svg"><rect width="${size}" height="${size}" fill="${bgColor}"/></svg>`;
+
const svgData = new TextEncoder().encode(svg);
+
response = new Response(svgData, {
+
"Content-Type": "image/svg+xml",
+
"Cache-Control": "public, max-age=43200",
+
await cache.put(cacheKey, response.clone());
+
avatarResponse = await fetch(avatarUrl, {
···
+
avatarResponse = await fetch(avatarUrl);
if (!avatarResponse.ok) {