You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-24 23:26:50 +02:00
All: Use Lerna to manage monorepo
This commit is contained in:
54
packages/app-cli/app/command-set.js
Normal file
54
packages/app-cli/app/command-set.js
Normal file
@ -0,0 +1,54 @@
|
||||
const { BaseCommand } = require('./base-command.js');
|
||||
const { app } = require('./app.js');
|
||||
const { _ } = require('@joplinapp/lib/locale');
|
||||
const BaseModel = require('@joplinapp/lib/BaseModel').default;
|
||||
const { Database } = require('@joplinapp/lib/database.js');
|
||||
const Note = require('@joplinapp/lib/models/Note.js');
|
||||
|
||||
class Command extends BaseCommand {
|
||||
usage() {
|
||||
return 'set <note> <name> [value]';
|
||||
}
|
||||
|
||||
description() {
|
||||
const fields = Note.fields();
|
||||
const s = [];
|
||||
for (let i = 0; i < fields.length; i++) {
|
||||
const f = fields[i];
|
||||
if (f.name === 'id') continue;
|
||||
s.push(`${f.name} (${Database.enumName('fieldType', f.type)})`);
|
||||
}
|
||||
|
||||
return _('Sets the property <name> of the given <note> to the given [value]. Possible properties are:\n\n%s', s.join(', '));
|
||||
}
|
||||
|
||||
async action(args) {
|
||||
const title = args['note'];
|
||||
const propName = args['name'];
|
||||
let propValue = args['value'];
|
||||
if (!propValue) propValue = '';
|
||||
|
||||
const notes = await app().loadItems(BaseModel.TYPE_NOTE, title);
|
||||
if (!notes.length) throw new Error(_('Cannot find "%s".', title));
|
||||
|
||||
for (let i = 0; i < notes.length; i++) {
|
||||
this.encryptionCheck(notes[i]);
|
||||
|
||||
const newNote = {
|
||||
id: notes[i].id,
|
||||
type_: notes[i].type_,
|
||||
};
|
||||
newNote[propName] = propValue;
|
||||
|
||||
const timestamp = Date.now();
|
||||
|
||||
await Note.save(newNote, {
|
||||
autoTimestamp: false, // No auto-timestamp because user may have provided them
|
||||
updated_time: timestamp,
|
||||
created_time: timestamp,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Command;
|
Reference in New Issue
Block a user