1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Desktop: API: Fixed externalEditWatcher/noteIsWatched call, fixed tests

This commit is contained in:
Laurent Cozic 2020-06-20 12:03:22 +01:00
parent 6350506ce7
commit 89ca8e08d6
6 changed files with 22 additions and 12 deletions

View File

@ -114,6 +114,7 @@ ReactNativeClient/lib/services/keychain/KeychainServiceDriver.mobile.js
ReactNativeClient/lib/services/keychain/KeychainServiceDriver.node.js
ReactNativeClient/lib/services/keychain/KeychainServiceDriverBase.js
ReactNativeClient/lib/services/ResourceEditWatcher.js
ReactNativeClient/lib/services/rest/actionApi.desktop.js
ReactNativeClient/lib/services/SettingUtils.js
ReactNativeClient/lib/services/UndoRedoService.js
ReactNativeClient/lib/ShareExtension.js

1
.gitignore vendored
View File

@ -104,6 +104,7 @@ ReactNativeClient/lib/services/keychain/KeychainServiceDriver.mobile.js
ReactNativeClient/lib/services/keychain/KeychainServiceDriver.node.js
ReactNativeClient/lib/services/keychain/KeychainServiceDriverBase.js
ReactNativeClient/lib/services/ResourceEditWatcher.js
ReactNativeClient/lib/services/rest/actionApi.desktop.js
ReactNativeClient/lib/services/SettingUtils.js
ReactNativeClient/lib/services/UndoRedoService.js
ReactNativeClient/lib/ShareExtension.js

View File

@ -4,6 +4,7 @@ const { Logger } = require('lib/logger.js');
const { randomClipperPort, startPort } = require('lib/randomClipperPort');
const enableServerDestroy = require('server-destroy');
const Api = require('lib/services/rest/Api');
const actionApi = require('lib/services/rest/ActionApi.desktop').default;
const ApiResponse = require('lib/services/rest/ApiResponse');
const multiparty = require('multiparty');
@ -15,7 +16,7 @@ class ClipperServer {
this.port_ = null;
this.api_ = new Api(() => {
return Setting.value('api.token');
});
}, actionApi);
}
static instance() {
@ -143,6 +144,8 @@ class ClipperServer {
writeResponseInstance(code, response);
} else if (typeof response === 'string') {
writeResponseText(code, response);
} else if (response === null || response === undefined) {
writeResponseText(code, '');
} else {
writeResponseJson(code, response);
}
@ -155,7 +158,7 @@ class ClipperServer {
const execRequest = async (request, body = '', files = []) => {
try {
const response = await this.api_.route(request.method, url.pathname, url.query, body, files);
writeResponse(200, response ? response : '');
writeResponse(200, response);
} catch (error) {
this.logger().error(error);
const httpCode = error.httpCode ? error.httpCode : 500;

View File

@ -36,7 +36,8 @@ class ExternalEditWatcher {
return this.stopWatching(noteId);
},
noteIsWatched: async ({ noteId }) => {
return this.noteIsWatched(noteId);
const note = await Note.load(noteId);
return this.noteIsWatched(note);
},
};
}

View File

@ -25,8 +25,6 @@ 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);
@ -60,10 +58,11 @@ class ErrorBadRequest extends ApiError {
}
class Api {
constructor(token = null) {
constructor(token = null, actionApi = null) {
this.token_ = token;
this.knownNounces_ = {};
this.logger_ = new Logger();
this.actionApi_ = actionApi;
}
get token() {
@ -391,13 +390,11 @@ class Api {
this.checkToken_(request);
if (request.method !== 'POST') throw new ErrorMethodNotAllowed();
if (!this.actionApi_) throw new ErrorNotFound('No action API has been setup!');
if (!this.actionApi_[serviceName]) throw new ErrorNotFound(`No such service: ${serviceName}`);
if (serviceName === 'externalEditWatcher') {
const externalApi = ExternalEditWatcher.instance().externalApi();
const externalApi = this.actionApi_[serviceName]();
return this.execServiceActionFromRequest_(externalApi, JSON.parse(request.body));
} else {
throw new ErrorNotFound(`No such service: ${serviceName}`);
}
}
async action_notes(request, id = null, link = null) {

View File

@ -0,0 +1,7 @@
const ExternalEditWatcher = require('lib/services/ExternalEditWatcher');
export default {
externalEditWatcher: () => ExternalEditWatcher.instance().externalApi(),
};