Various things

This commit is contained in:
Steffo 2024-10-22 05:19:31 +02:00
parent 58d4e3b8a4
commit 7d3ab00c2a
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
7 changed files with 45 additions and 11 deletions

1
.vscode/launch.json vendored
View file

@ -29,6 +29,7 @@
"cwd": "${workspaceFolder}",
"envFile": "${workspaceFolder}/local.env",
"runtimeExecutable": "/usr/bin/deno",
"restart": true,
"runtimeArgs": [
"run",
"--watch",

View file

@ -10,7 +10,7 @@ export async function initLogging() {
filters: {},
loggers: [
{ category: ["logtape", "meta"], sinks: ["console"], level: "warning" },
{ category: ["fedify"], sinks: ["console"], level: "info" },
{ category: ["fedify"], sinks: ["console"], level: "debug" },
{ category: ["dotino-veloce"], sinks: ["console"], level: "debug" },
],
})

View file

@ -1,6 +1,6 @@
import { getLogger } from "@logtape/logtape"
import { handleHostMeta } from "../dv/hostMeta.ts"
import { DotinoVeloce } from "../dv/dotinoVeloce.ts"
import { DotinoVeloce } from "../dv/index.ts"
import { handleFavicon } from "../dv/favicon.ts"

View file

@ -1,7 +1,7 @@
import { getLogger } from "@logtape/logtape"
const l = getLogger(["dotino-veloce", "ap", "favicon"])
const l = getLogger(["dotino-veloce", "dv", "favicon"])
export async function handleFavicon(): Promise<Response> {

View file

@ -1,7 +1,7 @@
import { getLogger } from "@logtape/logtape"
const l = getLogger(["dotino-veloce", "ap", "hostMeta"])
const l = getLogger(["dotino-veloce", "dv", "hostMeta"])
// deno-lint-ignore require-await

View file

@ -1,12 +1,12 @@
// deno-lint-ignore-file require-await
import { createFederation, Person, Application, Image, PropertyValue, Organization, Federation, KvStore, Context, Actor, Follow, Endpoints, importSpki, importJwk } from "@fedify/fedify"
import { createFederation, Person, Application, Image, PropertyValue, Organization, Federation, KvStore, Context, Actor, Follow, Endpoints, importSpki, importJwk, NodeInfo } from "@fedify/fedify"
import { getLogger } from "https://jsr.io/@logtape/logtape/0.6.3/logtape/logger.ts"
import { escapeHtml } from "@@x/escape"
import { StratzAPI } from "../stratz/api.ts"
import { Database } from "../database/index.ts"
const l = getLogger(["dotino-veloce", "ap", "federation"])
const l = getLogger(["dotino-veloce", "dv", "index"])
type ContextData = undefined
@ -21,17 +21,50 @@ export class DotinoVeloce {
this.db = db
this.stratz = stratz
this.federation = createFederation<ContextData>({ kv: db.useAsKvStore() })
this.federation = createFederation<ContextData>({
kv: db.useAsKvStore(),
})
this.federation
.setActorDispatcher("/users/{identifier}", this.#actorHandler.bind(this))
.setKeyPairsDispatcher(this.#actorKeys.bind(this))
.mapHandle(this.#actorMapper.bind(this))
.authorize(this.#authorizationHandler.bind(this))
this.federation
.setInboxListeners("/inbox/{identifier}", "/inbox")
// Akkoma with Authorized Fetch requires this to be set
// https://p.junimo.party/#/junimo.party/s/AnFW6s3OURPMY04LKq?view=full
.setSharedKeyDispatcher((_ctx: Context<ContextData>) => ({ identifier: "service" }))
.on(Follow, this.#followHandler.bind(this))
this.federation
.setNodeInfoDispatcher("/nodeinfo/2.1", this.#nodeInfoHandler.bind(this))
// TODO: Setup a message queue
}
async #nodeInfoHandler(ctx: Context<ContextData>): Promise<NodeInfo> {
return {
software: {
name: "dotino-veloce",
version: {
major: 0,
minor: 1,
patch: 0,
},
repository: new URL("https://forge.steffo.eu/steffo/dotino-veloce"),
},
protocols: ["activitypub"],
usage: {
users: {
total: 0,
activeHalfyear: 0,
activeMonth: 0,
},
localPosts: 0,
localComments: 0,
}
}
}
async #commonActorProperties(ctx: Context<ContextData>, handle: string): Promise<Partial<Actor>> {
@ -67,7 +100,7 @@ export class DotinoVeloce {
l.debug`Handle ${handle}'s SteamID seems to be: ${steamId}`
l.debug`Making sure the SteamID parsing didn't explode...`
if(Number.isFinite(steamId)) {
if(!Number.isFinite(steamId)) {
l.error`SteamID parsing for ${handle} exploded with ${steamId}, returning null.`
return null
}
@ -105,7 +138,7 @@ export class DotinoVeloce {
name: "DOTABUFF",
value: `<a href="https://www.dotabuff.com/players/${player.id}">https://www.dotabuff.com/players/${player.id}</a>`,
}),
]
],
})
l.debug`Generated ActivityPub actor for player ${steamId}: ${actor}`

View file

@ -3,7 +3,7 @@ import { initLogging } from "../deno/logging.ts"
import { StratzAPI } from "../stratz/api.ts"
import { behindProxy, Fetch } from "@hongminhee/x-forwarded-fetch"
import { createRouter } from "../deno/router.ts"
import { DotinoVeloce } from "../dv/dotinoVeloce.ts"
import { DotinoVeloce } from "../dv/index.ts"
import { Database } from "../database/index.ts"