You've already forked joplin
							
							
				mirror of
				https://github.com/laurent22/joplin.git
				synced 2025-10-31 00:07:48 +02:00 
			
		
		
		
	Api: Resolves #1956: Allow getting the resources of a note
This commit is contained in:
		| @@ -150,8 +150,8 @@ class BaseModel { | ||||
| 			}); | ||||
| 	} | ||||
|  | ||||
| 	static load(id) { | ||||
| 		return this.loadByField('id', id); | ||||
| 	static load(id, options = null) { | ||||
| 		return this.loadByField('id', id, options); | ||||
| 	} | ||||
|  | ||||
| 	static shortId(id) { | ||||
| @@ -250,7 +250,8 @@ class BaseModel { | ||||
| 	static loadByField(fieldName, fieldValue, options = null) { | ||||
| 		if (!options) options = {}; | ||||
| 		if (!('caseInsensitive' in options)) options.caseInsensitive = false; | ||||
| 		let sql = `SELECT * FROM \`${this.tableName()}\` WHERE \`${fieldName}\` = ?`; | ||||
| 		if (!options.fields) options.fields = '*'; | ||||
| 		let sql = `SELECT ${this.db().escapeFields(options.fields)} FROM \`${this.tableName()}\` WHERE \`${fieldName}\` = ?`; | ||||
| 		if (options.caseInsensitive) sql += ' COLLATE NOCASE'; | ||||
| 		return this.modelSelectOne(sql, [fieldValue]); | ||||
| 	} | ||||
|   | ||||
| @@ -354,12 +354,28 @@ class Api { | ||||
| 		return options; | ||||
| 	} | ||||
|  | ||||
| 	defaultLoadOptions_(request) { | ||||
| 		const options = {}; | ||||
| 		const fields = this.fields_(request, []); | ||||
| 		if (fields.length) options.fields = fields; | ||||
| 		return options; | ||||
| 	} | ||||
|  | ||||
| 	async action_notes(request, id = null, link = null) { | ||||
| 		this.checkToken_(request); | ||||
|  | ||||
| 		if (request.method === 'GET') { | ||||
| 			if (link && link === 'tags') { | ||||
| 				return Tag.tagsByNoteId(id); | ||||
| 			} else if (link && link === 'resources') { | ||||
| 				const note = await Note.load(id); | ||||
| 				const resourceIds = await Note.linkedResourceIds(note.body); | ||||
| 				const output = []; | ||||
| 				const loadOptions = this.defaultLoadOptions_(request); | ||||
| 				for (let resourceId of resourceIds) { | ||||
| 					output.push(await Resource.load(resourceId, loadOptions)); | ||||
| 				} | ||||
| 				return output; | ||||
| 			} else if (link) { | ||||
| 				throw new ErrorNotFound(); | ||||
| 			} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user