feat(forgejo): ✨ add forgejo
This commit is contained in:
parent
9e272b6a62
commit
aaea2e0c7c
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"conventionalCommits.scopes": [
|
"conventionalCommits.scopes": [
|
||||||
"gravatar"
|
"gravatar",
|
||||||
|
"forgejo"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -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.
|
||||||
|
|
|
@ -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",
|
||||||
|
|
45
src/translators/forgejo.ts
Normal file
45
src/translators/forgejo.ts
Normal 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}`
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
Loading…
Reference in a new issue