Compare commits

..

No commits in common. "e81de2aecc0e57eaaa0acc101c46ea81869a6021" and "6d805dc7c62b1bb21987d4630db622a0f131cf99" have entirely different histories.

3 changed files with 1 additions and 85 deletions

View file

@ -11,10 +11,6 @@ All settings for endpoints are configured in query parameters.
- `identifier`: Bluesky handle - `identifier`: Bluesky handle
- `password`: Bluesky password - create an app password in settings - `password`: Bluesky password - create an app password in settings
### `/gravatar`
- `cookie`: Your `gravatar` cookie.
### `/misskey` ### `/misskey`
- `instance`: Link to your Misskey instance. Include protocol. - `instance`: Link to your Misskey instance. Include protocol.

View file

@ -1,6 +1,6 @@
{ {
"name": "avahooks", "name": "avahooks",
"version": "1.1.0", "version": "1.0.6",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"start": "node ./dist/index.js", "start": "node ./dist/index.js",

View file

@ -1,80 +0,0 @@
import { z } from "zod"
import { translator } from "../lib/types.js"
import downloadAvatarForPayload from "../lib/downloadAvatarForPayload.js"
export default translator({
query: z.object({
cookie: z.string().describe("Your `gravatar` cookie."),
}),
async execute(payload, { cookie }) {
// unsure regarding supported image formats;
// just to play it safe, prefer png then jpeg
const avatar = await downloadAvatarForPayload(payload, [
"png",
"jpeg",
undefined,
])
if (!avatar) throw new Error("gravatar: failed to get avatar")
const Cookie = `gravatar=${encodeURIComponent(cookie)}; is-logged-in=1`
// construct fd
const fd = new FormData()
fd.append("image", avatar)
fd.append("source", "direct")
fd.append("forceIdentity", "false")
// upload the avatar
const uploadResult = await fetch(
"https://api.gravatar.com/v2/users/me/image",
{
body: fd,
method: "POST",
headers: { Cookie },
}
)
if (!uploadResult.ok)
throw new Error(
`gravatar: upload failed with ${uploadResult.status}`
)
const {
email_hash,
image_id,
}: { email_hash: string; image_id: string } = await uploadResult.json()
// set its alt text
if (payload.altText) {
let req = await fetch(
`https://api.gravatar.com/v2/users/me/image/${image_id}`,
{
method: "POST",
body: JSON.stringify({ altText: payload.altText }),
headers: { Cookie },
}
)
if (!req.ok)
console.warn(`gravatar: alt text set failed with ${req.status}`)
}
// set it as user avatar
const setUserAvatarResult = await fetch(
`/v2/users/me/identity/${email_hash}`,
{
method: "POST",
body: JSON.stringify({ image_id }),
headers: { Cookie },
}
)
if (!setUserAvatarResult.ok)
throw new Error(
`gravatar: set user avatar failed with ${setUserAvatarResult.status}`
)
},
})