Return basic Steam user data

This commit is contained in:
Steffo 2024-10-19 04:23:42 +02:00
parent 9f2b880086
commit d8ac0284cb
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0

View file

@ -1,42 +1,75 @@
import { createFederation, Follow, Service } from "@fedify/fedify"
import { createFederation, Service, Application, Image } from "@fedify/fedify"
import { kv } from "./redis.ts"
import { getLogger } from "https://jsr.io/@logtape/logtape/0.6.3/logtape/logger.ts"
import { doQueryPlayer } from "./graphql/stratz.ts"
const l = getLogger(["dotino-veloce", "federation"])
l.debug`Creating federation object...`
export const federation = createFederation<void>({ kv })
const userMatcher = /u([0-9]+)/
l.debug`Creating actor dispatcher...`
// deno-lint-ignore require-await
async function actorDispatcher(ctx: any, handle: string) {
l.debug`Received request for actor ${handle}, handling...`
if (handle !== "service") {
l.debug`No match found for ${handle}, returning null.`
return null
}
l.debug`Determining id of actor ${handle}...`
l.debug`Determining id of requested actor: ${handle}`
const id = ctx.getActorUri(handle)
l.debug`Requested actor is: ${id.href}`
l.info`Returning actor: ${id.href}`
return new Service({
if (handle === "service") {
l.info`Dispatching service account...`
return new Application({
id,
name: "[TEST] Dotino Veloce",
summary: "Core account of a Dotino Veloce instance.",
preferredUsername: id.href,
// Akkoma expects URL to be equal to ID
// https://akkoma.dev/AkkomaGang/akkoma/src/commit/f1018867097e6f293d8b2b5b6935f0a7ebf99bd0/lib/pleroma/object/fetcher.ex#L287
url: id,
// Akkoma requires inboxes to be setup to display profiles
// https://akkoma.dev/AkkomaGang/akkoma/src/commit/f1018867097e6f293d8b2b5b6935f0a7ebf99bd0/lib/pleroma/web/activity_pub/object_validators/user_validator.ex#L72
inbox: ctx.getInboxUri(handle),
name: "[TEST] Dotino Veloce",
summary: "Service account of a Dotino Veloce instance.",
})
}
const steamId = Number.parseInt(handle.match(userMatcher)?.[1] as any)
if(Number.isFinite(steamId)) {
l.info`Dispatching user account with Steam ID: ${steamId}`
const player = await doQueryPlayer(steamId)
if(player === null) {
l.warn`No Steam account was found with ID: ${steamId}`
return null
}
return new Service({
id,
preferredUsername: id.href,
// Akkoma expects URL to be equal to ID
// https://akkoma.dev/AkkomaGang/akkoma/src/commit/f1018867097e6f293d8b2b5b6935f0a7ebf99bd0/lib/pleroma/object/fetcher.ex#L287
url: id,
// Akkoma requires inboxes to be setup to display profiles
// https://akkoma.dev/AkkomaGang/akkoma/src/commit/f1018867097e6f293d8b2b5b6935f0a7ebf99bd0/lib/pleroma/web/activity_pub/object_validators/user_validator.ex#L72
inbox: ctx.getInboxUri(handle),
name: `[TEST] ${player.name}`,
icon: new Image({
url: new URL(player.avatar),
mediaType: "image/jpeg"
})
})
}
l.warn`No dispatcher was found for handle: ${handle}`
return null
}
l.debug`Connecting actor dispatcher to federation object...`
federation.setActorDispatcher("/users/{identifier}", actorDispatcher)
// Akkoma requires inboxes to be setup to display profiles
// https://akkoma.dev/AkkomaGang/akkoma/src/commit/f1018867097e6f293d8b2b5b6935f0a7ebf99bd0/lib/pleroma/web/activity_pub/object_validators/user_validator.ex#L72
l.debug`Initializing inbox listener...`
federation.setInboxListeners("/inbox/{identifier}") // I don't really care about the shared inbox for this project