mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(federation): ♻️ Replace WebFinger code with @lysand-org/federation logic, add new debug command
This commit is contained in:
parent
38c8ea24a9
commit
cea9452127
15 changed files with 256 additions and 99 deletions
51
cli/commands/federation/user/fetch.ts
Normal file
51
cli/commands/federation/user/fetch.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { SignatureConstructor } from "@lysand-org/federation";
|
||||
import { FederationRequester } from "@lysand-org/federation/requester";
|
||||
import { Args } from "@oclif/core";
|
||||
import chalk from "chalk";
|
||||
import ora from "ora";
|
||||
import { BaseCommand } from "~/cli/base";
|
||||
import { User } from "~/packages/database-interface/user";
|
||||
|
||||
export default class FederationUserFetch extends BaseCommand<
|
||||
typeof FederationUserFetch
|
||||
> {
|
||||
static override args = {
|
||||
address: Args.string({
|
||||
description: "Address of remote user (name@host.com)",
|
||||
required: true,
|
||||
}),
|
||||
};
|
||||
|
||||
static override description = "Fetch the URL of remote users via WebFinger";
|
||||
|
||||
static override examples = ["<%= config.bin %> <%= command.id %>"];
|
||||
|
||||
static override flags = {};
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const { args } = await this.parse(FederationUserFetch);
|
||||
|
||||
const spinner = ora("Fetching user URI").start();
|
||||
|
||||
const [username, host] = args.address.split("@");
|
||||
|
||||
const requester = await User.getServerActor();
|
||||
|
||||
const signatureConstructor = await SignatureConstructor.fromStringKey(
|
||||
requester.data.privateKey ?? "",
|
||||
requester.getUri(),
|
||||
);
|
||||
const manager = new FederationRequester(
|
||||
new URL(`https://${host}`),
|
||||
signatureConstructor,
|
||||
);
|
||||
|
||||
const uri = await manager.webFinger(username);
|
||||
|
||||
spinner.succeed("Fetched user URI");
|
||||
|
||||
this.log(`URI: ${chalk.blueBright(uri)}`);
|
||||
|
||||
this.exit(0);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue