mirror of
https://github.com/versia-pub/server.git
synced 2025-12-07 16:58:20 +01:00
refactor(federation): ♻️ Make Instance updateFromRemote non-static
This commit is contained in:
parent
8b23eb888d
commit
34370a082a
|
|
@ -362,26 +362,21 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
});
|
||||
}
|
||||
|
||||
public static async updateFromRemote(url: string): Promise<Instance> {
|
||||
public async updateFromRemote(): Promise<Instance> {
|
||||
const logger = getLogger("federation");
|
||||
const host = new URL(url).host;
|
||||
|
||||
const instance = await Instance.fromSql(eq(Instances.baseUrl, host));
|
||||
|
||||
if (!instance) {
|
||||
throw new Error("Instance not found");
|
||||
}
|
||||
|
||||
const output = await Instance.fetchMetadata(url);
|
||||
const output = await Instance.fetchMetadata(
|
||||
`https://${this.data.baseUrl}`,
|
||||
);
|
||||
|
||||
if (!output) {
|
||||
logger.error`Failed to update instance ${chalk.bold(host)}`;
|
||||
logger.error`Failed to update instance ${chalk.bold(this.data.baseUrl)}`;
|
||||
throw new Error("Failed to update instance");
|
||||
}
|
||||
|
||||
const { metadata, protocol } = output;
|
||||
|
||||
await instance.update({
|
||||
await this.update({
|
||||
name: metadata.name,
|
||||
version: metadata.software.version,
|
||||
logo: metadata.logo,
|
||||
|
|
@ -389,7 +384,7 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
publicKey: metadata.public_key,
|
||||
});
|
||||
|
||||
return instance;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static getCount(): Promise<number> {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import { Args } from "@oclif/core";
|
||||
import { Instance } from "@versia/kit/db";
|
||||
import { Instances } from "@versia/kit/tables";
|
||||
import { eq } from "drizzle-orm";
|
||||
import ora from "ora";
|
||||
import { BaseCommand } from "~/cli/base";
|
||||
import { formatArray } from "~/cli/utils/format";
|
||||
|
|
@ -26,7 +28,15 @@ export default class FederationInstanceRefetch extends BaseCommand<
|
|||
|
||||
const spinner = ora("Refetching instance metadata").start();
|
||||
|
||||
const data = await Instance.updateFromRemote(args.url);
|
||||
const host = new URL(args.url).host;
|
||||
|
||||
const instance = await Instance.fromSql(eq(Instances.baseUrl, host));
|
||||
|
||||
if (!instance) {
|
||||
throw new Error("Instance not found");
|
||||
}
|
||||
|
||||
const data = await instance.updateFromRemote();
|
||||
|
||||
if (!data) {
|
||||
spinner.fail("Failed to refetch instance metadata");
|
||||
|
|
|
|||
Loading…
Reference in a new issue