mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-23 21:51:56 +01:00
Update db model references
This commit is contained in:
parent
21343ffbd1
commit
6c1b4e3a36
@ -32,7 +32,7 @@ class Auth {
|
||||
await Database.updateServerSettings()
|
||||
|
||||
// New token secret creation added in v2.1.0 so generate new API tokens for each user
|
||||
const users = await Database.models.user.getOldUsers()
|
||||
const users = await Database.userModel.getOldUsers()
|
||||
if (users.length) {
|
||||
for (const user of users) {
|
||||
user.token = await this.generateAccessToken({ userId: user.id, username: user.username })
|
||||
@ -100,7 +100,7 @@ class Auth {
|
||||
return resolve(null)
|
||||
}
|
||||
|
||||
const user = await Database.models.user.getUserByIdOrOldId(payload.userId)
|
||||
const user = await Database.userModel.getUserByIdOrOldId(payload.userId)
|
||||
if (user && user.username === payload.username) {
|
||||
resolve(user)
|
||||
} else {
|
||||
@ -116,7 +116,7 @@ class Auth {
|
||||
* @returns {object}
|
||||
*/
|
||||
async getUserLoginResponsePayload(user) {
|
||||
const libraryIds = await Database.models.library.getAllLibraryIds()
|
||||
const libraryIds = await Database.libraryModel.getAllLibraryIds()
|
||||
return {
|
||||
user: user.toJSONForBrowser(),
|
||||
userDefaultLibraryId: user.getDefaultLibraryId(libraryIds),
|
||||
@ -131,7 +131,7 @@ class Auth {
|
||||
const username = (req.body.username || '').toLowerCase()
|
||||
const password = req.body.password || ''
|
||||
|
||||
const user = await Database.models.user.getUserByUsername(username)
|
||||
const user = await Database.userModel.getUserByUsername(username)
|
||||
|
||||
if (!user?.isActive) {
|
||||
Logger.warn(`[Auth] Failed login attempt ${req.rateLimit.current} of ${req.rateLimit.limit} from ${ipAddress}`)
|
||||
@ -178,7 +178,7 @@ class Auth {
|
||||
async userChangePassword(req, res) {
|
||||
var { password, newPassword } = req.body
|
||||
newPassword = newPassword || ''
|
||||
const matchingUser = await Database.models.user.getUserById(req.user.id)
|
||||
const matchingUser = await Database.userModel.getUserById(req.user.id)
|
||||
|
||||
// Only root can have an empty password
|
||||
if (matchingUser.type !== 'root' && !newPassword) {
|
||||
|
@ -34,6 +34,16 @@ class Database {
|
||||
return this.sequelize?.models || {}
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/User')} */
|
||||
get userModel() {
|
||||
return this.models.user
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/Library')} */
|
||||
get libraryModel() {
|
||||
return this.models.library
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/Author')} */
|
||||
get authorModel() {
|
||||
return this.models.author
|
||||
@ -49,11 +59,26 @@ class Database {
|
||||
return this.models.book
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/BookSeries')} */
|
||||
get bookSeriesModel() {
|
||||
return this.models.bookSeries
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/BookAuthor')} */
|
||||
get bookAuthorModel() {
|
||||
return this.models.bookAuthor
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/Podcast')} */
|
||||
get podcastModel() {
|
||||
return this.models.podcast
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/PodcastEpisode')} */
|
||||
get podcastEpisodeModel() {
|
||||
return this.models.podcastEpisode
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/LibraryItem')} */
|
||||
get libraryItemModel() {
|
||||
return this.models.libraryItem
|
||||
@ -69,6 +94,36 @@ class Database {
|
||||
return this.models.mediaProgress
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/Collection')} */
|
||||
get collectionModel() {
|
||||
return this.models.collection
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/CollectionBook')} */
|
||||
get collectionBookModel() {
|
||||
return this.models.collectionBook
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/Playlist')} */
|
||||
get playlistModel() {
|
||||
return this.models.playlist
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/PlaylistMediaItem')} */
|
||||
get playlistMediaItemModel() {
|
||||
return this.models.playlistMediaItem
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/Feed')} */
|
||||
get feedModel() {
|
||||
return this.models.feed
|
||||
}
|
||||
|
||||
/** @type {typeof import('./models/Feed')} */
|
||||
get feedEpisodeModel() {
|
||||
return this.models.feedEpisode
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if db file exists
|
||||
* @returns {boolean}
|
||||
|
@ -116,7 +116,7 @@ class Server {
|
||||
await this.logManager.init()
|
||||
await this.rssFeedManager.init()
|
||||
|
||||
const libraries = await Database.models.library.getAllOldLibraries()
|
||||
const libraries = await Database.libraryModel.getAllOldLibraries()
|
||||
await this.cronManager.init(libraries)
|
||||
|
||||
if (Database.serverSettings.scannerDisableWatcher) {
|
||||
@ -253,7 +253,7 @@ class Server {
|
||||
*/
|
||||
async cleanUserData() {
|
||||
// Get all media progress without an associated media item
|
||||
const mediaProgressToRemove = await Database.models.mediaProgress.findAll({
|
||||
const mediaProgressToRemove = await Database.mediaProgressModel.findAll({
|
||||
where: {
|
||||
'$podcastEpisode.id$': null,
|
||||
'$book.id$': null
|
||||
@ -261,18 +261,18 @@ class Server {
|
||||
attributes: ['id'],
|
||||
include: [
|
||||
{
|
||||
model: Database.models.book,
|
||||
model: Database.bookModel,
|
||||
attributes: ['id']
|
||||
},
|
||||
{
|
||||
model: Database.models.podcastEpisode,
|
||||
model: Database.podcastEpisodeModel,
|
||||
attributes: ['id']
|
||||
}
|
||||
]
|
||||
})
|
||||
if (mediaProgressToRemove.length) {
|
||||
// Remove media progress
|
||||
const mediaProgressRemoved = await Database.models.mediaProgress.destroy({
|
||||
const mediaProgressRemoved = await Database.mediaProgressModel.destroy({
|
||||
where: {
|
||||
id: {
|
||||
[Sequelize.Op.in]: mediaProgressToRemove.map(mp => mp.id)
|
||||
@ -285,7 +285,7 @@ class Server {
|
||||
}
|
||||
|
||||
// Remove series from hide from continue listening that no longer exist
|
||||
const users = await Database.models.user.getOldUsers()
|
||||
const users = await Database.userModel.getOldUsers()
|
||||
for (const _user of users) {
|
||||
let hasUpdated = false
|
||||
if (_user.seriesHideFromContinueListening.length) {
|
||||
|
@ -21,7 +21,7 @@ class AuthorController {
|
||||
|
||||
// Used on author landing page to include library items and items grouped in series
|
||||
if (include.includes('items')) {
|
||||
authorJson.libraryItems = await Database.models.libraryItem.getForAuthor(req.author, req.user)
|
||||
authorJson.libraryItems = await Database.libraryItemModel.getForAuthor(req.author, req.user)
|
||||
|
||||
if (include.includes('series')) {
|
||||
const seriesMap = {}
|
||||
@ -96,7 +96,7 @@ class AuthorController {
|
||||
const existingAuthor = authorNameUpdate ? Database.authors.find(au => au.id !== req.author.id && payload.name === au.name) : false
|
||||
if (existingAuthor) {
|
||||
const bookAuthorsToCreate = []
|
||||
const itemsWithAuthor = await Database.models.libraryItem.getForAuthor(req.author)
|
||||
const itemsWithAuthor = await Database.libraryItemModel.getForAuthor(req.author)
|
||||
itemsWithAuthor.forEach(libraryItem => { // Replace old author with merging author for each book
|
||||
libraryItem.media.metadata.replaceAuthor(req.author, existingAuthor)
|
||||
bookAuthorsToCreate.push({
|
||||
@ -117,7 +117,7 @@ class AuthorController {
|
||||
Database.removeAuthorFromFilterData(req.author.libraryId, req.author.id)
|
||||
|
||||
// Send updated num books for merged author
|
||||
const numBooks = await Database.models.libraryItem.getForAuthor(existingAuthor).length
|
||||
const numBooks = await Database.libraryItemModel.getForAuthor(existingAuthor).length
|
||||
SocketAuthority.emitter('author_updated', existingAuthor.toJSONExpanded(numBooks))
|
||||
|
||||
res.json({
|
||||
@ -132,7 +132,7 @@ class AuthorController {
|
||||
if (hasUpdated) {
|
||||
req.author.updatedAt = Date.now()
|
||||
|
||||
const itemsWithAuthor = await Database.models.libraryItem.getForAuthor(req.author)
|
||||
const itemsWithAuthor = await Database.libraryItemModel.getForAuthor(req.author)
|
||||
if (authorNameUpdate) { // Update author name on all books
|
||||
itemsWithAuthor.forEach(libraryItem => {
|
||||
libraryItem.media.metadata.updateAuthor(req.author)
|
||||
@ -204,7 +204,7 @@ class AuthorController {
|
||||
|
||||
await Database.updateAuthor(req.author)
|
||||
|
||||
const numBooks = await Database.models.libraryItem.getForAuthor(req.author).length
|
||||
const numBooks = await Database.libraryItemModel.getForAuthor(req.author).length
|
||||
SocketAuthority.emitter('author_updated', req.author.toJSONExpanded(numBooks))
|
||||
}
|
||||
|
||||
|
@ -22,10 +22,10 @@ class CollectionController {
|
||||
}
|
||||
|
||||
// Create collection record
|
||||
await Database.models.collection.createFromOld(newCollection)
|
||||
await Database.collectionModel.createFromOld(newCollection)
|
||||
|
||||
// Get library items in collection
|
||||
const libraryItemsInCollection = await Database.models.libraryItem.getForCollection(newCollection)
|
||||
const libraryItemsInCollection = await Database.libraryItemModel.getForCollection(newCollection)
|
||||
|
||||
// Create collectionBook records
|
||||
let order = 1
|
||||
@ -50,7 +50,7 @@ class CollectionController {
|
||||
}
|
||||
|
||||
async findAll(req, res) {
|
||||
const collectionsExpanded = await Database.models.collection.getOldCollectionsJsonExpanded(req.user)
|
||||
const collectionsExpanded = await Database.collectionModel.getOldCollectionsJsonExpanded(req.user)
|
||||
res.json({
|
||||
collections: collectionsExpanded
|
||||
})
|
||||
@ -96,8 +96,8 @@ class CollectionController {
|
||||
if (req.body.books?.length) {
|
||||
const collectionBooks = await req.collection.getCollectionBooks({
|
||||
include: {
|
||||
model: Database.models.book,
|
||||
include: Database.models.libraryItem
|
||||
model: Database.bookModel,
|
||||
include: Database.libraryItemModel
|
||||
},
|
||||
order: [['order', 'ASC']]
|
||||
})
|
||||
@ -143,7 +143,7 @@ class CollectionController {
|
||||
* @param {*} res
|
||||
*/
|
||||
async addBook(req, res) {
|
||||
const libraryItem = await Database.models.libraryItem.getOldById(req.body.id)
|
||||
const libraryItem = await Database.libraryItemModel.getOldById(req.body.id)
|
||||
if (!libraryItem) {
|
||||
return res.status(404).send('Book not found')
|
||||
}
|
||||
@ -158,7 +158,7 @@ class CollectionController {
|
||||
}
|
||||
|
||||
// Create collectionBook record
|
||||
await Database.models.collectionBook.create({
|
||||
await Database.collectionBookModel.create({
|
||||
collectionId: req.collection.id,
|
||||
bookId: libraryItem.media.id,
|
||||
order: collectionBooks.length + 1
|
||||
@ -176,7 +176,7 @@ class CollectionController {
|
||||
* @param {*} res
|
||||
*/
|
||||
async removeBook(req, res) {
|
||||
const libraryItem = await Database.models.libraryItem.getOldById(req.params.bookId)
|
||||
const libraryItem = await Database.libraryItemModel.getOldById(req.params.bookId)
|
||||
if (!libraryItem) {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
@ -227,14 +227,14 @@ class CollectionController {
|
||||
}
|
||||
|
||||
// Get library items associated with ids
|
||||
const libraryItems = await Database.models.libraryItem.findAll({
|
||||
const libraryItems = await Database.libraryItemModel.findAll({
|
||||
where: {
|
||||
id: {
|
||||
[Sequelize.Op.in]: bookIdsToAdd
|
||||
}
|
||||
},
|
||||
include: {
|
||||
model: Database.models.book
|
||||
model: Database.bookModel
|
||||
}
|
||||
})
|
||||
|
||||
@ -285,14 +285,14 @@ class CollectionController {
|
||||
}
|
||||
|
||||
// Get library items associated with ids
|
||||
const libraryItems = await Database.models.libraryItem.findAll({
|
||||
const libraryItems = await Database.libraryItemModel.findAll({
|
||||
where: {
|
||||
id: {
|
||||
[Sequelize.Op.in]: bookIdsToRemove
|
||||
}
|
||||
},
|
||||
include: {
|
||||
model: Database.models.book
|
||||
model: Database.bookModel
|
||||
}
|
||||
})
|
||||
|
||||
@ -327,7 +327,7 @@ class CollectionController {
|
||||
|
||||
async middleware(req, res, next) {
|
||||
if (req.params.id) {
|
||||
const collection = await Database.models.collection.findByPk(req.params.id)
|
||||
const collection = await Database.collectionModel.findByPk(req.params.id)
|
||||
if (!collection) {
|
||||
return res.status(404).send('Collection not found')
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class FileSystemController {
|
||||
})
|
||||
|
||||
// Do not include existing mapped library paths in response
|
||||
const libraryFoldersPaths = await Database.models.libraryFolder.getAllLibraryFolderPaths()
|
||||
const libraryFoldersPaths = await Database.libraryModelFolder.getAllLibraryFolderPaths()
|
||||
libraryFoldersPaths.forEach((path) => {
|
||||
let dir = path || ''
|
||||
if (dir.includes(global.appRoot)) dir = dir.replace(global.appRoot, '')
|
||||
|
@ -51,7 +51,7 @@ class LibraryController {
|
||||
|
||||
const library = new Library()
|
||||
|
||||
let currentLargestDisplayOrder = await Database.models.library.getMaxDisplayOrder()
|
||||
let currentLargestDisplayOrder = await Database.libraryModel.getMaxDisplayOrder()
|
||||
if (isNaN(currentLargestDisplayOrder)) currentLargestDisplayOrder = 0
|
||||
newLibraryPayload.displayOrder = currentLargestDisplayOrder + 1
|
||||
library.setData(newLibraryPayload)
|
||||
@ -70,7 +70,7 @@ class LibraryController {
|
||||
}
|
||||
|
||||
async findAll(req, res) {
|
||||
const libraries = await Database.models.library.getAllOldLibraries()
|
||||
const libraries = await Database.libraryModel.getAllOldLibraries()
|
||||
|
||||
const librariesAccessible = req.user.librariesAccessible || []
|
||||
if (librariesAccessible.length) {
|
||||
@ -92,7 +92,7 @@ class LibraryController {
|
||||
return res.json({
|
||||
filterdata,
|
||||
issues: filterdata.numIssues,
|
||||
numUserPlaylists: await Database.models.playlist.getNumPlaylistsForUserAndLibrary(req.user.id, req.library.id),
|
||||
numUserPlaylists: await Database.playlistModel.getNumPlaylistsForUserAndLibrary(req.user.id, req.library.id),
|
||||
library: req.library
|
||||
})
|
||||
}
|
||||
@ -144,17 +144,17 @@ class LibraryController {
|
||||
for (const folder of library.folders) {
|
||||
if (!req.body.folders.some(f => f.id === folder.id)) {
|
||||
// Remove library items in folder
|
||||
const libraryItemsInFolder = await Database.models.libraryItem.findAll({
|
||||
const libraryItemsInFolder = await Database.libraryItemModel.findAll({
|
||||
where: {
|
||||
libraryFolderId: folder.id
|
||||
},
|
||||
attributes: ['id', 'mediaId', 'mediaType'],
|
||||
include: [
|
||||
{
|
||||
model: Database.models.podcast,
|
||||
model: Database.podcastModel,
|
||||
attributes: ['id'],
|
||||
include: {
|
||||
model: Database.models.podcastEpisode,
|
||||
model: Database.podcastEpisodeModel,
|
||||
attributes: ['id']
|
||||
}
|
||||
}
|
||||
@ -210,23 +210,23 @@ class LibraryController {
|
||||
this.watcher.removeLibrary(library)
|
||||
|
||||
// Remove collections for library
|
||||
const numCollectionsRemoved = await Database.models.collection.removeAllForLibrary(library.id)
|
||||
const numCollectionsRemoved = await Database.collectionModel.removeAllForLibrary(library.id)
|
||||
if (numCollectionsRemoved) {
|
||||
Logger.info(`[Server] Removed ${numCollectionsRemoved} collections for library "${library.name}"`)
|
||||
}
|
||||
|
||||
// Remove items in this library
|
||||
const libraryItemsInLibrary = await Database.models.libraryItem.findAll({
|
||||
const libraryItemsInLibrary = await Database.libraryItemModel.findAll({
|
||||
where: {
|
||||
libraryId: library.id
|
||||
},
|
||||
attributes: ['id', 'mediaId', 'mediaType'],
|
||||
include: [
|
||||
{
|
||||
model: Database.models.podcast,
|
||||
model: Database.podcastModel,
|
||||
attributes: ['id'],
|
||||
include: {
|
||||
model: Database.models.podcastEpisode,
|
||||
model: Database.podcastEpisodeModel,
|
||||
attributes: ['id']
|
||||
}
|
||||
}
|
||||
@ -248,7 +248,7 @@ class LibraryController {
|
||||
await Database.removeLibrary(library.id)
|
||||
|
||||
// Re-order libraries
|
||||
await Database.models.library.resetDisplayOrder()
|
||||
await Database.libraryModel.resetDisplayOrder()
|
||||
|
||||
SocketAuthority.emitter('library_removed', libraryJson)
|
||||
|
||||
@ -278,7 +278,7 @@ class LibraryController {
|
||||
}
|
||||
payload.offset = payload.page * payload.limit
|
||||
|
||||
const { libraryItems, count } = await Database.models.libraryItem.getByFilterAndSort(req.library, req.user, payload)
|
||||
const { libraryItems, count } = await Database.libraryItemModel.getByFilterAndSort(req.library, req.user, payload)
|
||||
payload.results = libraryItems
|
||||
payload.total = count
|
||||
|
||||
@ -486,7 +486,7 @@ class LibraryController {
|
||||
* @param {import('express').Response} res
|
||||
*/
|
||||
async removeLibraryItemsWithIssues(req, res) {
|
||||
const libraryItemsWithIssues = await Database.models.libraryItem.findAll({
|
||||
const libraryItemsWithIssues = await Database.libraryItemModel.findAll({
|
||||
where: {
|
||||
libraryId: req.library.id,
|
||||
[Sequelize.Op.or]: [
|
||||
@ -501,10 +501,10 @@ class LibraryController {
|
||||
attributes: ['id', 'mediaId', 'mediaType'],
|
||||
include: [
|
||||
{
|
||||
model: Database.models.podcast,
|
||||
model: Database.podcastModel,
|
||||
attributes: ['id'],
|
||||
include: {
|
||||
model: Database.models.podcastEpisode,
|
||||
model: Database.podcastEpisodeModel,
|
||||
attributes: ['id']
|
||||
}
|
||||
}
|
||||
@ -624,7 +624,7 @@ class LibraryController {
|
||||
}
|
||||
|
||||
// TODO: Create paginated queries
|
||||
let collections = await Database.models.collection.getOldCollectionsJsonExpanded(req.user, req.library.id, include)
|
||||
let collections = await Database.collectionModel.getOldCollectionsJsonExpanded(req.user, req.library.id, include)
|
||||
|
||||
payload.total = collections.length
|
||||
|
||||
@ -644,7 +644,7 @@ class LibraryController {
|
||||
* @param {*} res
|
||||
*/
|
||||
async getUserPlaylistsForLibrary(req, res) {
|
||||
let playlistsForUser = await Database.models.playlist.getPlaylistsForUserAndLibrary(req.user.id, req.library.id)
|
||||
let playlistsForUser = await Database.playlistModel.getPlaylistsForUserAndLibrary(req.user.id, req.library.id)
|
||||
playlistsForUser = await Promise.all(playlistsForUser.map(async p => p.getOldJsonExpanded()))
|
||||
|
||||
const payload = {
|
||||
@ -697,7 +697,7 @@ class LibraryController {
|
||||
Logger.error('[LibraryController] ReorderLibraries invalid user', req.user)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
const libraries = await Database.models.library.getAllOldLibraries()
|
||||
const libraries = await Database.libraryModel.getAllOldLibraries()
|
||||
|
||||
const orderdata = req.body
|
||||
let hasUpdates = false
|
||||
@ -799,7 +799,7 @@ class LibraryController {
|
||||
},
|
||||
replacements,
|
||||
include: {
|
||||
model: Database.models.book,
|
||||
model: Database.bookModel,
|
||||
attributes: ['id', 'tags', 'explicit'],
|
||||
where: bookWhere,
|
||||
required: true,
|
||||
@ -832,12 +832,12 @@ class LibraryController {
|
||||
*/
|
||||
async getNarrators(req, res) {
|
||||
// Get all books with narrators
|
||||
const booksWithNarrators = await Database.models.book.findAll({
|
||||
const booksWithNarrators = await Database.bookModel.findAll({
|
||||
where: Sequelize.where(Sequelize.fn('json_array_length', Sequelize.col('narrators')), {
|
||||
[Sequelize.Op.gt]: 0
|
||||
}),
|
||||
include: {
|
||||
model: Database.models.libraryItem,
|
||||
model: Database.libraryItemModel,
|
||||
attributes: ['id', 'libraryId'],
|
||||
where: {
|
||||
libraryId: req.library.id
|
||||
@ -904,7 +904,7 @@ class LibraryController {
|
||||
await libraryItem.media.update({
|
||||
narrators: libraryItem.media.narrators
|
||||
})
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(libraryItem)
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(libraryItem)
|
||||
itemsUpdated.push(oldLibraryItem)
|
||||
}
|
||||
|
||||
@ -944,7 +944,7 @@ class LibraryController {
|
||||
await libraryItem.media.update({
|
||||
narrators: libraryItem.media.narrators
|
||||
})
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(libraryItem)
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(libraryItem)
|
||||
itemsUpdated.push(oldLibraryItem)
|
||||
}
|
||||
|
||||
@ -1041,7 +1041,7 @@ class LibraryController {
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
|
||||
const library = await Database.models.library.getOldById(req.params.id)
|
||||
const library = await Database.libraryModel.getOldById(req.params.id)
|
||||
if (!library) {
|
||||
return res.status(404).send('Library not found')
|
||||
}
|
||||
@ -1064,7 +1064,7 @@ class LibraryController {
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
|
||||
const library = await Database.models.library.getOldById(req.params.id)
|
||||
const library = await Database.libraryModel.getOldById(req.params.id)
|
||||
if (!library) {
|
||||
return res.status(404).send('Library not found')
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ class LibraryItemController {
|
||||
return res.status(400).send('Invalid request body')
|
||||
}
|
||||
|
||||
const itemsToDelete = await Database.models.libraryItem.getAllOldLibraryItems({
|
||||
const itemsToDelete = await Database.libraryItemModel.getAllOldLibraryItems({
|
||||
id: libraryItemIds
|
||||
})
|
||||
|
||||
@ -349,7 +349,7 @@ class LibraryItemController {
|
||||
|
||||
for (const updatePayload of updatePayloads) {
|
||||
const mediaPayload = updatePayload.mediaPayload
|
||||
const libraryItem = await Database.models.libraryItem.getOldById(updatePayload.id)
|
||||
const libraryItem = await Database.libraryItemModel.getOldById(updatePayload.id)
|
||||
if (!libraryItem) return null
|
||||
|
||||
await this.createAuthorsAndSeriesForItemUpdate(mediaPayload, libraryItem.libraryId)
|
||||
@ -387,7 +387,7 @@ class LibraryItemController {
|
||||
if (!libraryItemIds.length) {
|
||||
return res.status(403).send('Invalid payload')
|
||||
}
|
||||
const libraryItems = await Database.models.libraryItem.getAllOldLibraryItems({
|
||||
const libraryItems = await Database.libraryItemModel.getAllOldLibraryItems({
|
||||
id: libraryItemIds
|
||||
})
|
||||
res.json({
|
||||
@ -700,7 +700,7 @@ class LibraryItemController {
|
||||
}
|
||||
|
||||
async middleware(req, res, next) {
|
||||
req.libraryItem = await Database.models.libraryItem.getOldById(req.params.id)
|
||||
req.libraryItem = await Database.libraryItemModel.getOldById(req.params.id)
|
||||
if (!req.libraryItem?.media) return res.sendStatus(404)
|
||||
|
||||
// Check user can access this library item
|
||||
|
@ -59,7 +59,7 @@ class MeController {
|
||||
|
||||
// PATCH: api/me/progress/:id
|
||||
async createUpdateMediaProgress(req, res) {
|
||||
const libraryItem = await Database.models.libraryItem.getOldById(req.params.id)
|
||||
const libraryItem = await Database.libraryItemModel.getOldById(req.params.id)
|
||||
if (!libraryItem) {
|
||||
return res.status(404).send('Item not found')
|
||||
}
|
||||
@ -75,7 +75,7 @@ class MeController {
|
||||
// PATCH: api/me/progress/:id/:episodeId
|
||||
async createUpdateEpisodeMediaProgress(req, res) {
|
||||
const episodeId = req.params.episodeId
|
||||
const libraryItem = await Database.models.libraryItem.getOldById(req.params.id)
|
||||
const libraryItem = await Database.libraryItemModel.getOldById(req.params.id)
|
||||
if (!libraryItem) {
|
||||
return res.status(404).send('Item not found')
|
||||
}
|
||||
@ -101,7 +101,7 @@ class MeController {
|
||||
|
||||
let shouldUpdate = false
|
||||
for (const itemProgress of itemProgressPayloads) {
|
||||
const libraryItem = await Database.models.libraryItem.getOldById(itemProgress.libraryItemId)
|
||||
const libraryItem = await Database.libraryItemModel.getOldById(itemProgress.libraryItemId)
|
||||
if (libraryItem) {
|
||||
if (req.user.createUpdateMediaProgress(libraryItem, itemProgress, itemProgress.episodeId)) {
|
||||
const mediaProgress = req.user.getMediaProgress(libraryItem.id, itemProgress.episodeId)
|
||||
@ -122,7 +122,7 @@ class MeController {
|
||||
|
||||
// POST: api/me/item/:id/bookmark
|
||||
async createBookmark(req, res) {
|
||||
if (!await Database.models.libraryItem.checkExistsById(req.params.id)) return res.sendStatus(404)
|
||||
if (!await Database.libraryItemModel.checkExistsById(req.params.id)) return res.sendStatus(404)
|
||||
|
||||
const { time, title } = req.body
|
||||
const bookmark = req.user.createBookmark(req.params.id, time, title)
|
||||
@ -133,7 +133,7 @@ class MeController {
|
||||
|
||||
// PATCH: api/me/item/:id/bookmark
|
||||
async updateBookmark(req, res) {
|
||||
if (!await Database.models.libraryItem.checkExistsById(req.params.id)) return res.sendStatus(404)
|
||||
if (!await Database.libraryItemModel.checkExistsById(req.params.id)) return res.sendStatus(404)
|
||||
|
||||
const { time, title } = req.body
|
||||
if (!req.user.findBookmark(req.params.id, time)) {
|
||||
@ -151,7 +151,7 @@ class MeController {
|
||||
|
||||
// DELETE: api/me/item/:id/bookmark/:time
|
||||
async removeBookmark(req, res) {
|
||||
if (!await Database.models.libraryItem.checkExistsById(req.params.id)) return res.sendStatus(404)
|
||||
if (!await Database.libraryItemModel.checkExistsById(req.params.id)) return res.sendStatus(404)
|
||||
|
||||
const time = Number(req.params.time)
|
||||
if (isNaN(time)) return res.sendStatus(500)
|
||||
|
@ -38,7 +38,7 @@ class MiscController {
|
||||
const libraryId = req.body.library
|
||||
const folderId = req.body.folder
|
||||
|
||||
const library = await Database.models.library.getOldById(libraryId)
|
||||
const library = await Database.libraryModel.getOldById(libraryId)
|
||||
if (!library) {
|
||||
return res.status(404).send(`Library not found with id ${libraryId}`)
|
||||
}
|
||||
@ -177,7 +177,7 @@ class MiscController {
|
||||
}
|
||||
|
||||
const tags = []
|
||||
const books = await Database.models.book.findAll({
|
||||
const books = await Database.bookModel.findAll({
|
||||
attributes: ['tags'],
|
||||
where: Sequelize.where(Sequelize.fn('json_array_length', Sequelize.col('tags')), {
|
||||
[Sequelize.Op.gt]: 0
|
||||
@ -189,7 +189,7 @@ class MiscController {
|
||||
}
|
||||
}
|
||||
|
||||
const podcasts = await Database.models.podcast.findAll({
|
||||
const podcasts = await Database.podcastModel.findAll({
|
||||
attributes: ['tags'],
|
||||
where: Sequelize.where(Sequelize.fn('json_array_length', Sequelize.col('tags')), {
|
||||
[Sequelize.Op.gt]: 0
|
||||
@ -248,7 +248,7 @@ class MiscController {
|
||||
await libraryItem.media.update({
|
||||
tags: libraryItem.media.tags
|
||||
})
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(libraryItem)
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(libraryItem)
|
||||
SocketAuthority.emitter('item_updated', oldLibraryItem.toJSONExpanded())
|
||||
numItemsUpdated++
|
||||
}
|
||||
@ -289,7 +289,7 @@ class MiscController {
|
||||
await libraryItem.media.update({
|
||||
tags: libraryItem.media.tags
|
||||
})
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(libraryItem)
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(libraryItem)
|
||||
SocketAuthority.emitter('item_updated', oldLibraryItem.toJSONExpanded())
|
||||
numItemsUpdated++
|
||||
}
|
||||
@ -311,7 +311,7 @@ class MiscController {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
const genres = []
|
||||
const books = await Database.models.book.findAll({
|
||||
const books = await Database.bookModel.findAll({
|
||||
attributes: ['genres'],
|
||||
where: Sequelize.where(Sequelize.fn('json_array_length', Sequelize.col('genres')), {
|
||||
[Sequelize.Op.gt]: 0
|
||||
@ -323,7 +323,7 @@ class MiscController {
|
||||
}
|
||||
}
|
||||
|
||||
const podcasts = await Database.models.podcast.findAll({
|
||||
const podcasts = await Database.podcastModel.findAll({
|
||||
attributes: ['genres'],
|
||||
where: Sequelize.where(Sequelize.fn('json_array_length', Sequelize.col('genres')), {
|
||||
[Sequelize.Op.gt]: 0
|
||||
@ -382,7 +382,7 @@ class MiscController {
|
||||
await libraryItem.media.update({
|
||||
genres: libraryItem.media.genres
|
||||
})
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(libraryItem)
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(libraryItem)
|
||||
SocketAuthority.emitter('item_updated', oldLibraryItem.toJSONExpanded())
|
||||
numItemsUpdated++
|
||||
}
|
||||
@ -423,7 +423,7 @@ class MiscController {
|
||||
await libraryItem.media.update({
|
||||
genres: libraryItem.media.genres
|
||||
})
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(libraryItem)
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(libraryItem)
|
||||
SocketAuthority.emitter('item_updated', oldLibraryItem.toJSONExpanded())
|
||||
numItemsUpdated++
|
||||
}
|
||||
|
@ -22,11 +22,11 @@ class PlaylistController {
|
||||
}
|
||||
|
||||
// Create Playlist record
|
||||
const newPlaylist = await Database.models.playlist.createFromOld(oldPlaylist)
|
||||
const newPlaylist = await Database.playlistModel.createFromOld(oldPlaylist)
|
||||
|
||||
// Lookup all library items in playlist
|
||||
const libraryItemIds = oldPlaylist.items.map(i => i.libraryItemId).filter(i => i)
|
||||
const libraryItemsInPlaylist = await Database.models.libraryItem.findAll({
|
||||
const libraryItemsInPlaylist = await Database.libraryItemModel.findAll({
|
||||
where: {
|
||||
id: libraryItemIds
|
||||
}
|
||||
@ -62,7 +62,7 @@ class PlaylistController {
|
||||
* @param {*} res
|
||||
*/
|
||||
async findAllForUser(req, res) {
|
||||
const playlistsForUser = await Database.models.playlist.findAll({
|
||||
const playlistsForUser = await Database.playlistModel.findAll({
|
||||
where: {
|
||||
userId: req.user.id
|
||||
}
|
||||
@ -106,7 +106,7 @@ class PlaylistController {
|
||||
// If array of items is passed in then update order of playlist media items
|
||||
const libraryItemIds = req.body.items?.map(i => i.libraryItemId).filter(i => i) || []
|
||||
if (libraryItemIds.length) {
|
||||
const libraryItems = await Database.models.libraryItem.findAll({
|
||||
const libraryItems = await Database.libraryItemModel.findAll({
|
||||
where: {
|
||||
id: libraryItemIds
|
||||
}
|
||||
@ -173,14 +173,14 @@ class PlaylistController {
|
||||
* @param {*} res
|
||||
*/
|
||||
async addItem(req, res) {
|
||||
const oldPlaylist = await Database.models.playlist.getById(req.playlist.id)
|
||||
const oldPlaylist = await Database.playlistModel.getById(req.playlist.id)
|
||||
const itemToAdd = req.body
|
||||
|
||||
if (!itemToAdd.libraryItemId) {
|
||||
return res.status(400).send('Request body has no libraryItemId')
|
||||
}
|
||||
|
||||
const libraryItem = await Database.models.libraryItem.getOldById(itemToAdd.libraryItemId)
|
||||
const libraryItem = await Database.libraryItemModel.getOldById(itemToAdd.libraryItemId)
|
||||
if (!libraryItem) {
|
||||
return res.status(400).send('Library item not found')
|
||||
}
|
||||
@ -217,7 +217,7 @@ class PlaylistController {
|
||||
* @param {*} res
|
||||
*/
|
||||
async removeItem(req, res) {
|
||||
const oldLibraryItem = await Database.models.libraryItem.getOldById(req.params.libraryItemId)
|
||||
const oldLibraryItem = await Database.libraryItemModel.getOldById(req.params.libraryItemId)
|
||||
if (!oldLibraryItem) {
|
||||
return res.status(404).send('Library item not found')
|
||||
}
|
||||
@ -281,7 +281,7 @@ class PlaylistController {
|
||||
}
|
||||
|
||||
// Find all library items
|
||||
const libraryItems = await Database.models.libraryItem.findAll({
|
||||
const libraryItems = await Database.libraryItemModel.findAll({
|
||||
where: {
|
||||
id: libraryItemIds
|
||||
}
|
||||
@ -345,7 +345,7 @@ class PlaylistController {
|
||||
}
|
||||
|
||||
// Find all library items
|
||||
const libraryItems = await Database.models.libraryItem.findAll({
|
||||
const libraryItems = await Database.libraryItemModel.findAll({
|
||||
where: {
|
||||
id: libraryItemIds
|
||||
}
|
||||
@ -391,7 +391,7 @@ class PlaylistController {
|
||||
* @param {*} res
|
||||
*/
|
||||
async createFromCollection(req, res) {
|
||||
const collection = await Database.models.collection.findByPk(req.params.collectionId)
|
||||
const collection = await Database.collectionModel.findByPk(req.params.collectionId)
|
||||
if (!collection) {
|
||||
return res.status(404).send('Collection not found')
|
||||
}
|
||||
@ -416,7 +416,7 @@ class PlaylistController {
|
||||
})
|
||||
|
||||
// Create Playlist record
|
||||
const newPlaylist = await Database.models.playlist.createFromOld(oldPlaylist)
|
||||
const newPlaylist = await Database.playlistModel.createFromOld(oldPlaylist)
|
||||
|
||||
// Create PlaylistMediaItem records
|
||||
const mediaItemsToAdd = []
|
||||
@ -438,7 +438,7 @@ class PlaylistController {
|
||||
|
||||
async middleware(req, res, next) {
|
||||
if (req.params.id) {
|
||||
const playlist = await Database.models.playlist.findByPk(req.params.id)
|
||||
const playlist = await Database.playlistModel.findByPk(req.params.id)
|
||||
if (!playlist) {
|
||||
return res.status(404).send('Playlist not found')
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class PodcastController {
|
||||
}
|
||||
const payload = req.body
|
||||
|
||||
const library = await Database.models.library.getOldById(payload.libraryId)
|
||||
const library = await Database.libraryModel.getOldById(payload.libraryId)
|
||||
if (!library) {
|
||||
Logger.error(`[PodcastController] Create: Library not found "${payload.libraryId}"`)
|
||||
return res.status(404).send('Library not found')
|
||||
@ -34,7 +34,7 @@ class PodcastController {
|
||||
const podcastPath = filePathToPOSIX(payload.path)
|
||||
|
||||
// Check if a library item with this podcast folder exists already
|
||||
const existingLibraryItem = (await Database.models.libraryItem.count({
|
||||
const existingLibraryItem = (await Database.libraryItemModel.count({
|
||||
where: {
|
||||
path: podcastPath
|
||||
}
|
||||
@ -272,13 +272,13 @@ class PodcastController {
|
||||
}
|
||||
|
||||
// Update/remove playlists that had this podcast episode
|
||||
const playlistMediaItems = await Database.models.playlistMediaItem.findAll({
|
||||
const playlistMediaItems = await Database.playlistMediaItemModel.findAll({
|
||||
where: {
|
||||
mediaItemId: episodeId
|
||||
},
|
||||
include: {
|
||||
model: Database.models.playlist,
|
||||
include: Database.models.playlistMediaItem
|
||||
model: Database.playlistModel,
|
||||
include: Database.playlistMediaItemModel
|
||||
}
|
||||
})
|
||||
for (const pmi of playlistMediaItems) {
|
||||
@ -297,7 +297,7 @@ class PodcastController {
|
||||
}
|
||||
|
||||
// Remove media progress for this episode
|
||||
const mediaProgressRemoved = await Database.models.mediaProgress.destroy({
|
||||
const mediaProgressRemoved = await Database.mediaProgressModel.destroy({
|
||||
where: {
|
||||
mediaItemId: episode.id
|
||||
}
|
||||
@ -312,7 +312,7 @@ class PodcastController {
|
||||
}
|
||||
|
||||
async middleware(req, res, next) {
|
||||
const item = await Database.models.libraryItem.getOldById(req.params.id)
|
||||
const item = await Database.libraryItemModel.getOldById(req.params.id)
|
||||
if (!item?.media) return res.sendStatus(404)
|
||||
|
||||
if (!item.isPodcast) {
|
||||
|
@ -9,7 +9,7 @@ class RSSFeedController {
|
||||
async openRSSFeedForItem(req, res) {
|
||||
const options = req.body || {}
|
||||
|
||||
const item = await Database.models.libraryItem.getOldById(req.params.itemId)
|
||||
const item = await Database.libraryItemModel.getOldById(req.params.itemId)
|
||||
if (!item) return res.sendStatus(404)
|
||||
|
||||
// Check user can access this library item
|
||||
@ -46,7 +46,7 @@ class RSSFeedController {
|
||||
async openRSSFeedForCollection(req, res) {
|
||||
const options = req.body || {}
|
||||
|
||||
const collection = await Database.models.collection.findByPk(req.params.collectionId)
|
||||
const collection = await Database.collectionModel.findByPk(req.params.collectionId)
|
||||
if (!collection) return res.sendStatus(404)
|
||||
|
||||
// Check request body options exist
|
||||
|
@ -49,7 +49,7 @@ class SessionController {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
|
||||
const minifiedUserObjects = await Database.models.user.getMinifiedUserObjects()
|
||||
const minifiedUserObjects = await Database.userModel.getMinifiedUserObjects()
|
||||
const openSessions = this.playbackSessionManager.sessions.map(se => {
|
||||
return {
|
||||
...se.toJSON(),
|
||||
|
@ -106,7 +106,7 @@ class ToolsController {
|
||||
}
|
||||
|
||||
if (req.params.id) {
|
||||
const item = await Database.models.libraryItem.getOldById(req.params.id)
|
||||
const item = await Database.libraryItemModel.getOldById(req.params.id)
|
||||
if (!item?.media) return res.sendStatus(404)
|
||||
|
||||
// Check user can access this library item
|
||||
|
@ -17,7 +17,7 @@ class UserController {
|
||||
const includes = (req.query.include || '').split(',').map(i => i.trim())
|
||||
|
||||
// Minimal toJSONForBrowser does not include mediaProgress and bookmarks
|
||||
const allUsers = await Database.models.user.getOldUsers()
|
||||
const allUsers = await Database.userModel.getOldUsers()
|
||||
const users = allUsers.map(u => u.toJSONForBrowser(hideRootToken, true))
|
||||
|
||||
if (includes.includes('latestSession')) {
|
||||
@ -47,20 +47,20 @@ class UserController {
|
||||
}
|
||||
|
||||
// Get user media progress with associated mediaItem
|
||||
const mediaProgresses = await Database.models.mediaProgress.findAll({
|
||||
const mediaProgresses = await Database.mediaProgressModel.findAll({
|
||||
where: {
|
||||
userId: req.reqUser.id
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Database.models.book,
|
||||
model: Database.bookModel,
|
||||
attributes: ['id', 'title', 'coverPath', 'updatedAt']
|
||||
},
|
||||
{
|
||||
model: Database.models.podcastEpisode,
|
||||
model: Database.podcastEpisodeModel,
|
||||
attributes: ['id', 'title'],
|
||||
include: {
|
||||
model: Database.models.podcast,
|
||||
model: Database.podcastModel,
|
||||
attributes: ['id', 'title', 'coverPath', 'updatedAt']
|
||||
}
|
||||
}
|
||||
@ -92,7 +92,7 @@ class UserController {
|
||||
const account = req.body
|
||||
const username = account.username
|
||||
|
||||
const usernameExists = await Database.models.user.getUserByUsername(username)
|
||||
const usernameExists = await Database.userModel.getUserByUsername(username)
|
||||
if (usernameExists) {
|
||||
return res.status(500).send('Username already taken')
|
||||
}
|
||||
@ -127,7 +127,7 @@ class UserController {
|
||||
var shouldUpdateToken = false
|
||||
|
||||
if (account.username !== undefined && account.username !== user.username) {
|
||||
const usernameExists = await Database.models.user.getUserByUsername(account.username)
|
||||
const usernameExists = await Database.userModel.getUserByUsername(account.username)
|
||||
if (usernameExists) {
|
||||
return res.status(500).send('Username already taken')
|
||||
}
|
||||
@ -169,7 +169,7 @@ class UserController {
|
||||
// Todo: check if user is logged in and cancel streams
|
||||
|
||||
// Remove user playlists
|
||||
const userPlaylists = await Database.models.playlist.findAll({
|
||||
const userPlaylists = await Database.playlistModel.findAll({
|
||||
where: {
|
||||
userId: user.id
|
||||
}
|
||||
@ -233,7 +233,7 @@ class UserController {
|
||||
}
|
||||
|
||||
if (req.params.id) {
|
||||
req.reqUser = await Database.models.user.getUserById(req.params.id)
|
||||
req.reqUser = await Database.userModel.getUserById(req.params.id)
|
||||
if (!req.reqUser) {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
|
@ -5,23 +5,23 @@ const { Sequelize } = require('sequelize')
|
||||
const Database = require('../Database')
|
||||
|
||||
const getLibraryItemMinified = (libraryItemId) => {
|
||||
return Database.models.libraryItem.findByPk(libraryItemId, {
|
||||
return Database.libraryItemModel.findByPk(libraryItemId, {
|
||||
include: [
|
||||
{
|
||||
model: Database.models.book,
|
||||
model: Database.bookModel,
|
||||
attributes: [
|
||||
'id', 'title', 'subtitle', 'publishedYear', 'publishedDate', 'publisher', 'description', 'isbn', 'asin', 'language', 'explicit', 'narrators', 'coverPath', 'genres', 'tags'
|
||||
],
|
||||
include: [
|
||||
{
|
||||
model: Database.models.author,
|
||||
model: Database.authorModel,
|
||||
attributes: ['id', 'name'],
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
},
|
||||
{
|
||||
model: Database.models.series,
|
||||
model: Database.seriesModel,
|
||||
attributes: ['id', 'name'],
|
||||
through: {
|
||||
attributes: ['sequence']
|
||||
@ -30,7 +30,7 @@ const getLibraryItemMinified = (libraryItemId) => {
|
||||
]
|
||||
},
|
||||
{
|
||||
model: Database.models.podcast,
|
||||
model: Database.podcastModel,
|
||||
attributes: [
|
||||
'id', 'title', 'author', 'releaseDate', 'feedURL', 'imageURL', 'description', 'itunesPageURL', 'itunesId', 'itunesArtistId', 'language', 'podcastType', 'explicit', 'autoDownloadEpisodes', 'genres', 'tags',
|
||||
[Sequelize.literal('(SELECT COUNT(*) FROM "podcastEpisodes" WHERE "podcastEpisodes"."podcastId" = podcast.id)'), 'numPodcastEpisodes']
|
||||
@ -41,19 +41,19 @@ const getLibraryItemMinified = (libraryItemId) => {
|
||||
}
|
||||
|
||||
const getLibraryItemExpanded = (libraryItemId) => {
|
||||
return Database.models.libraryItem.findByPk(libraryItemId, {
|
||||
return Database.libraryItemModel.findByPk(libraryItemId, {
|
||||
include: [
|
||||
{
|
||||
model: Database.models.book,
|
||||
model: Database.bookModel,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.author,
|
||||
model: Database.authorModel,
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
},
|
||||
{
|
||||
model: Database.models.series,
|
||||
model: Database.seriesModel,
|
||||
through: {
|
||||
attributes: ['sequence']
|
||||
}
|
||||
@ -61,10 +61,10 @@ const getLibraryItemExpanded = (libraryItemId) => {
|
||||
]
|
||||
},
|
||||
{
|
||||
model: Database.models.podcast,
|
||||
model: Database.podcastModel,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.podcastEpisode
|
||||
model: Database.podcastEpisodeModel
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -77,7 +77,7 @@ class CronManager {
|
||||
async initPodcastCrons() {
|
||||
const cronExpressionMap = {}
|
||||
|
||||
const podcastsWithAutoDownload = await Database.models.podcast.findAll({
|
||||
const podcastsWithAutoDownload = await Database.podcastModel.findAll({
|
||||
where: {
|
||||
autoDownloadEpisodes: true,
|
||||
autoDownloadSchedule: {
|
||||
@ -85,7 +85,7 @@ class CronManager {
|
||||
}
|
||||
},
|
||||
include: {
|
||||
model: Database.models.libraryItem
|
||||
model: Database.libraryItemModel
|
||||
}
|
||||
})
|
||||
|
||||
@ -139,7 +139,7 @@ class CronManager {
|
||||
// Get podcast library items to check
|
||||
const libraryItems = []
|
||||
for (const libraryItemId of libraryItemIds) {
|
||||
const libraryItem = await Database.models.libraryItem.getOldById(libraryItemId)
|
||||
const libraryItem = await Database.libraryItemModel.getOldById(libraryItemId)
|
||||
if (!libraryItem) {
|
||||
Logger.error(`[CronManager] Library item ${libraryItemId} not found for episode check cron ${expression}`)
|
||||
podcastCron.libraryItemIds = podcastCron.libraryItemIds.filter(lid => lid !== libraryItemId) // Filter it out
|
||||
|
@ -18,7 +18,7 @@ class NotificationManager {
|
||||
if (!Database.notificationSettings.isUseable) return
|
||||
|
||||
Logger.debug(`[NotificationManager] onPodcastEpisodeDownloaded: Episode "${episode.title}" for podcast ${libraryItem.media.metadata.title}`)
|
||||
const library = await Database.models.library.getOldById(libraryItem.libraryId)
|
||||
const library = await Database.libraryModel.getOldById(libraryItem.libraryId)
|
||||
const eventData = {
|
||||
libraryItemId: libraryItem.id,
|
||||
libraryId: libraryItem.libraryId,
|
||||
|
@ -265,7 +265,7 @@ class PlaybackSessionManager {
|
||||
}
|
||||
|
||||
async syncSession(user, session, syncData) {
|
||||
const libraryItem = await Database.models.libraryItem.getOldById(session.libraryItemId)
|
||||
const libraryItem = await Database.libraryItemModel.getOldById(session.libraryItemId)
|
||||
if (!libraryItem) {
|
||||
Logger.error(`[PlaybackSessionManager] syncSession Library Item not found "${session.libraryItemId}"`)
|
||||
return null
|
||||
|
@ -150,7 +150,7 @@ class PodcastManager {
|
||||
return false
|
||||
}
|
||||
|
||||
const libraryItem = await Database.models.libraryItem.getOldById(this.currentDownload.libraryItem.id)
|
||||
const libraryItem = await Database.libraryItemModel.getOldById(this.currentDownload.libraryItem.id)
|
||||
if (!libraryItem) {
|
||||
Logger.error(`[PodcastManager] Podcast Episode finished but library item was not found ${this.currentDownload.libraryItem.id}`)
|
||||
return false
|
||||
|
@ -13,13 +13,13 @@ class RssFeedManager {
|
||||
|
||||
async validateFeedEntity(feedObj) {
|
||||
if (feedObj.entityType === 'collection') {
|
||||
const collection = await Database.models.collection.getOldById(feedObj.entityId)
|
||||
const collection = await Database.collectionModel.getOldById(feedObj.entityId)
|
||||
if (!collection) {
|
||||
Logger.error(`[RssFeedManager] Removing feed "${feedObj.id}". Collection "${feedObj.entityId}" not found`)
|
||||
return false
|
||||
}
|
||||
} else if (feedObj.entityType === 'libraryItem') {
|
||||
const libraryItemExists = await Database.models.libraryItem.checkExistsById(feedObj.entityId)
|
||||
const libraryItemExists = await Database.libraryItemModel.checkExistsById(feedObj.entityId)
|
||||
if (!libraryItemExists) {
|
||||
Logger.error(`[RssFeedManager] Removing feed "${feedObj.id}". Library item "${feedObj.entityId}" not found`)
|
||||
return false
|
||||
@ -41,7 +41,7 @@ class RssFeedManager {
|
||||
* Validate all feeds and remove invalid
|
||||
*/
|
||||
async init() {
|
||||
const feeds = await Database.models.feed.getOldFeeds()
|
||||
const feeds = await Database.feedModel.getOldFeeds()
|
||||
for (const feed of feeds) {
|
||||
// Remove invalid feeds
|
||||
if (!await this.validateFeedEntity(feed)) {
|
||||
@ -56,7 +56,7 @@ class RssFeedManager {
|
||||
* @returns {Promise<objects.Feed>} oldFeed
|
||||
*/
|
||||
findFeedForEntityId(entityId) {
|
||||
return Database.models.feed.findOneOld({ entityId })
|
||||
return Database.feedModel.findOneOld({ entityId })
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,7 +65,7 @@ class RssFeedManager {
|
||||
* @returns {Promise<objects.Feed>} oldFeed
|
||||
*/
|
||||
findFeedBySlug(slug) {
|
||||
return Database.models.feed.findOneOld({ slug })
|
||||
return Database.feedModel.findOneOld({ slug })
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,7 +74,7 @@ class RssFeedManager {
|
||||
* @returns {Promise<objects.Feed>} oldFeed
|
||||
*/
|
||||
findFeed(id) {
|
||||
return Database.models.feed.findByPkOld(id)
|
||||
return Database.feedModel.findByPkOld(id)
|
||||
}
|
||||
|
||||
async getFeed(req, res) {
|
||||
@ -103,7 +103,7 @@ class RssFeedManager {
|
||||
await Database.updateFeed(feed)
|
||||
}
|
||||
} else if (feed.entityType === 'collection') {
|
||||
const collection = await Database.models.collection.findByPk(feed.entityId)
|
||||
const collection = await Database.collectionModel.findByPk(feed.entityId)
|
||||
if (collection) {
|
||||
const collectionExpanded = await collection.getOldJsonExpanded()
|
||||
|
||||
|
@ -359,7 +359,7 @@ class ApiRouter {
|
||||
*/
|
||||
async handleDeleteLibraryItem(mediaType, libraryItemId, mediaItemIds) {
|
||||
// Remove media progress for this library item from all users
|
||||
const users = await Database.models.user.getOldUsers()
|
||||
const users = await Database.userModel.getOldUsers()
|
||||
for (const user of users) {
|
||||
for (const mediaProgress of user.getAllMediaProgressForLibraryItem(libraryItemId)) {
|
||||
await Database.removeMediaProgress(mediaProgress.id)
|
||||
@ -371,14 +371,14 @@ class ApiRouter {
|
||||
// Remove series if empty
|
||||
if (mediaType === 'book') {
|
||||
// TODO: update filter data
|
||||
const bookSeries = await Database.models.bookSeries.findAll({
|
||||
const bookSeries = await Database.bookSeriesModel.findAll({
|
||||
where: {
|
||||
bookId: mediaItemIds[0]
|
||||
},
|
||||
include: {
|
||||
model: Database.models.series,
|
||||
model: Database.seriesModel,
|
||||
include: {
|
||||
model: Database.models.book
|
||||
model: Database.bookModel
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -390,7 +390,7 @@ class ApiRouter {
|
||||
}
|
||||
|
||||
// remove item from playlists
|
||||
const playlistsWithItem = await Database.models.playlist.getPlaylistsForMediaItemIds(mediaItemIds)
|
||||
const playlistsWithItem = await Database.playlistModel.getPlaylistsForMediaItemIds(mediaItemIds)
|
||||
for (const playlist of playlistsWithItem) {
|
||||
let numMediaItems = playlist.playlistMediaItems.length
|
||||
|
||||
@ -450,16 +450,16 @@ class ApiRouter {
|
||||
async checkRemoveEmptySeries(bookId, seriesIds) {
|
||||
if (!seriesIds?.length) return
|
||||
|
||||
const bookSeries = await Database.models.bookSeries.findAll({
|
||||
const bookSeries = await Database.bookSeriesModel.findAll({
|
||||
where: {
|
||||
bookId,
|
||||
seriesId: seriesIds
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Database.models.series,
|
||||
model: Database.seriesModel,
|
||||
include: {
|
||||
model: Database.models.book
|
||||
model: Database.bookModel
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -495,7 +495,7 @@ class ApiRouter {
|
||||
async getAllSessionsWithUserData() {
|
||||
const sessions = await Database.getPlaybackSessions()
|
||||
sessions.sort((a, b) => b.updatedAt - a.updatedAt)
|
||||
const minifiedUserObjects = await Database.models.user.getMinifiedUserObjects()
|
||||
const minifiedUserObjects = await Database.userModel.getMinifiedUserObjects()
|
||||
return sessions.map(se => {
|
||||
return {
|
||||
...se,
|
||||
|
@ -67,7 +67,7 @@ class Scanner {
|
||||
}
|
||||
|
||||
async scanLibraryItemByRequest(libraryItem) {
|
||||
const library = await Database.models.library.getOldById(libraryItem.libraryId)
|
||||
const library = await Database.libraryModel.getOldById(libraryItem.libraryId)
|
||||
if (!library) {
|
||||
Logger.error(`[Scanner] Scan libraryItem by id library not found "${libraryItem.libraryId}"`)
|
||||
return ScanResult.NOTHING
|
||||
@ -561,7 +561,7 @@ class Scanner {
|
||||
|
||||
for (const folderId in folderGroups) {
|
||||
const libraryId = folderGroups[folderId].libraryId
|
||||
const library = await Database.models.library.getOldById(libraryId)
|
||||
const library = await Database.libraryModel.getOldById(libraryId)
|
||||
if (!library) {
|
||||
Logger.error(`[Scanner] Library not found in files changed ${libraryId}`)
|
||||
continue
|
||||
@ -612,7 +612,7 @@ class Scanner {
|
||||
const altDir = `${itemDir}/${firstNest}`
|
||||
|
||||
const fullPath = Path.posix.join(filePathToPOSIX(folder.fullPath), itemDir)
|
||||
const childLibraryItem = await Database.models.libraryItem.findOne({
|
||||
const childLibraryItem = await Database.libraryItemModel.findOne({
|
||||
attributes: ['id', 'path'],
|
||||
where: {
|
||||
path: {
|
||||
@ -628,7 +628,7 @@ class Scanner {
|
||||
}
|
||||
|
||||
const altFullPath = Path.posix.join(filePathToPOSIX(folder.fullPath), altDir)
|
||||
const altChildLibraryItem = await Database.models.libraryItem.findOne({
|
||||
const altChildLibraryItem = await Database.libraryItemModel.findOne({
|
||||
attributes: ['id', 'path'],
|
||||
where: {
|
||||
path: {
|
||||
@ -661,12 +661,12 @@ class Scanner {
|
||||
}
|
||||
|
||||
// Check if book dir group is already an item
|
||||
let existingLibraryItem = await Database.models.libraryItem.findOneOld({
|
||||
let existingLibraryItem = await Database.libraryItemModel.findOneOld({
|
||||
path: potentialChildDirs
|
||||
})
|
||||
|
||||
if (!existingLibraryItem) {
|
||||
existingLibraryItem = await Database.models.libraryItem.findOneOld({
|
||||
existingLibraryItem = await Database.libraryItemModel.findOneOld({
|
||||
ino: dirIno
|
||||
})
|
||||
if (existingLibraryItem) {
|
||||
@ -701,7 +701,7 @@ class Scanner {
|
||||
}
|
||||
|
||||
// Check if a library item is a subdirectory of this dir
|
||||
const childItem = await Database.models.libraryItem.findOne({
|
||||
const childItem = await Database.libraryItemModel.findOne({
|
||||
attributes: ['id', 'path'],
|
||||
where: {
|
||||
path: {
|
||||
|
@ -71,7 +71,7 @@ module.exports = {
|
||||
} else if (filterBy === 'issues') {
|
||||
filtered = filtered.filter(li => li.hasIssues)
|
||||
} else if (filterBy === 'feed-open') {
|
||||
const libraryItemIdsWithFeed = await Database.models.feed.findAllLibraryItemIds()
|
||||
const libraryItemIdsWithFeed = await Database.feedModel.findAllLibraryItemIds()
|
||||
filtered = filtered.filter(li => libraryItemIdsWithFeed.includes(li.id))
|
||||
} else if (filterBy === 'abridged') {
|
||||
filtered = filtered.filter(li => !!li.media.metadata?.abridged)
|
||||
|
@ -52,9 +52,9 @@ module.exports = {
|
||||
const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'progress', 'in-progress', 'progress', true, false, include, limit, 0)
|
||||
return {
|
||||
items: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified()
|
||||
if (li.rssFeed) {
|
||||
oldLibraryItem.rssFeed = Database.models.feed.getOldFeed(li.rssFeed).toJSONMinified()
|
||||
oldLibraryItem.rssFeed = Database.feedModel.getOldFeed(li.rssFeed).toJSONMinified()
|
||||
}
|
||||
return oldLibraryItem
|
||||
}),
|
||||
@ -65,7 +65,7 @@ module.exports = {
|
||||
return {
|
||||
count,
|
||||
items: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified()
|
||||
oldLibraryItem.recentEpisode = li.recentEpisode
|
||||
return oldLibraryItem
|
||||
})
|
||||
@ -86,9 +86,9 @@ module.exports = {
|
||||
const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'recent', null, 'addedAt', true, false, include, limit, 0)
|
||||
return {
|
||||
libraryItems: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified()
|
||||
if (li.rssFeed) {
|
||||
oldLibraryItem.rssFeed = Database.models.feed.getOldFeed(li.rssFeed).toJSONMinified()
|
||||
oldLibraryItem.rssFeed = Database.feedModel.getOldFeed(li.rssFeed).toJSONMinified()
|
||||
}
|
||||
if (li.size && !oldLibraryItem.media.size) {
|
||||
oldLibraryItem.media.size = li.size
|
||||
@ -101,9 +101,9 @@ module.exports = {
|
||||
const { libraryItems, count } = await libraryItemsPodcastFilters.getFilteredLibraryItems(library.id, user, 'recent', null, 'addedAt', true, include, limit, 0)
|
||||
return {
|
||||
libraryItems: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified()
|
||||
if (li.rssFeed) {
|
||||
oldLibraryItem.rssFeed = Database.models.feed.getOldFeed(li.rssFeed).toJSONMinified()
|
||||
oldLibraryItem.rssFeed = Database.feedModel.getOldFeed(li.rssFeed).toJSONMinified()
|
||||
}
|
||||
if (li.size && !oldLibraryItem.media.size) {
|
||||
oldLibraryItem.media.size = li.size
|
||||
@ -127,9 +127,9 @@ module.exports = {
|
||||
const { libraryItems, count } = await libraryItemsBookFilters.getContinueSeriesLibraryItems(library.id, user, include, limit, 0)
|
||||
return {
|
||||
libraryItems: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified()
|
||||
if (li.rssFeed) {
|
||||
oldLibraryItem.rssFeed = Database.models.feed.getOldFeed(li.rssFeed).toJSONMinified()
|
||||
oldLibraryItem.rssFeed = Database.feedModel.getOldFeed(li.rssFeed).toJSONMinified()
|
||||
}
|
||||
if (li.series) {
|
||||
oldLibraryItem.media.metadata.series = li.series
|
||||
@ -153,9 +153,9 @@ module.exports = {
|
||||
const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'progress', 'finished', 'progress', true, false, include, limit, 0)
|
||||
return {
|
||||
items: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified()
|
||||
if (li.rssFeed) {
|
||||
oldLibraryItem.rssFeed = Database.models.feed.getOldFeed(li.rssFeed).toJSONMinified()
|
||||
oldLibraryItem.rssFeed = Database.feedModel.getOldFeed(li.rssFeed).toJSONMinified()
|
||||
}
|
||||
return oldLibraryItem
|
||||
}),
|
||||
@ -166,7 +166,7 @@ module.exports = {
|
||||
return {
|
||||
count,
|
||||
items: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified()
|
||||
oldLibraryItem.recentEpisode = li.recentEpisode
|
||||
return oldLibraryItem
|
||||
})
|
||||
@ -188,7 +188,7 @@ module.exports = {
|
||||
const seriesIncludes = []
|
||||
if (include.includes('rssfeed')) {
|
||||
seriesIncludes.push({
|
||||
model: Database.models.feed
|
||||
model: Database.feedModel
|
||||
})
|
||||
}
|
||||
|
||||
@ -230,12 +230,12 @@ module.exports = {
|
||||
replacements: userPermissionBookWhere.replacements,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.bookSeries,
|
||||
model: Database.bookSeriesModel,
|
||||
include: {
|
||||
model: Database.models.book,
|
||||
model: Database.bookModel,
|
||||
where: userPermissionBookWhere.bookWhere,
|
||||
include: {
|
||||
model: Database.models.libraryItem
|
||||
model: Database.libraryItemModel
|
||||
}
|
||||
},
|
||||
separate: true
|
||||
@ -252,7 +252,7 @@ module.exports = {
|
||||
const oldSeries = s.getOldSeries().toJSON()
|
||||
|
||||
if (s.feeds?.length) {
|
||||
oldSeries.rssFeed = Database.models.feed.getOldFeed(s.feeds[0]).toJSONMinified()
|
||||
oldSeries.rssFeed = Database.feedModel.getOldFeed(s.feeds[0]).toJSONMinified()
|
||||
}
|
||||
|
||||
// TODO: Sort books by sequence in query
|
||||
@ -268,7 +268,7 @@ module.exports = {
|
||||
const libraryItem = bs.book.libraryItem.toJSON()
|
||||
delete bs.book.libraryItem
|
||||
libraryItem.media = bs.book
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(libraryItem).toJSONMinified()
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(libraryItem).toJSONMinified()
|
||||
return oldLibraryItem
|
||||
})
|
||||
allOldSeries.push(oldSeries)
|
||||
@ -299,7 +299,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
include: {
|
||||
model: Database.models.bookAuthor,
|
||||
model: Database.bookAuthorModel,
|
||||
required: true // Must belong to a book
|
||||
},
|
||||
limit,
|
||||
@ -332,9 +332,9 @@ module.exports = {
|
||||
const { libraryItems, count } = await libraryItemsBookFilters.getDiscoverLibraryItems(library.id, user, include, limit)
|
||||
return {
|
||||
libraryItems: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified()
|
||||
if (li.rssFeed) {
|
||||
oldLibraryItem.rssFeed = Database.models.feed.getOldFeed(li.rssFeed).toJSONMinified()
|
||||
oldLibraryItem.rssFeed = Database.feedModel.getOldFeed(li.rssFeed).toJSONMinified()
|
||||
}
|
||||
return oldLibraryItem
|
||||
}),
|
||||
@ -356,7 +356,7 @@ module.exports = {
|
||||
return {
|
||||
count,
|
||||
libraryItems: libraryItems.map(li => {
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(li).toJSONMinified()
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified()
|
||||
oldLibraryItem.recentEpisode = li.recentEpisode
|
||||
return oldLibraryItem
|
||||
})
|
||||
@ -417,9 +417,9 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (oldLibrary.isPodcast) {
|
||||
const podcasts = await Database.models.podcast.findAll({
|
||||
const podcasts = await Database.podcastModel.findAll({
|
||||
include: {
|
||||
model: Database.models.libraryItem,
|
||||
model: Database.libraryItemModel,
|
||||
attributes: [],
|
||||
where: {
|
||||
libraryId: oldLibrary.id
|
||||
@ -436,9 +436,9 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const books = await Database.models.book.findAll({
|
||||
const books = await Database.bookModel.findAll({
|
||||
include: {
|
||||
model: Database.models.libraryItem,
|
||||
model: Database.libraryItemModel,
|
||||
attributes: ['isMissing', 'isInvalid'],
|
||||
where: {
|
||||
libraryId: oldLibrary.id
|
||||
|
@ -11,7 +11,7 @@ module.exports = {
|
||||
*/
|
||||
async getAllLibraryItemsWithTags(tags) {
|
||||
const libraryItems = []
|
||||
const booksWithTag = await Database.models.book.findAll({
|
||||
const booksWithTag = await Database.bookModel.findAll({
|
||||
where: Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM json_each(tags) WHERE json_valid(tags) AND json_each.value IN (:tags))`), {
|
||||
[Sequelize.Op.gte]: 1
|
||||
}),
|
||||
@ -20,16 +20,16 @@ module.exports = {
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem
|
||||
model: Database.libraryItemModel
|
||||
},
|
||||
{
|
||||
model: Database.models.author,
|
||||
model: Database.authorModel,
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
},
|
||||
{
|
||||
model: Database.models.series,
|
||||
model: Database.seriesModel,
|
||||
through: {
|
||||
attributes: ['sequence']
|
||||
}
|
||||
@ -41,7 +41,7 @@ module.exports = {
|
||||
libraryItem.media = book
|
||||
libraryItems.push(libraryItem)
|
||||
}
|
||||
const podcastsWithTag = await Database.models.podcast.findAll({
|
||||
const podcastsWithTag = await Database.podcastModel.findAll({
|
||||
where: Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM json_each(tags) WHERE json_valid(tags) AND json_each.value IN (:tags))`), {
|
||||
[Sequelize.Op.gte]: 1
|
||||
}),
|
||||
@ -50,10 +50,10 @@ module.exports = {
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem
|
||||
model: Database.libraryItemModel
|
||||
},
|
||||
{
|
||||
model: Database.models.podcastEpisode
|
||||
model: Database.podcastEpisodeModel
|
||||
}
|
||||
]
|
||||
})
|
||||
@ -72,7 +72,7 @@ module.exports = {
|
||||
*/
|
||||
async getAllLibraryItemsWithGenres(genres) {
|
||||
const libraryItems = []
|
||||
const booksWithGenre = await Database.models.book.findAll({
|
||||
const booksWithGenre = await Database.bookModel.findAll({
|
||||
where: Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM json_each(genres) WHERE json_valid(genres) AND json_each.value IN (:genres))`), {
|
||||
[Sequelize.Op.gte]: 1
|
||||
}),
|
||||
@ -81,16 +81,16 @@ module.exports = {
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem
|
||||
model: Database.libraryItemModel
|
||||
},
|
||||
{
|
||||
model: Database.models.author,
|
||||
model: Database.authorModel,
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
},
|
||||
{
|
||||
model: Database.models.series,
|
||||
model: Database.seriesModel,
|
||||
through: {
|
||||
attributes: ['sequence']
|
||||
}
|
||||
@ -102,7 +102,7 @@ module.exports = {
|
||||
libraryItem.media = book
|
||||
libraryItems.push(libraryItem)
|
||||
}
|
||||
const podcastsWithGenre = await Database.models.podcast.findAll({
|
||||
const podcastsWithGenre = await Database.podcastModel.findAll({
|
||||
where: Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM json_each(genres) WHERE json_valid(genres) AND json_each.value IN (:genres))`), {
|
||||
[Sequelize.Op.gte]: 1
|
||||
}),
|
||||
@ -111,10 +111,10 @@ module.exports = {
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem
|
||||
model: Database.libraryItemModel
|
||||
},
|
||||
{
|
||||
model: Database.models.podcastEpisode
|
||||
model: Database.podcastEpisodeModel
|
||||
}
|
||||
]
|
||||
})
|
||||
@ -133,7 +133,7 @@ module.exports = {
|
||||
*/
|
||||
async getAllLibraryItemsWithNarrators(narrators) {
|
||||
const libraryItems = []
|
||||
const booksWithGenre = await Database.models.book.findAll({
|
||||
const booksWithGenre = await Database.bookModel.findAll({
|
||||
where: Sequelize.where(Sequelize.literal(`(SELECT count(*) FROM json_each(narrators) WHERE json_valid(narrators) AND json_each.value IN (:narrators))`), {
|
||||
[Sequelize.Op.gte]: 1
|
||||
}),
|
||||
@ -142,16 +142,16 @@ module.exports = {
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem
|
||||
model: Database.libraryItemModel
|
||||
},
|
||||
{
|
||||
model: Database.models.author,
|
||||
model: Database.authorModel,
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
},
|
||||
{
|
||||
model: Database.models.series,
|
||||
model: Database.seriesModel,
|
||||
through: {
|
||||
attributes: ['sequence']
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ module.exports = {
|
||||
where: seriesWhere,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.book,
|
||||
model: Database.bookModel,
|
||||
attributes: ['id', 'title'],
|
||||
through: {
|
||||
attributes: ['id', 'seriesId', 'bookId', 'sequence']
|
||||
@ -374,10 +374,10 @@ module.exports = {
|
||||
}
|
||||
|
||||
let seriesInclude = {
|
||||
model: Database.models.bookSeries,
|
||||
model: Database.bookSeriesModel,
|
||||
attributes: ['id', 'seriesId', 'sequence', 'createdAt'],
|
||||
include: {
|
||||
model: Database.models.series,
|
||||
model: Database.seriesModel,
|
||||
attributes: ['id', 'name', 'nameIgnorePrefix']
|
||||
},
|
||||
order: [
|
||||
@ -387,10 +387,10 @@ module.exports = {
|
||||
}
|
||||
|
||||
let authorInclude = {
|
||||
model: Database.models.bookAuthor,
|
||||
model: Database.bookAuthorModel,
|
||||
attributes: ['authorId', 'createdAt'],
|
||||
include: {
|
||||
model: Database.models.author,
|
||||
model: Database.authorModel,
|
||||
attributes: ['id', 'name']
|
||||
},
|
||||
order: [
|
||||
@ -405,13 +405,13 @@ module.exports = {
|
||||
const bookIncludes = []
|
||||
if (includeRSSFeed) {
|
||||
libraryItemIncludes.push({
|
||||
model: Database.models.feed,
|
||||
model: Database.feedModel,
|
||||
required: filterGroup === 'feed-open'
|
||||
})
|
||||
}
|
||||
if (filterGroup === 'feed-open' && !includeRSSFeed) {
|
||||
libraryItemIncludes.push({
|
||||
model: Database.models.feed,
|
||||
model: Database.feedModel,
|
||||
required: true
|
||||
})
|
||||
} else if (filterGroup === 'ebooks' && filterValue === 'supplementary') {
|
||||
@ -421,7 +421,7 @@ module.exports = {
|
||||
}
|
||||
} else if (filterGroup === 'missing' && filterValue === 'authors') {
|
||||
authorInclude = {
|
||||
model: Database.models.author,
|
||||
model: Database.authorModel,
|
||||
attributes: ['id'],
|
||||
through: {
|
||||
attributes: []
|
||||
@ -429,7 +429,7 @@ module.exports = {
|
||||
}
|
||||
} else if ((filterGroup === 'series' && filterValue === 'no-series') || (filterGroup === 'missing' && filterValue === 'series')) {
|
||||
seriesInclude = {
|
||||
model: Database.models.series,
|
||||
model: Database.seriesModel,
|
||||
attributes: ['id'],
|
||||
through: {
|
||||
attributes: []
|
||||
@ -437,7 +437,7 @@ module.exports = {
|
||||
}
|
||||
} else if (filterGroup === 'authors') {
|
||||
bookIncludes.push({
|
||||
model: Database.models.author,
|
||||
model: Database.authorModel,
|
||||
attributes: ['id', 'name'],
|
||||
where: {
|
||||
id: filterValue
|
||||
@ -448,7 +448,7 @@ module.exports = {
|
||||
})
|
||||
} else if (filterGroup === 'series') {
|
||||
bookIncludes.push({
|
||||
model: Database.models.series,
|
||||
model: Database.seriesModel,
|
||||
attributes: ['id', 'name'],
|
||||
where: {
|
||||
id: filterValue
|
||||
@ -472,7 +472,7 @@ module.exports = {
|
||||
]
|
||||
} else if (filterGroup === 'progress' && user) {
|
||||
bookIncludes.push({
|
||||
model: Database.models.mediaProgress,
|
||||
model: Database.mediaProgressModel,
|
||||
attributes: ['id', 'isFinished', 'currentTime', 'ebookProgress', 'updatedAt'],
|
||||
where: {
|
||||
userId: user.id
|
||||
@ -513,7 +513,7 @@ module.exports = {
|
||||
where: seriesBookWhere,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem,
|
||||
model: Database.libraryItemModel,
|
||||
required: true,
|
||||
where: libraryItemWhere,
|
||||
include: libraryItemIncludes
|
||||
@ -542,7 +542,7 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
const { rows: books, count } = await Database.models.book.findAndCountAll({
|
||||
const { rows: books, count } = await Database.bookModel.findAndCountAll({
|
||||
where: bookWhere,
|
||||
distinct: true,
|
||||
attributes: bookAttributes,
|
||||
@ -553,7 +553,7 @@ module.exports = {
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem,
|
||||
model: Database.libraryItemModel,
|
||||
required: true,
|
||||
where: libraryItemWhere,
|
||||
include: libraryItemIncludes
|
||||
@ -633,7 +633,7 @@ module.exports = {
|
||||
const libraryItemIncludes = []
|
||||
if (include.includes('rssfeed')) {
|
||||
libraryItemIncludes.push({
|
||||
model: Database.models.feed
|
||||
model: Database.feedModel
|
||||
})
|
||||
}
|
||||
|
||||
@ -670,7 +670,7 @@ module.exports = {
|
||||
...userPermissionBookWhere.replacements
|
||||
},
|
||||
include: {
|
||||
model: Database.models.bookSeries,
|
||||
model: Database.bookSeriesModel,
|
||||
attributes: ['bookId', 'sequence'],
|
||||
separate: true,
|
||||
subQuery: false,
|
||||
@ -683,21 +683,21 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
include: {
|
||||
model: Database.models.book,
|
||||
model: Database.bookModel,
|
||||
where: bookWhere,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem,
|
||||
model: Database.libraryItemModel,
|
||||
include: libraryItemIncludes
|
||||
},
|
||||
{
|
||||
model: Database.models.author,
|
||||
model: Database.authorModel,
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
},
|
||||
{
|
||||
model: Database.models.mediaProgress,
|
||||
model: Database.mediaProgressModel,
|
||||
where: {
|
||||
userId: user.id
|
||||
},
|
||||
@ -765,12 +765,12 @@ module.exports = {
|
||||
},
|
||||
attributes: ['id'],
|
||||
include: {
|
||||
model: Database.models.bookSeries,
|
||||
model: Database.bookSeriesModel,
|
||||
attributes: ['bookId', 'sequence'],
|
||||
separate: true,
|
||||
required: true,
|
||||
include: {
|
||||
model: Database.models.book,
|
||||
model: Database.bookModel,
|
||||
where: userPermissionBookWhere.bookWhere
|
||||
},
|
||||
order: [
|
||||
@ -789,12 +789,12 @@ module.exports = {
|
||||
const libraryItemIncludes = []
|
||||
if (include.includes('rssfeed')) {
|
||||
libraryItemIncludes.push({
|
||||
model: Database.models.feed
|
||||
model: Database.feedModel
|
||||
})
|
||||
}
|
||||
|
||||
// Step 2: Get books not started and not in a series OR is the first book of a series not started (ordered randomly)
|
||||
const { rows: books, count } = await Database.models.book.findAndCountAll({
|
||||
const { rows: books, count } = await Database.bookModel.findAndCountAll({
|
||||
where: [
|
||||
{
|
||||
'$mediaProgresses.isFinished$': {
|
||||
@ -817,32 +817,32 @@ module.exports = {
|
||||
replacements: userPermissionBookWhere.replacements,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem,
|
||||
model: Database.libraryItemModel,
|
||||
where: {
|
||||
libraryId
|
||||
},
|
||||
include: libraryItemIncludes
|
||||
},
|
||||
{
|
||||
model: Database.models.mediaProgress,
|
||||
model: Database.mediaProgressModel,
|
||||
where: {
|
||||
userId: user.id
|
||||
},
|
||||
required: false
|
||||
},
|
||||
{
|
||||
model: Database.models.bookAuthor,
|
||||
model: Database.bookAuthorModel,
|
||||
attributes: ['authorId'],
|
||||
include: {
|
||||
model: Database.models.author
|
||||
model: Database.authorModel
|
||||
},
|
||||
separate: true
|
||||
},
|
||||
{
|
||||
model: Database.models.bookSeries,
|
||||
model: Database.bookSeriesModel,
|
||||
attributes: ['seriesId', 'sequence'],
|
||||
include: {
|
||||
model: Database.models.series
|
||||
model: Database.seriesModel
|
||||
},
|
||||
separate: true
|
||||
}
|
||||
@ -884,10 +884,10 @@ module.exports = {
|
||||
return []
|
||||
}
|
||||
|
||||
const books = await Database.models.book.findAll({
|
||||
const books = await Database.bookModel.findAll({
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem,
|
||||
model: Database.libraryItemModel,
|
||||
where: {
|
||||
id: {
|
||||
[Sequelize.Op.in]: collection.books
|
||||
@ -895,13 +895,13 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
{
|
||||
model: Database.models.author,
|
||||
model: Database.authorModel,
|
||||
through: {
|
||||
attributes: []
|
||||
}
|
||||
},
|
||||
{
|
||||
model: Database.models.series,
|
||||
model: Database.seriesModel,
|
||||
through: {
|
||||
attributes: ['sequence']
|
||||
}
|
||||
@ -925,7 +925,7 @@ module.exports = {
|
||||
*/
|
||||
async getLibraryItemsForSeries(oldSeries, oldUser) {
|
||||
const { libraryItems } = await this.getFilteredLibraryItems(oldSeries.libraryId, oldUser, 'series', oldSeries.id, null, null, false, [], null, null)
|
||||
return libraryItems.map(li => Database.models.libraryItem.getOldLibraryItem(li))
|
||||
return libraryItems.map(li => Database.libraryItemModel.getOldLibraryItem(li))
|
||||
},
|
||||
|
||||
/**
|
||||
@ -978,14 +978,14 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
{
|
||||
model: Database.models.bookSeries,
|
||||
model: Database.bookSeriesModel,
|
||||
include: {
|
||||
model: Database.seriesModel
|
||||
},
|
||||
separate: true
|
||||
},
|
||||
{
|
||||
model: Database.models.bookAuthor,
|
||||
model: Database.bookAuthorModel,
|
||||
include: {
|
||||
model: Database.authorModel
|
||||
},
|
||||
@ -1071,7 +1071,7 @@ module.exports = {
|
||||
replacements: userPermissionBookWhere.replacements,
|
||||
include: {
|
||||
separate: true,
|
||||
model: Database.models.bookSeries,
|
||||
model: Database.bookSeriesModel,
|
||||
include: {
|
||||
model: Database.bookModel,
|
||||
where: userPermissionBookWhere.bookWhere,
|
||||
|
@ -112,7 +112,7 @@ module.exports = {
|
||||
const libraryItemIncludes = []
|
||||
if (includeRSSFeed) {
|
||||
libraryItemIncludes.push({
|
||||
model: Database.models.feed,
|
||||
model: Database.feedModel,
|
||||
required: filterGroup === 'feed-open'
|
||||
})
|
||||
}
|
||||
@ -146,7 +146,7 @@ module.exports = {
|
||||
replacements = { ...replacements, ...userPermissionPodcastWhere.replacements }
|
||||
podcastWhere.push(...userPermissionPodcastWhere.podcastWhere)
|
||||
|
||||
const { rows: podcasts, count } = await Database.models.podcast.findAndCountAll({
|
||||
const { rows: podcasts, count } = await Database.podcastModel.findAndCountAll({
|
||||
where: podcastWhere,
|
||||
replacements,
|
||||
distinct: true,
|
||||
@ -158,7 +158,7 @@ module.exports = {
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem,
|
||||
model: Database.libraryItemModel,
|
||||
required: true,
|
||||
where: libraryItemWhere,
|
||||
include: libraryItemIncludes
|
||||
@ -219,7 +219,7 @@ module.exports = {
|
||||
}
|
||||
if (filterGroup === 'progress') {
|
||||
podcastEpisodeIncludes.push({
|
||||
model: Database.models.mediaProgress,
|
||||
model: Database.mediaProgressModel,
|
||||
where: {
|
||||
userId: user.id
|
||||
},
|
||||
@ -255,16 +255,16 @@ module.exports = {
|
||||
|
||||
const userPermissionPodcastWhere = this.getUserPermissionPodcastWhereQuery(user)
|
||||
|
||||
const { rows: podcastEpisodes, count } = await Database.models.podcastEpisode.findAndCountAll({
|
||||
const { rows: podcastEpisodes, count } = await Database.podcastEpisodeModel.findAndCountAll({
|
||||
where: podcastEpisodeWhere,
|
||||
replacements: userPermissionPodcastWhere.replacements,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.podcast,
|
||||
model: Database.podcastModel,
|
||||
where: userPermissionPodcastWhere.podcastWhere,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem,
|
||||
model: Database.libraryItemModel,
|
||||
where: libraryItemWhere
|
||||
}
|
||||
]
|
||||
|
@ -34,7 +34,7 @@ module.exports = {
|
||||
const seriesIncludes = []
|
||||
if (include.includes('rssfeed')) {
|
||||
seriesIncludes.push({
|
||||
model: Database.models.feed
|
||||
model: Database.feedModel
|
||||
})
|
||||
}
|
||||
|
||||
@ -149,13 +149,13 @@ module.exports = {
|
||||
replacements: userPermissionBookWhere.replacements,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.bookSeries,
|
||||
model: Database.bookSeriesModel,
|
||||
include: {
|
||||
model: Database.models.book,
|
||||
model: Database.bookModel,
|
||||
where: userPermissionBookWhere.bookWhere,
|
||||
include: [
|
||||
{
|
||||
model: Database.models.libraryItem
|
||||
model: Database.libraryItemModel
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -176,7 +176,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (s.feeds?.length) {
|
||||
oldSeries.rssFeed = Database.models.feed.getOldFeed(s.feeds[0]).toJSONMinified()
|
||||
oldSeries.rssFeed = Database.feedModel.getOldFeed(s.feeds[0]).toJSONMinified()
|
||||
}
|
||||
|
||||
// TODO: Sort books by sequence in query
|
||||
@ -192,7 +192,7 @@ module.exports = {
|
||||
const libraryItem = bs.book.libraryItem.toJSON()
|
||||
delete bs.book.libraryItem
|
||||
libraryItem.media = bs.book
|
||||
const oldLibraryItem = Database.models.libraryItem.getOldLibraryItem(libraryItem).toJSONMinified()
|
||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(libraryItem).toJSONMinified()
|
||||
return oldLibraryItem
|
||||
})
|
||||
allOldSeries.push(oldSeries)
|
||||
|
Loading…
Reference in New Issue
Block a user