mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
feat(federation): ✨ Add user refetching, support for Undo in federation
This commit is contained in:
parent
908fdcaa79
commit
f8196f72f9
4 changed files with 251 additions and 37 deletions
98
cli/commands/user/refetch.ts
Normal file
98
cli/commands/user/refetch.ts
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
import confirm from "@inquirer/confirm";
|
||||
import { Flags } from "@oclif/core";
|
||||
import chalk from "chalk";
|
||||
import { UserFinderCommand } from "~/cli/classes";
|
||||
import { formatArray } from "~/cli/utils/format";
|
||||
|
||||
export default class UserRefetch extends UserFinderCommand<typeof UserRefetch> {
|
||||
static override description = "Refetch remote users";
|
||||
|
||||
static override examples = [
|
||||
"<%= config.bin %> <%= command.id %> johngastron --type username",
|
||||
"<%= config.bin %> <%= command.id %> 018ec11c-c6cb-7a67-bd20-a4c81bf42912",
|
||||
];
|
||||
|
||||
static override flags = {
|
||||
confirm: Flags.boolean({
|
||||
description:
|
||||
"Ask for confirmation before refetching the user (default yes)",
|
||||
allowNo: true,
|
||||
default: true,
|
||||
}),
|
||||
limit: Flags.integer({
|
||||
char: "n",
|
||||
description: "Limit the number of users",
|
||||
default: 1,
|
||||
}),
|
||||
};
|
||||
|
||||
static override args = {
|
||||
identifier: UserFinderCommand.baseArgs.identifier,
|
||||
};
|
||||
|
||||
public async run(): Promise<void> {
|
||||
const { flags } = await this.parse(UserRefetch);
|
||||
|
||||
const users = await this.findUsers();
|
||||
|
||||
if (!users || users.length === 0) {
|
||||
this.log(chalk.bold(`${chalk.red("✗")} No users found`));
|
||||
this.exit(1);
|
||||
}
|
||||
|
||||
// Display user
|
||||
flags.print &&
|
||||
this.log(
|
||||
chalk.bold(
|
||||
`${chalk.green("✓")} Found ${chalk.green(
|
||||
users.length,
|
||||
)} user(s)`,
|
||||
),
|
||||
);
|
||||
|
||||
flags.print &&
|
||||
this.log(
|
||||
formatArray(
|
||||
users.map((u) => u.getUser()),
|
||||
[
|
||||
"id",
|
||||
"username",
|
||||
"displayName",
|
||||
"createdAt",
|
||||
"updatedAt",
|
||||
"isAdmin",
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (flags.confirm && !flags.print) {
|
||||
const choice = await confirm({
|
||||
message: `Refetch these users? ${chalk.red(
|
||||
"This is irreversible.",
|
||||
)}`,
|
||||
});
|
||||
|
||||
if (!choice) {
|
||||
this.log(chalk.bold(`${chalk.red("✗")} Aborted operation`));
|
||||
return this.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
for (const user of users) {
|
||||
try {
|
||||
await user.updateFromRemote();
|
||||
} catch (error) {
|
||||
this.log(
|
||||
chalk.bold(
|
||||
`${chalk.red("✗")} Failed to refetch user ${
|
||||
user.getUser().username
|
||||
}`,
|
||||
),
|
||||
);
|
||||
this.log(chalk.red((error as Error).message));
|
||||
}
|
||||
}
|
||||
|
||||
this.exit(0);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import Start from "./commands/start";
|
|||
import UserCreate from "./commands/user/create";
|
||||
import UserDelete from "./commands/user/delete";
|
||||
import UserList from "./commands/user/list";
|
||||
import UserRefetch from "./commands/user/refetch";
|
||||
import UserReset from "./commands/user/reset";
|
||||
|
||||
// Use "explicit" oclif strategy to avoid issues with oclif's module resolver and bundling
|
||||
|
|
@ -15,6 +16,7 @@ export const commands = {
|
|||
"user:delete": UserDelete,
|
||||
"user:create": UserCreate,
|
||||
"user:reset": UserReset,
|
||||
"user:refetch": UserRefetch,
|
||||
"emoji:add": EmojiAdd,
|
||||
"emoji:delete": EmojiDelete,
|
||||
"emoji:list": EmojiList,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue