From 577a856eed39f987dfeeaffa603d9557682c2183 Mon Sep 17 00:00:00 2001 From: split Date: Fri, 22 Nov 2024 21:59:45 -0800 Subject: [PATCH] fix(gravatar): :bug: ughhh --- src/translators/gravatar.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/translators/gravatar.ts b/src/translators/gravatar.ts index 190026f..2b788d0 100644 --- a/src/translators/gravatar.ts +++ b/src/translators/gravatar.ts @@ -22,7 +22,7 @@ export default translator({ if (!avatar) throw new Error("gravatar: failed to get avatar") - const Cookie = `gravatar=${encodeURIComponent(cookie)}; is-logged-in=1` + const Cookie = `gravatar=${cookie}; is-logged-in=1` // construct fd const fd = new FormData() @@ -33,11 +33,15 @@ export default translator({ // upload the avatar const uploadResult = await fetch( - "https://api.gravatar.com/v2/users/me/image", + "https://api.gravatar.com/v2/users/me/image?_locale=&source=web-app-editor", { body: fd, method: "POST", - headers: { Cookie }, + headers: { + Cookie, + "Alt-Used": "api.gravatar.com", + "X-GR-Nonce": crypto.randomUUID(), + }, } ) @@ -60,11 +64,15 @@ export default translator({ if (payload.altText) { let req = await fetch( - `https://api.gravatar.com/v2/users/me/image/${image_id}`, + `https://api.gravatar.com/v2/users/me/image/${image_id}?_locale=&source=web-app-editor`, { method: "POST", body: JSON.stringify({ altText: payload.altText }), - headers: { Cookie }, + headers: { + Cookie, + "Alt-Used": "api.gravatar.com", + "X-GR-Nonce": crypto.randomUUID(), + }, } ) if (!req.ok) @@ -74,11 +82,15 @@ export default translator({ // set it as user avatar const setUserAvatarResult = await fetch( - `/v2/users/me/identity/${email_hash}`, + `https://api.gravatar.com/v2/users/me/identity/${email_hash}?_locale=&source=web-app-editor`, { method: "POST", body: JSON.stringify({ image_id }), - headers: { Cookie }, + headers: { + Cookie, + "Alt-Used": "api.gravatar.com", + "X-GR-Nonce": crypto.randomUUID(), + }, } )