1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00

API: Allow accessing revision data

This commit is contained in:
Laurent Cozic 2023-10-06 15:03:32 +01:00
parent 634fa8a61f
commit e49ca26a36
8 changed files with 60 additions and 7 deletions

View File

@ -803,6 +803,7 @@ packages/lib/services/rest/routes/master_keys.js
packages/lib/services/rest/routes/notes.js packages/lib/services/rest/routes/notes.js
packages/lib/services/rest/routes/ping.js packages/lib/services/rest/routes/ping.js
packages/lib/services/rest/routes/resources.js packages/lib/services/rest/routes/resources.js
packages/lib/services/rest/routes/revisions.js
packages/lib/services/rest/routes/search.js packages/lib/services/rest/routes/search.js
packages/lib/services/rest/routes/tags.js packages/lib/services/rest/routes/tags.js
packages/lib/services/rest/utils/collectionToPaginatedResults.js packages/lib/services/rest/utils/collectionToPaginatedResults.js

1
.gitignore vendored
View File

@ -789,6 +789,7 @@ packages/lib/services/rest/routes/master_keys.js
packages/lib/services/rest/routes/notes.js packages/lib/services/rest/routes/notes.js
packages/lib/services/rest/routes/ping.js packages/lib/services/rest/routes/ping.js
packages/lib/services/rest/routes/resources.js packages/lib/services/rest/routes/resources.js
packages/lib/services/rest/routes/revisions.js
packages/lib/services/rest/routes/search.js packages/lib/services/rest/routes/search.js
packages/lib/services/rest/routes/tags.js packages/lib/services/rest/routes/tags.js
packages/lib/services/rest/utils/collectionToPaginatedResults.js packages/lib/services/rest/utils/collectionToPaginatedResults.js

View File

@ -50,6 +50,9 @@ class Command extends BaseCommand {
{ {
type: BaseModel.TYPE_TAG, type: BaseModel.TYPE_TAG,
}, },
{
type: BaseModel.TYPE_REVISION,
},
]; ];
const lines = []; const lines = [];
@ -411,7 +414,7 @@ async function fetchAllNotes() {
lines.push(''); lines.push('');
lines.push('If no `cursor` property is provided, the API will respond with the latest change ID. That can be used to retrieve future events later on.'); lines.push('If no `cursor` property is provided, the API will respond with the latest change ID. That can be used to retrieve future events later on.');
lines.push(''); lines.push('');
lines.push('The results are paginated so will need to may multiple calls to retrieve all the events. Use the `has_more` property to know if more can be retrieved.'); lines.push('The results are paginated so you may need multiple calls to retrieve all the events. Use the `has_more` property to know if more can be retrieved.');
lines.push(''); lines.push('');
lines.push('## GET /events/:id'); lines.push('## GET /events/:id');
lines.push(''); lines.push('');

View File

@ -10,6 +10,7 @@ import route_search from './routes/search';
import route_ping from './routes/ping'; import route_ping from './routes/ping';
import route_auth from './routes/auth'; import route_auth from './routes/auth';
import route_events from './routes/events'; import route_events from './routes/events';
import route_revisions from './routes/revisions';
const { ltrimSlashes } = require('../../path-utils'); const { ltrimSlashes } = require('../../path-utils');
const md5 = require('md5'); const md5 = require('md5');
@ -113,6 +114,7 @@ export default class Api {
services: this.action_services.bind(this), services: this.action_services.bind(this),
auth: route_auth, auth: route_auth,
events: route_events, events: route_events,
revisions: route_revisions,
}; };
this.dispatch = this.dispatch.bind(this); this.dispatch = this.dispatch.bind(this);

View File

@ -0,0 +1,7 @@
import defaultAction from '../utils/defaultAction';
import { ModelType } from '../../../BaseModel';
import { Request } from '../Api';
export default async function(request: Request, id: string = null, link: string = null) {
return defaultAction(ModelType.Revision, request, id, link, ['id']);
}

View File

@ -6,7 +6,7 @@ import readonlyProperties from './readonlyProperties';
import requestFields from './requestFields'; import requestFields from './requestFields';
import BaseItem from '../../../models/BaseItem'; import BaseItem from '../../../models/BaseItem';
export default async function(modelType: number, request: Request, id: string = null, link: string = null) { export default async function(modelType: number, request: Request, id: string = null, link: string = null, defaultFields: string[] = null) {
if (link) throw new ErrorNotFound(); // Default action doesn't support links at all for now if (link) throw new ErrorNotFound(); // Default action doesn't support links at all for now
const ModelClass = BaseItem.getClassByItemType(modelType); const ModelClass = BaseItem.getClassByItemType(modelType);
@ -20,10 +20,10 @@ export default async function(modelType: number, request: Request, id: string =
if (request.method === 'GET') { if (request.method === 'GET') {
if (id) { if (id) {
return getOneModel({ return getOneModel({
fields: requestFields(request, modelType), fields: requestFields(request, modelType, defaultFields),
}); });
} else { } else {
return paginatedResults(modelType, request); return paginatedResults(modelType, request, null, defaultFields);
} }
} }

View File

@ -5,9 +5,9 @@ import requestPaginationOptions from './requestPaginationOptions';
import paginatedFeed, { WhereQuery, ModelFeedPage } from '../../../models/utils/paginatedFeed'; import paginatedFeed, { WhereQuery, ModelFeedPage } from '../../../models/utils/paginatedFeed';
import BaseItem from '../../../models/BaseItem'; import BaseItem from '../../../models/BaseItem';
export default async function(modelType: number, request: Request, whereQuery: WhereQuery = null): Promise<ModelFeedPage> { export default async function(modelType: number, request: Request, whereQuery: WhereQuery = null, defaultFields: string[] = null): Promise<ModelFeedPage> {
const ModelClass = BaseItem.getClassByItemType(modelType); const ModelClass = BaseItem.getClassByItemType(modelType);
const fields = requestFields(request, modelType); const fields = requestFields(request, modelType, defaultFields);
const pagination = requestPaginationOptions(request); const pagination = requestPaginationOptions(request);
return paginatedFeed(BaseModel.db(), ModelClass.tableName(), pagination, whereQuery, fields); return paginatedFeed(BaseModel.db(), ModelClass.tableName(), pagination, whereQuery, fields);
} }

View File

@ -418,6 +418,45 @@ Deletes the tag with ID :id
Remove the tag from the note. Remove the tag from the note.
# Revisions
## Properties
| Name | Type | Description |
| ----- | ----- | ----- |
| id | text | |
| parent_id | text | |
| item_type | int | |
| item_id | text | |
| item_updated_time | int | |
| title_diff | text | |
| body_diff | text | |
| metadata_diff | text | |
| encryption_cipher_text | text | |
| encryption_applied | int | |
| updated_time | int | |
| created_time | int | |
## GET /revisions
Gets all revisions
## GET /revisions/:id
Gets revision with ID :id
## POST /revisions
Creates a new revision
## PUT /revisions/:id
Sets the properties of the revision with ID :id
## DELETE /revisions/:id
Deletes the revision with ID :id
# Events # Events
This end point can be used to retrieve the latest note changes. Currently only note changes are tracked. This end point can be used to retrieve the latest note changes. Currently only note changes are tracked.
@ -440,7 +479,7 @@ Returns a paginated list of recent events. A `cursor` property should be provide
If no `cursor` property is provided, the API will respond with the latest change ID. That can be used to retrieve future events later on. If no `cursor` property is provided, the API will respond with the latest change ID. That can be used to retrieve future events later on.
The results are paginated so will need to may multiple calls to retrieve all the events. Use the `has_more` property to know if more can be retrieved. The results are paginated so you may need multiple calls to retrieve all the events. Use the `has_more` property to know if more can be retrieved.
## GET /events/:id ## GET /events/:id