2023-03-19 23:41:27 +01:00
|
|
|
const { Sequelize } = require('sequelize')
|
2023-03-19 21:19:22 +01:00
|
|
|
const Database = require('../Database')
|
|
|
|
|
|
|
|
class LibraryItemController {
|
|
|
|
constructor() { }
|
|
|
|
|
2023-03-19 23:41:27 +01:00
|
|
|
// Example get library item full, expanded, minified
|
2023-03-19 21:19:22 +01:00
|
|
|
async get(req, res) {
|
2023-03-19 23:41:27 +01:00
|
|
|
const key = req.query.minified == 1 ? 'minified' : req.query.expanded == 1 ? 'expanded' : 'full'
|
2023-03-19 21:19:22 +01:00
|
|
|
const include = {
|
|
|
|
minified: [
|
2023-03-19 23:41:27 +01:00
|
|
|
{
|
|
|
|
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: [
|
2023-03-19 21:19:22 +01:00
|
|
|
{
|
|
|
|
model: Database.models.book,
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
model: Database.models.audioTrack
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.genre,
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.tag,
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.person,
|
|
|
|
as: 'authors',
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.person,
|
|
|
|
as: 'narrators',
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.series,
|
|
|
|
through: {
|
|
|
|
attributes: ['sequence']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.bookChapter
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.eBookFile,
|
|
|
|
include: 'fileMetadata'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.podcast,
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
model: Database.models.podcastEpisode,
|
|
|
|
include: {
|
|
|
|
model: Database.models.audioTrack
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.genre,
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.tag,
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2023-03-19 23:41:27 +01:00
|
|
|
expanded: [
|
2023-03-19 21:19:22 +01:00
|
|
|
{
|
|
|
|
model: Database.models.book,
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
model: Database.models.fileMetadata,
|
|
|
|
as: 'imageFile'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.audioTrack,
|
|
|
|
include: {
|
|
|
|
model: Database.models.mediaFile,
|
|
|
|
include: [
|
|
|
|
'fileMetadata',
|
|
|
|
'mediaStreams'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.genre,
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.tag,
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.person,
|
|
|
|
as: 'authors',
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.person,
|
|
|
|
as: 'narrators',
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.series,
|
|
|
|
through: {
|
|
|
|
attributes: ['sequence']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.bookChapter
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.eBookFile,
|
|
|
|
include: 'fileMetadata'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.podcast,
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
model: Database.models.fileMetadata,
|
|
|
|
as: 'imageFile'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.podcastEpisode,
|
|
|
|
include: {
|
|
|
|
model: Database.models.audioTrack,
|
|
|
|
include: {
|
|
|
|
model: Database.models.mediaFile,
|
|
|
|
include: [
|
|
|
|
'fileMetadata',
|
|
|
|
'mediaStreams'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.genre,
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.tag,
|
|
|
|
through: {
|
|
|
|
attributes: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.libraryFile,
|
|
|
|
include: 'fileMetadata'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
model: Database.models.libraryFolder,
|
|
|
|
include: 'library'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
const LibraryItem = await Database.models.libraryItem.findByPk(req.params.id, {
|
|
|
|
include: include[key]
|
|
|
|
})
|
|
|
|
|
|
|
|
res.json(LibraryItem)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = new LibraryItemController()
|