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