mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(cli): ♻️ Rewrite CLI with Clerk. Removes a bunch of commands now covered by API.
This commit is contained in:
parent
28577d017a
commit
5b756ea2dd
32 changed files with 536 additions and 2721 deletions
37
cli/instance/refetch.ts
Normal file
37
cli/instance/refetch.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import chalk from "chalk";
|
||||
// @ts-expect-error - Root import is required or the Clec type definitions won't work
|
||||
// biome-ignore lint/correctness/noUnusedImports: Root import is required or the Clec type definitions won't work
|
||||
import { type Root, defineCommand } from "clerc";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { Instance } from "~/classes/database/instance.ts";
|
||||
import { FetchJobType, fetchQueue } from "~/classes/queues/fetch.ts";
|
||||
import { Instances } from "~/drizzle/schema.ts";
|
||||
|
||||
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)}.`,
|
||||
);
|
||||
},
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue