From 7d3ab00c2ac0da3ef1d6ee05081cb0b960d64502 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 22 Oct 2024 05:19:31 +0200 Subject: [PATCH] Various things --- .vscode/launch.json | 1 + src/deno/logging.ts | 2 +- src/deno/router.ts | 2 +- src/dv/favicon.ts | 2 +- src/dv/hostMeta.ts | 2 +- src/dv/{dotinoVeloce.ts => index.ts} | 45 ++++++++++++++++++++++++---- src/entry/server.ts | 2 +- 7 files changed, 45 insertions(+), 11 deletions(-) rename src/dv/{dotinoVeloce.ts => index.ts} (89%) diff --git a/.vscode/launch.json b/.vscode/launch.json index 0b30c2a..b373eb9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -29,6 +29,7 @@ "cwd": "${workspaceFolder}", "envFile": "${workspaceFolder}/local.env", "runtimeExecutable": "/usr/bin/deno", + "restart": true, "runtimeArgs": [ "run", "--watch", diff --git a/src/deno/logging.ts b/src/deno/logging.ts index 866f0b7..d99cad1 100644 --- a/src/deno/logging.ts +++ b/src/deno/logging.ts @@ -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" }, ], }) diff --git a/src/deno/router.ts b/src/deno/router.ts index e905f8f..82715f5 100644 --- a/src/deno/router.ts +++ b/src/deno/router.ts @@ -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" diff --git a/src/dv/favicon.ts b/src/dv/favicon.ts index 04e9045..dc8eace 100644 --- a/src/dv/favicon.ts +++ b/src/dv/favicon.ts @@ -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 { diff --git a/src/dv/hostMeta.ts b/src/dv/hostMeta.ts index d7f6a1d..a706be4 100644 --- a/src/dv/hostMeta.ts +++ b/src/dv/hostMeta.ts @@ -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 diff --git a/src/dv/dotinoVeloce.ts b/src/dv/index.ts similarity index 89% rename from src/dv/dotinoVeloce.ts rename to src/dv/index.ts index 4843169..bc39724 100644 --- a/src/dv/dotinoVeloce.ts +++ b/src/dv/index.ts @@ -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({ kv: db.useAsKvStore() }) + this.federation = createFederation({ + 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) => ({ 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): Promise { + 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, handle: string): Promise> { @@ -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: `https://www.dotabuff.com/players/${player.id}`, }), - ] + ], }) l.debug`Generated ActivityPub actor for player ${steamId}: ${actor}` diff --git a/src/entry/server.ts b/src/entry/server.ts index eb9bc68..cf9bfc2 100644 --- a/src/entry/server.ts +++ b/src/entry/server.ts @@ -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"