mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
refactor: ♻️ Store instance federation protocol in database, refactor fetcher
This commit is contained in:
parent
6dc51ab323
commit
f2b0de779b
10 changed files with 2515 additions and 73 deletions
48
cli/commands/federation/instance/fetch.ts
Normal file
48
cli/commands/federation/instance/fetch.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { Args } from "@oclif/core";
|
||||
import ora from "ora";
|
||||
import { BaseCommand } from "~/cli/base";
|
||||
import { formatArray } from "~/cli/utils/format";
|
||||
import { Instance } from "~/packages/database-interface/instance";
|
||||
|
||||
export default class FederationInstanceFetch extends BaseCommand<
|
||||
typeof FederationInstanceFetch
|
||||
> {
|
||||
static override args = {
|
||||
url: Args.string({
|
||||
description: "URL of the remote instance",
|
||||
required: true,
|
||||
}),
|
||||
};
|
||||
|
||||
static override description = "Fetch metadata from remote instances";
|
||||
|
||||
static override examples = ["<%= config.bin %> <%= command.id %>"];
|
||||
|
||||
static override flags = {};
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const { args } = await this.parse(FederationInstanceFetch);
|
||||
|
||||
const spinner = ora("Fetching instance metadata").start();
|
||||
|
||||
const data = await Instance.fetchMetadata(args.url);
|
||||
|
||||
if (!data) {
|
||||
spinner.fail("Failed to fetch instance metadata");
|
||||
this.exit(1);
|
||||
}
|
||||
|
||||
spinner.succeed("Fetched instance metadata");
|
||||
|
||||
const { metadata, protocol } = data;
|
||||
|
||||
this.log(
|
||||
formatArray(
|
||||
[{ ...metadata, protocol }],
|
||||
["name", "description", "version", "protocol"],
|
||||
),
|
||||
);
|
||||
|
||||
this.exit(0);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue