mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Update library item example route
This commit is contained in:
		
							parent
							
								
									54ca58e610
								
							
						
					
					
						commit
						258b9ec54e
					
				| @ -104,7 +104,7 @@ class Server { | |||||||
|     await this.playbackSessionManager.removeOrphanStreams() |     await this.playbackSessionManager.removeOrphanStreams() | ||||||
| 
 | 
 | ||||||
|     // TODO: Test new db connection
 |     // TODO: Test new db connection
 | ||||||
|     const force = true |     const force = false | ||||||
|     await Database.init(force) |     await Database.init(force) | ||||||
|     if (force) await dbMigration3.migrate() |     if (force) await dbMigration3.migrate() | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,13 +1,86 @@ | |||||||
|  | const { Sequelize } = require('sequelize') | ||||||
| const Database = require('../Database') | const Database = require('../Database') | ||||||
| 
 | 
 | ||||||
| class LibraryItemController { | class LibraryItemController { | ||||||
|   constructor() { } |   constructor() { } | ||||||
| 
 | 
 | ||||||
|   // Example get library item fully expanded or minified
 |   // Example get library item full, expanded, minified
 | ||||||
|   async get(req, res) { |   async get(req, res) { | ||||||
|     const key = req.query.minified == 1 ? 'minified' : 'full' |     const key = req.query.minified == 1 ? 'minified' : req.query.expanded == 1 ? 'expanded' : 'full' | ||||||
|     const include = { |     const include = { | ||||||
|       minified: [ |       minified: [ | ||||||
|  |         { | ||||||
|  |           model: Database.models.book, | ||||||
|  |           attributes: [ | ||||||
|  |             'id', 'title', 'subtitle', 'publishedYear', 'publishedDate', 'publisher', 'description', 'isbn', 'asin', 'language', 'explicit', | ||||||
|  |             [Sequelize.literal('(SELECT COUNT(*) FROM "audioTracks" WHERE "audioTracks"."mediaItemId" = book.id)'), 'numAudioTracks'], | ||||||
|  |             [Sequelize.literal('(SELECT COUNT(*) FROM "bookChapters" WHERE "bookChapters"."bookId" = book.id)'), 'numChapters'] | ||||||
|  |           ], | ||||||
|  |           include: [ | ||||||
|  |             { | ||||||
|  |               model: Database.models.genre, | ||||||
|  |               attributes: ['id', 'name'], | ||||||
|  |               through: { | ||||||
|  |                 attributes: [] | ||||||
|  |               } | ||||||
|  |             }, | ||||||
|  |             { | ||||||
|  |               model: Database.models.tag, | ||||||
|  |               attributes: ['id', 'name'], | ||||||
|  |               through: { | ||||||
|  |                 attributes: [] | ||||||
|  |               } | ||||||
|  |             }, | ||||||
|  |             { | ||||||
|  |               model: Database.models.person, | ||||||
|  |               as: 'authors', | ||||||
|  |               attributes: ['id', 'name'], | ||||||
|  |               through: { | ||||||
|  |                 attributes: [] | ||||||
|  |               } | ||||||
|  |             }, | ||||||
|  |             { | ||||||
|  |               model: Database.models.person, | ||||||
|  |               as: 'narrators', | ||||||
|  |               attributes: ['id', 'name'], | ||||||
|  |               through: { | ||||||
|  |                 attributes: [] | ||||||
|  |               } | ||||||
|  |             }, | ||||||
|  |             { | ||||||
|  |               model: Database.models.series, | ||||||
|  |               attributes: ['id', 'name'], | ||||||
|  |               through: { | ||||||
|  |                 attributes: ['sequence'] | ||||||
|  |               } | ||||||
|  |             } | ||||||
|  |           ] | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           model: Database.models.podcast, | ||||||
|  |           attributes: [ | ||||||
|  |             'id', 'title', 'author', 'releaseDate', 'feedURL', 'imageURL', 'description', 'itunesPageURL', 'itunesId', 'itunesArtistId', 'language', 'podcastType', 'explicit', 'autoDownloadEpisodes', | ||||||
|  |             [Sequelize.literal('(SELECT COUNT(*) FROM "podcastEpisodes" WHERE "podcastEpisodes"."podcastId" = podcast.id)'), 'numPodcastEpisodes'] | ||||||
|  |           ], | ||||||
|  |           include: [ | ||||||
|  |             { | ||||||
|  |               model: Database.models.genre, | ||||||
|  |               attributes: ['id', 'name'], | ||||||
|  |               through: { | ||||||
|  |                 attributes: [] | ||||||
|  |               } | ||||||
|  |             }, | ||||||
|  |             { | ||||||
|  |               model: Database.models.tag, | ||||||
|  |               attributes: ['id', 'name'], | ||||||
|  |               through: { | ||||||
|  |                 attributes: [] | ||||||
|  |               } | ||||||
|  |             }, | ||||||
|  |           ] | ||||||
|  |         } | ||||||
|  |       ], | ||||||
|  |       full: [ | ||||||
|         { |         { | ||||||
|           model: Database.models.book, |           model: Database.models.book, | ||||||
|           include: [ |           include: [ | ||||||
| @ -79,7 +152,7 @@ class LibraryItemController { | |||||||
|           ] |           ] | ||||||
|         } |         } | ||||||
|       ], |       ], | ||||||
|       full: [ |       expanded: [ | ||||||
|         { |         { | ||||||
|           model: Database.models.book, |           model: Database.models.book, | ||||||
|           include: [ |           include: [ | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user