2024-03-02 16:25:27 +02:00
|
|
|
import BaseCommand from './base-command';
|
|
|
|
import app from './app';
|
|
|
|
import { _ } from '@joplin/lib/locale';
|
|
|
|
import restoreItems from '@joplin/lib/services/trash/restoreItems';
|
|
|
|
|
|
|
|
class Command extends BaseCommand {
|
|
|
|
public override usage() {
|
|
|
|
return 'restore <pattern>';
|
|
|
|
}
|
|
|
|
|
|
|
|
public override description() {
|
2024-03-12 20:20:49 +02:00
|
|
|
return _('Restore the items matching <pattern> from the trash.');
|
2024-03-02 16:25:27 +02:00
|
|
|
}
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2024-03-02 16:25:27 +02:00
|
|
|
public override async action(args: any) {
|
|
|
|
const pattern = args['pattern'];
|
|
|
|
|
|
|
|
const items = await app().loadItems('folderOrNote', pattern);
|
|
|
|
if (!items.length) throw new Error(_('Cannot find "%s".', pattern));
|
|
|
|
|
|
|
|
const ids = items.map(n => n.id);
|
|
|
|
await restoreItems(items[0].type_, ids, { useRestoreFolder: true });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Command;
|