mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-24 08:12:24 +02:00
Desktop: API: Add support for external editing from API
This commit is contained in:
parent
e38794171a
commit
45160a2e73
@ -26,6 +26,21 @@ class ExternalEditWatcher {
|
||||
return this.instance_;
|
||||
}
|
||||
|
||||
externalApi() {
|
||||
return {
|
||||
openAndWatch: async ({ noteId }) => {
|
||||
const note = await Note.load(noteId);
|
||||
return this.openAndWatch(note);
|
||||
},
|
||||
stopWatching: async ({ noteId }) => {
|
||||
return this.stopWatching(noteId);
|
||||
},
|
||||
noteIsWatched: async ({ noteId }) => {
|
||||
return this.noteIsWatched(noteId);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
tempDir() {
|
||||
return Setting.value('profileDir');
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ const uri2path = require('file-uri-to-path');
|
||||
const { MarkupToHtml } = require('lib/joplin-renderer');
|
||||
const { uuid } = require('lib/uuid');
|
||||
|
||||
const ExternalEditWatcher = require('lib/services/ExternalEditWatcher');
|
||||
|
||||
class ApiError extends Error {
|
||||
constructor(message, httpCode = 400) {
|
||||
super(message);
|
||||
@ -377,6 +379,27 @@ class Api {
|
||||
return options;
|
||||
}
|
||||
|
||||
async execServiceActionFromRequest_(externalApi, request) {
|
||||
const action = externalApi[request.action];
|
||||
if (!action) throw new ErrorNotFound(`Invalid action: ${request.action}`);
|
||||
const args = Object.assign({}, request);
|
||||
delete args.action;
|
||||
return action(args);
|
||||
}
|
||||
|
||||
async action_services(request, serviceName) {
|
||||
this.checkToken_(request);
|
||||
|
||||
if (request.method !== 'POST') throw new ErrorMethodNotAllowed();
|
||||
|
||||
if (serviceName === 'externalEditWatcher') {
|
||||
const externalApi = ExternalEditWatcher.instance().externalApi();
|
||||
return this.execServiceActionFromRequest_(externalApi, JSON.parse(request.body));
|
||||
} else {
|
||||
throw new ErrorNotFound(`No such service: ${serviceName}`);
|
||||
}
|
||||
}
|
||||
|
||||
async action_notes(request, id = null, link = null) {
|
||||
this.checkToken_(request);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user