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`
|
### `/gravatar`
|
||||||
|
|
||||||
- `cookie`: Your `gravatar` cookie.
|
- `cookie`: Your `gravatar` cookie.
|
||||||
|
- `email` (optional): Email to set the profile picture for.
|
||||||
|
|
||||||
### `/misskey`
|
### `/misskey`
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "avahooks",
|
"name": "avahooks",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./dist/index.js",
|
"start": "node ./dist/index.js",
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { translator } from "../lib/types.js"
|
import { translator } from "../lib/types.js"
|
||||||
import downloadAvatarForPayload from "../lib/downloadAvatarForPayload.js"
|
import downloadAvatarForPayload from "../lib/downloadAvatarForPayload.js"
|
||||||
|
import crypto from "node:crypto"
|
||||||
export default translator({
|
export default translator({
|
||||||
query: z.object({
|
query: z.object({
|
||||||
cookie: z.string().describe("Your `gravatar` cookie."),
|
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;
|
// unsure regarding supported image formats;
|
||||||
// just to play it safe, prefer png then jpeg
|
// just to play it safe, prefer png then jpeg
|
||||||
|
|
||||||
|
@ -41,10 +46,15 @@ export default translator({
|
||||||
`gravatar: upload failed with ${uploadResult.status}`
|
`gravatar: upload failed with ${uploadResult.status}`
|
||||||
)
|
)
|
||||||
|
|
||||||
const {
|
const uprRes: { email_hash: string; image_id: string } =
|
||||||
email_hash,
|
await uploadResult.json(),
|
||||||
image_id,
|
{ image_id } = uprRes,
|
||||||
}: { email_hash: string; image_id: string } = await uploadResult.json()
|
email_hash = email
|
||||||
|
? crypto
|
||||||
|
.createHash("md5")
|
||||||
|
.update(email.toLowerCase())
|
||||||
|
.digest("hex")
|
||||||
|
: uprRes.email_hash
|
||||||
|
|
||||||
// set its alt text
|
// set its alt text
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue