mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(cli): ♻️ Rewrite instance fetch command to refetch instances instead
This commit is contained in:
parent
50ebc12783
commit
8b23eb888d
4 changed files with 88 additions and 50 deletions
|
|
@ -362,6 +362,36 @@ export class Instance extends BaseInterface<typeof Instances> {
|
|||
});
|
||||
}
|
||||
|
||||
public static async updateFromRemote(url: string): 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);
|
||||
|
||||
if (!output) {
|
||||
logger.error`Failed to update instance ${chalk.bold(host)}`;
|
||||
throw new Error("Failed to update instance");
|
||||
}
|
||||
|
||||
const { metadata, protocol } = output;
|
||||
|
||||
await instance.update({
|
||||
name: metadata.name,
|
||||
version: metadata.software.version,
|
||||
logo: metadata.logo,
|
||||
protocol,
|
||||
publicKey: metadata.public_key,
|
||||
});
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static getCount(): Promise<number> {
|
||||
return db.$count(Instances);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue