feat(forgejo): add forgejo

This commit is contained in:
May 2024-11-23 00:01:28 -08:00
parent 9e272b6a62
commit aaea2e0c7c
Signed by: split
GPG key ID: C325C61F0BF517C0
4 changed files with 53 additions and 2 deletions

View file

@ -1,5 +1,6 @@
{ {
"conventionalCommits.scopes": [ "conventionalCommits.scopes": [
"gravatar" "gravatar",
"forgejo"
] ]
} }

View file

@ -11,6 +11,11 @@ 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
### `/forgejo`
- `instance`: Link to your Forgejo instance. Include protocol.
- `apiKey`: Forgejo API key.
### `/gravatar` ### `/gravatar`
- `cookie`: Your `gravatar` cookie. - `cookie`: Your `gravatar` cookie.

View file

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

View file

@ -0,0 +1,45 @@
import { z } from "zod"
import { translator } from "../lib/types.js"
import downloadAvatarForPayload from "../lib/downloadAvatarForPayload.js"
export default translator({
query: z.object({
instance: z
.string()
.describe("Link to your Forgejo instance. Include protocol."),
apiKey: z.string().describe("Forgejo API key."),
}),
async execute(payload, { instance, apiKey }) {
const avatar = await downloadAvatarForPayload(payload, [
"png",
"jpeg",
"webp",
"gif",
undefined,
])
if (!avatar) throw new Error("forgejo: failed to get avatar")
// update the user avatar
let updateRequest = await fetch(
new URL("/api/v1/user/avatar", instance),
{
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
avatar: `data:${avatar.type};base64,${Buffer.from(
await avatar.arrayBuffer()
).toString("base64")}`,
}),
method: "POST",
}
)
if (!updateRequest.ok)
console.error(
`forgejo: updating avatar, got ${updateRequest.status}`
)
},
})