mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	attachment ETAPI support WIP
This commit is contained in:
		
							parent
							
								
									3b3f6082a7
								
							
						
					
					
						commit
						57702a07a2
					
				@ -2,8 +2,7 @@ const becca = require("../becca/becca");
 | 
				
			|||||||
const eu = require("./etapi_utils");
 | 
					const eu = require("./etapi_utils");
 | 
				
			||||||
const mappers = require("./mappers");
 | 
					const mappers = require("./mappers");
 | 
				
			||||||
const v = require("./validators");
 | 
					const v = require("./validators");
 | 
				
			||||||
const utils = require("../services/utils.js");
 | 
					const utils = require("../services/utils");
 | 
				
			||||||
const noteService = require("../services/notes.js");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
function register(router) {
 | 
					function register(router) {
 | 
				
			||||||
    const ALLOWED_PROPERTIES_FOR_CREATE_ATTACHMENT = {
 | 
					    const ALLOWED_PROPERTIES_FOR_CREATE_ATTACHMENT = {
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,6 @@ function register(router) {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const ALLOWED_PROPERTIES_FOR_CREATE_BRANCH = {
 | 
					    const ALLOWED_PROPERTIES_FOR_CREATE_BRANCH = {
 | 
				
			||||||
        'branchId': [v.mandatory, v.notNull, v.isValidEntityId],
 | 
					 | 
				
			||||||
        'noteId': [v.mandatory, v.notNull, v.isNoteId],
 | 
					        'noteId': [v.mandatory, v.notNull, v.isNoteId],
 | 
				
			||||||
        'parentNoteId': [v.mandatory, v.notNull, v.isNoteId],
 | 
					        'parentNoteId': [v.mandatory, v.notNull, v.isNoteId],
 | 
				
			||||||
        'notePosition': [v.notNull, v.isInteger],
 | 
					        'notePosition': [v.notNull, v.isInteger],
 | 
				
			||||||
 | 
				
			|||||||
@ -49,8 +49,7 @@ function register(router) {
 | 
				
			|||||||
        'notePosition': [v.notNull, v.isInteger],
 | 
					        'notePosition': [v.notNull, v.isInteger],
 | 
				
			||||||
        'prefix': [v.notNull, v.isString],
 | 
					        'prefix': [v.notNull, v.isString],
 | 
				
			||||||
        'isExpanded': [v.notNull, v.isBoolean],
 | 
					        'isExpanded': [v.notNull, v.isBoolean],
 | 
				
			||||||
        'noteId': [v.notNull, v.isValidEntityId],
 | 
					        'noteId': [v.notNull, v.isValidEntityId]
 | 
				
			||||||
        'branchId': [v.notNull, v.isValidEntityId],
 | 
					 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eu.route(router, 'post' ,'/etapi/create-note', (req, res, next) => {
 | 
					    eu.route(router, 'post' ,'/etapi/create-note', (req, res, next) => {
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,6 @@ Content-Type: application/json
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  "noteId": "forcedId{{$randomInt}}",
 | 
					  "noteId": "forcedId{{$randomInt}}",
 | 
				
			||||||
  "branchId": "forcedId{{$randomInt}}",
 | 
					 | 
				
			||||||
  "parentNoteId": "root",
 | 
					  "parentNoteId": "root",
 | 
				
			||||||
  "title": "Hello",
 | 
					  "title": "Hello",
 | 
				
			||||||
  "type": "text",
 | 
					  "type": "text",
 | 
				
			||||||
@ -15,7 +14,6 @@ Content-Type: application/json
 | 
				
			|||||||
    client.assert(response.status === 201);
 | 
					    client.assert(response.status === 201);
 | 
				
			||||||
    client.assert(response.body.note.noteId.startsWith("forcedId"));
 | 
					    client.assert(response.body.note.noteId.startsWith("forcedId"));
 | 
				
			||||||
    client.assert(response.body.note.title == "Hello");
 | 
					    client.assert(response.body.note.title == "Hello");
 | 
				
			||||||
    client.assert(response.body.branch.branchId.startsWith("forcedId"));
 | 
					 | 
				
			||||||
    client.assert(response.body.branch.parentNoteId == "root");
 | 
					    client.assert(response.body.branch.parentNoteId == "root");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    client.log(`Created note ` + response.body.note.noteId + ` and branch ` + response.body.branch.branchId);
 | 
					    client.log(`Created note ` + response.body.note.noteId + ` and branch ` + response.body.branch.branchId);
 | 
				
			||||||
@ -31,14 +29,13 @@ Authorization: {{authToken}}
 | 
				
			|||||||
Content-Type: application/json
 | 
					Content-Type: application/json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  "branchId": "forcedClonedId",
 | 
					 | 
				
			||||||
  "noteId": "{{createdNoteId}}",
 | 
					  "noteId": "{{createdNoteId}}",
 | 
				
			||||||
  "parentNoteId": '_hidden'
 | 
					  "parentNoteId": "_hidden"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
> {%
 | 
					> {%
 | 
				
			||||||
    client.assert(response.status === 201);
 | 
					    client.assert(response.status === 201);
 | 
				
			||||||
    client.assert(response.body.parentNoteId == '_hidden');
 | 
					    client.assert(response.body.parentNoteId == "_hidden");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    client.global.set("clonedBranchId", response.body.branchId);
 | 
					    client.global.set("clonedBranchId", response.body.branchId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -122,3 +119,36 @@ Authorization: {{authToken}}
 | 
				
			|||||||
    client.assert(response.status === 200);
 | 
					    client.assert(response.status === 200);
 | 
				
			||||||
    client.assert(response.body.attributeId == client.global.get("createdAttributeId"));
 | 
					    client.assert(response.body.attributeId == client.global.get("createdAttributeId"));
 | 
				
			||||||
%}
 | 
					%}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					###
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					POST {{triliumHost}}/etapi/attachments
 | 
				
			||||||
 | 
					Content-Type: application/json
 | 
				
			||||||
 | 
					Authorization: {{authToken}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  "parentId": "{{createdNoteId}}",
 | 
				
			||||||
 | 
					  "role": "file",
 | 
				
			||||||
 | 
					  "mime": "plain/text",
 | 
				
			||||||
 | 
					  "title": "my attachment",
 | 
				
			||||||
 | 
					  "content": "my text"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> {%
 | 
				
			||||||
 | 
					    client.assert(response.status === 201);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    client.global.set("createdAttachmentId", response.body.attachmentId);
 | 
				
			||||||
 | 
					%}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					###
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					GET {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}
 | 
				
			||||||
 | 
					Authorization: {{authToken}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					> {%
 | 
				
			||||||
 | 
					    client.assert(response.status === 200);
 | 
				
			||||||
 | 
					    client.assert(response.body.attachmentId == client.global.get("createdAttachmentId"));
 | 
				
			||||||
 | 
					    client.assert(response.body.role == "file");
 | 
				
			||||||
 | 
					    client.assert(response.body.mime == "plain/text");
 | 
				
			||||||
 | 
					    client.assert(response.body.title == "my attachment");
 | 
				
			||||||
 | 
					%}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user