2025-12-10 21:26:02 +01:00
|
|
|
import { defineCommand } from "@clerc/core";
|
2025-06-15 23:50:34 +02:00
|
|
|
import { User } from "@versia-server/kit/db";
|
2025-02-26 00:00:21 +01:00
|
|
|
import chalk from "chalk";
|
|
|
|
|
import ora from "ora";
|
|
|
|
|
import { retrieveUser } from "../utils.ts";
|
|
|
|
|
|
2025-12-18 22:11:54 +01:00
|
|
|
export const refetchUserCommand = defineCommand(
|
|
|
|
|
{
|
|
|
|
|
name: "user refetch",
|
|
|
|
|
description: "Refetches user data from their remote instance.",
|
|
|
|
|
parameters: ["<handle>"],
|
|
|
|
|
},
|
|
|
|
|
async (context) => {
|
2025-02-26 00:00:21 +01:00
|
|
|
const { handle } = context.parameters;
|
|
|
|
|
|
|
|
|
|
const user = await retrieveUser(handle);
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
|
|
|
|
throw new Error(`User ${chalk.gray(handle)} not found.`);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-08 18:13:30 +02:00
|
|
|
if (user.local) {
|
2025-02-26 00:00:21 +01:00
|
|
|
throw new Error(
|
|
|
|
|
"This user is local and as such cannot be refetched.",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const spinner = ora("Refetching user").start();
|
|
|
|
|
|
|
|
|
|
try {
|
2025-04-08 17:27:08 +02:00
|
|
|
await User.fromVersia(user.uri);
|
2025-02-26 00:00:21 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
spinner.fail(
|
|
|
|
|
`Failed to refetch user ${chalk.gray(user.data.username)}`,
|
|
|
|
|
);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spinner.succeed(`User ${chalk.gray(user.data.username)} refetched.`);
|
|
|
|
|
},
|
2025-12-18 22:11:54 +01:00
|
|
|
);
|