2022-11-01 17:28:14 +02:00
|
|
|
const BaseCommand = require('./base-command').default;
|
2017-11-03 02:09:34 +02:00
|
|
|
const { app } = require('./app.js');
|
2020-11-07 17:59:37 +02:00
|
|
|
const { _ } = require('@joplin/lib/locale');
|
|
|
|
const BaseModel = require('@joplin/lib/BaseModel').default;
|
|
|
|
const shim = require('@joplin/lib/shim').default;
|
2017-10-20 00:02:13 +02:00
|
|
|
|
|
|
|
class Command extends BaseCommand {
|
|
|
|
usage() {
|
|
|
|
return 'attach <note> <file>';
|
|
|
|
}
|
|
|
|
|
|
|
|
description() {
|
|
|
|
return _('Attaches the given file to the note.');
|
|
|
|
}
|
|
|
|
|
|
|
|
async action(args) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const title = args['note'];
|
2017-10-20 00:02:13 +02:00
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const note = await app().loadItem(BaseModel.TYPE_NOTE, title, { parent: app().currentFolder() });
|
2017-12-26 12:38:53 +02:00
|
|
|
this.encryptionCheck(note);
|
2017-10-20 00:02:13 +02:00
|
|
|
if (!note) throw new Error(_('Cannot find "%s".', title));
|
|
|
|
|
|
|
|
const localFilePath = args['file'];
|
|
|
|
|
2017-11-11 00:18:00 +02:00
|
|
|
await shim.attachFileToNote(note, localFilePath);
|
2017-10-20 00:02:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
module.exports = Command;
|