2025-06-15 23:50:34 +02:00
|
|
|
import { Instance } from "@versia-server/kit/db";
|
2025-06-29 22:56:52 +02:00
|
|
|
import { FetchJobType, fetchQueue } from "@versia-server/kit/queues/fetch";
|
2025-06-15 23:50:34 +02:00
|
|
|
import { Instances } from "@versia-server/kit/tables";
|
2025-02-26 00:00:21 +01:00
|
|
|
import chalk from "chalk";
|
|
|
|
|
// @ts-expect-error - Root import is required or the Clec type definitions won't work
|
2025-04-10 19:56:42 +02:00
|
|
|
// biome-ignore lint/correctness/noUnusedImports: Root import is required or the Clec type definitions won't work
|
2025-04-10 19:15:31 +02:00
|
|
|
import { defineCommand, type Root } from "clerc";
|
2025-02-26 00:00:21 +01:00
|
|
|
import { eq } from "drizzle-orm";
|
|
|
|
|
|
|
|
|
|
export const refetchInstanceCommand = defineCommand(
|
|
|
|
|
{
|
|
|
|
|
name: "instance refetch",
|
|
|
|
|
description: "Refetches metadata from remote instances.",
|
|
|
|
|
parameters: ["<url_or_host>"],
|
|
|
|
|
},
|
|
|
|
|
async (context) => {
|
|
|
|
|
const { urlOrHost } = context.parameters;
|
|
|
|
|
|
|
|
|
|
const host = URL.canParse(urlOrHost)
|
|
|
|
|
? new URL(urlOrHost).host
|
|
|
|
|
: urlOrHost;
|
|
|
|
|
|
|
|
|
|
const instance = await Instance.fromSql(eq(Instances.baseUrl, host));
|
|
|
|
|
|
|
|
|
|
if (!instance) {
|
|
|
|
|
throw new Error(`Instance ${chalk.gray(host)} not found.`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await fetchQueue.add(FetchJobType.Instance, {
|
|
|
|
|
uri: new URL(`https://${instance.data.baseUrl}`).origin,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.info(
|
|
|
|
|
`Refresh job enqueued for ${chalk.gray(instance.data.baseUrl)}.`,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|