feat(gravatar): ✨ specify email for avatar
This commit is contained in:
parent
e81de2aecc
commit
e2c99d8e96
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"conventionalCommits.scopes": [
|
||||
"gravatar"
|
||||
]
|
||||
}
|
|
@ -14,6 +14,7 @@ All settings for endpoints are configured in query parameters.
|
|||
### `/gravatar`
|
||||
|
||||
- `cookie`: Your `gravatar` cookie.
|
||||
- `email` (optional): Email to set the profile picture for.
|
||||
|
||||
### `/misskey`
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "avahooks",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node ./dist/index.js",
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
import { z } from "zod"
|
||||
import { translator } from "../lib/types.js"
|
||||
import downloadAvatarForPayload from "../lib/downloadAvatarForPayload.js"
|
||||
import crypto from "node:crypto"
|
||||
export default translator({
|
||||
query: z.object({
|
||||
cookie: z.string().describe("Your `gravatar` cookie."),
|
||||
email: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe("Email to set the profile picture for."),
|
||||
}),
|
||||
async execute(payload, { cookie }) {
|
||||
async execute(payload, { cookie, email }) {
|
||||
// unsure regarding supported image formats;
|
||||
// just to play it safe, prefer png then jpeg
|
||||
|
||||
|
@ -41,10 +46,15 @@ export default translator({
|
|||
`gravatar: upload failed with ${uploadResult.status}`
|
||||
)
|
||||
|
||||
const {
|
||||
email_hash,
|
||||
image_id,
|
||||
}: { email_hash: string; image_id: string } = await uploadResult.json()
|
||||
const uprRes: { email_hash: string; image_id: string } =
|
||||
await uploadResult.json(),
|
||||
{ image_id } = uprRes,
|
||||
email_hash = email
|
||||
? crypto
|
||||
.createHash("md5")
|
||||
.update(email.toLowerCase())
|
||||
.digest("hex")
|
||||
: uprRes.email_hash
|
||||
|
||||
// set its alt text
|
||||
|
||||
|
|
Loading…
Reference in a new issue