mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Update:API endpoint for get all users to use minimal payload
This commit is contained in:
		
							parent
							
								
									d2e0844493
								
							
						
					
					
						commit
						575a162f8b
					
				| @ -11,9 +11,9 @@ class UserController { | ||||
|   findAll(req, res) { | ||||
|     if (!req.user.isAdminOrUp) return res.sendStatus(403) | ||||
|     const hideRootToken = !req.user.isRoot | ||||
|     const users = this.db.users.map(u => this.userJsonWithItemProgressDetails(u, hideRootToken)) | ||||
|     res.json({ | ||||
|       users: users | ||||
|       // Minimal toJSONForBrowser does not include mediaProgress and bookmarks
 | ||||
|       users: this.db.users.map(u => u.toJSONForBrowser(hideRootToken, true)) | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -101,12 +101,12 @@ class User { | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   toJSONForBrowser() { | ||||
|     return { | ||||
|   toJSONForBrowser(hideRootToken = false, minimal = false) { | ||||
|     const json = { | ||||
|       id: this.id, | ||||
|       username: this.username, | ||||
|       type: this.type, | ||||
|       token: this.token, | ||||
|       token: (this.type === 'root' && hideRootToken) ? '' : this.token, | ||||
|       mediaProgress: this.mediaProgress ? this.mediaProgress.map(li => li.toJSON()) : [], | ||||
|       seriesHideFromContinueListening: [...this.seriesHideFromContinueListening], | ||||
|       bookmarks: this.bookmarks ? this.bookmarks.map(b => b.toJSON()) : [], | ||||
| @ -119,6 +119,11 @@ class User { | ||||
|       librariesAccessible: [...this.librariesAccessible], | ||||
|       itemTagsAccessible: [...this.itemTagsAccessible] | ||||
|     } | ||||
|     if (minimal) { | ||||
|       delete json.mediaProgress | ||||
|       delete json.bookmarks | ||||
|     } | ||||
|     return json | ||||
|   } | ||||
| 
 | ||||
|   // Data broadcasted
 | ||||
|  | ||||
| @ -339,10 +339,7 @@ class ApiRouter { | ||||
|   // Helper Methods
 | ||||
|   //
 | ||||
|   userJsonWithItemProgressDetails(user, hideRootToken = false) { | ||||
|     const json = user.toJSONForBrowser() | ||||
|     if (json.type === 'root' && hideRootToken) { | ||||
|       json.token = '' | ||||
|     } | ||||
|     const json = user.toJSONForBrowser(hideRootToken) | ||||
| 
 | ||||
|     json.mediaProgress = json.mediaProgress.map(lip => { | ||||
|       const libraryItem = this.db.libraryItems.find(li => li.id === lip.libraryItemId) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user