mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-03 17:54:54 +02:00
Updates to LibraryController to use new Library model
- Additional validation on API endpoints - Removed success toast when reorder libraries
This commit is contained in:
parent
e0de59a4b6
commit
5d13faef33
12 changed files with 260 additions and 169 deletions
|
@ -173,16 +173,16 @@ module.exports = {
|
|||
/**
|
||||
* Search library items
|
||||
* @param {import('../../models/User')} user
|
||||
* @param {import('../../objects/Library')} oldLibrary
|
||||
* @param {import('../../models/Library')} library
|
||||
* @param {string} query
|
||||
* @param {number} limit
|
||||
* @returns {{book:object[], narrators:object[], authors:object[], tags:object[], series:object[], podcast:object[]}}
|
||||
*/
|
||||
search(user, oldLibrary, query, limit) {
|
||||
if (oldLibrary.isBook) {
|
||||
return libraryItemsBookFilters.search(user, oldLibrary, query, limit, 0)
|
||||
search(user, library, query, limit) {
|
||||
if (library.isBook) {
|
||||
return libraryItemsBookFilters.search(user, library, query, limit, 0)
|
||||
} else {
|
||||
return libraryItemsPodcastFilters.search(user, oldLibrary, query, limit, 0)
|
||||
return libraryItemsPodcastFilters.search(user, library, query, limit, 0)
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -966,13 +966,13 @@ module.exports = {
|
|||
/**
|
||||
* Search books, authors, series
|
||||
* @param {import('../../models/User')} user
|
||||
* @param {import('../../objects/Library')} oldLibrary
|
||||
* @param {import('../../models/Library')} library
|
||||
* @param {string} query
|
||||
* @param {number} limit
|
||||
* @param {number} offset
|
||||
* @returns {{book:object[], narrators:object[], authors:object[], tags:object[], series:object[]}}
|
||||
*/
|
||||
async search(user, oldLibrary, query, limit, offset) {
|
||||
async search(user, library, query, limit, offset) {
|
||||
const userPermissionBookWhere = this.getUserPermissionBookWhereQuery(user)
|
||||
|
||||
const normalizedQuery = query
|
||||
|
@ -1006,7 +1006,7 @@ module.exports = {
|
|||
{
|
||||
model: Database.libraryItemModel,
|
||||
where: {
|
||||
libraryId: oldLibrary.id
|
||||
libraryId: library.id
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -1047,7 +1047,7 @@ module.exports = {
|
|||
const narratorMatches = []
|
||||
const [narratorResults] = await Database.sequelize.query(`SELECT value, count(*) AS numBooks FROM books b, libraryItems li, json_each(b.narrators) WHERE json_valid(b.narrators) AND ${matchJsonValue} AND b.id = li.mediaId AND li.libraryId = :libraryId GROUP BY value LIMIT :limit OFFSET :offset;`, {
|
||||
replacements: {
|
||||
libraryId: oldLibrary.id,
|
||||
libraryId: library.id,
|
||||
limit,
|
||||
offset
|
||||
},
|
||||
|
@ -1064,7 +1064,7 @@ module.exports = {
|
|||
const tagMatches = []
|
||||
const [tagResults] = await Database.sequelize.query(`SELECT value, count(*) AS numItems FROM books b, libraryItems li, json_each(b.tags) WHERE json_valid(b.tags) AND ${matchJsonValue} AND b.id = li.mediaId AND li.libraryId = :libraryId GROUP BY value ORDER BY numItems DESC LIMIT :limit OFFSET :offset;`, {
|
||||
replacements: {
|
||||
libraryId: oldLibrary.id,
|
||||
libraryId: library.id,
|
||||
limit,
|
||||
offset
|
||||
},
|
||||
|
@ -1081,7 +1081,7 @@ module.exports = {
|
|||
const genreMatches = []
|
||||
const [genreResults] = await Database.sequelize.query(`SELECT value, count(*) AS numItems FROM books b, libraryItems li, json_each(b.genres) WHERE json_valid(b.genres) AND ${matchJsonValue} AND b.id = li.mediaId AND li.libraryId = :libraryId GROUP BY value ORDER BY numItems DESC LIMIT :limit OFFSET :offset;`, {
|
||||
replacements: {
|
||||
libraryId: oldLibrary.id,
|
||||
libraryId: library.id,
|
||||
limit,
|
||||
offset
|
||||
},
|
||||
|
@ -1101,7 +1101,7 @@ module.exports = {
|
|||
[Sequelize.Op.and]: [
|
||||
Sequelize.literal(matchName),
|
||||
{
|
||||
libraryId: oldLibrary.id
|
||||
libraryId: library.id
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1136,7 +1136,7 @@ module.exports = {
|
|||
}
|
||||
|
||||
// Search authors
|
||||
const authorMatches = await authorFilters.search(oldLibrary.id, normalizedQuery, limit, offset)
|
||||
const authorMatches = await authorFilters.search(library.id, normalizedQuery, limit, offset)
|
||||
|
||||
return {
|
||||
book: itemMatches,
|
||||
|
|
|
@ -306,13 +306,13 @@ module.exports = {
|
|||
/**
|
||||
* Search podcasts
|
||||
* @param {import('../../models/User')} user
|
||||
* @param {import('../../objects/Library')} oldLibrary
|
||||
* @param {import('../../models/Library')} library
|
||||
* @param {string} query
|
||||
* @param {number} limit
|
||||
* @param {number} offset
|
||||
* @returns {{podcast:object[], tags:object[]}}
|
||||
*/
|
||||
async search(user, oldLibrary, query, limit, offset) {
|
||||
async search(user, library, query, limit, offset) {
|
||||
const userPermissionPodcastWhere = this.getUserPermissionPodcastWhereQuery(user)
|
||||
|
||||
const normalizedQuery = query
|
||||
|
@ -345,7 +345,7 @@ module.exports = {
|
|||
{
|
||||
model: Database.libraryItemModel,
|
||||
where: {
|
||||
libraryId: oldLibrary.id
|
||||
libraryId: library.id
|
||||
}
|
||||
}
|
||||
],
|
||||
|
@ -372,7 +372,7 @@ module.exports = {
|
|||
const tagMatches = []
|
||||
const [tagResults] = await Database.sequelize.query(`SELECT value, count(*) AS numItems FROM podcasts p, libraryItems li, json_each(p.tags) WHERE json_valid(p.tags) AND ${matchJsonValue} AND p.id = li.mediaId AND li.libraryId = :libraryId GROUP BY value ORDER BY numItems DESC LIMIT :limit OFFSET :offset;`, {
|
||||
replacements: {
|
||||
libraryId: oldLibrary.id,
|
||||
libraryId: library.id,
|
||||
limit,
|
||||
offset
|
||||
},
|
||||
|
@ -389,7 +389,7 @@ module.exports = {
|
|||
const genreMatches = []
|
||||
const [genreResults] = await Database.sequelize.query(`SELECT value, count(*) AS numItems FROM podcasts p, libraryItems li, json_each(p.genres) WHERE json_valid(p.genres) AND ${matchJsonValue} AND p.id = li.mediaId AND li.libraryId = :libraryId GROUP BY value ORDER BY numItems DESC LIMIT :limit OFFSET :offset;`, {
|
||||
replacements: {
|
||||
libraryId: oldLibrary.id,
|
||||
libraryId: library.id,
|
||||
limit,
|
||||
offset
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue