mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-19 01:15:23 +02:00
Remove unused functions, jsdoc updates, auto-formatting
This commit is contained in:
parent
964ef910b6
commit
3fd290c518
@ -26,11 +26,6 @@ class Author extends Model {
|
|||||||
this.createdAt
|
this.createdAt
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getOldAuthors() {
|
|
||||||
const authors = await this.findAll()
|
|
||||||
return authors.map(au => au.getOldAuthor())
|
|
||||||
}
|
|
||||||
|
|
||||||
getOldAuthor() {
|
getOldAuthor() {
|
||||||
return new oldAuthor({
|
return new oldAuthor({
|
||||||
id: this.id,
|
id: this.id,
|
||||||
@ -112,14 +107,16 @@ class Author extends Model {
|
|||||||
* @returns {Promise<oldAuthor>}
|
* @returns {Promise<oldAuthor>}
|
||||||
*/
|
*/
|
||||||
static async getOldByNameAndLibrary(authorName, libraryId) {
|
static async getOldByNameAndLibrary(authorName, libraryId) {
|
||||||
const author = (await this.findOne({
|
const author = (
|
||||||
|
await this.findOne({
|
||||||
where: [
|
where: [
|
||||||
where(fn('lower', col('name')), authorName.toLowerCase()),
|
where(fn('lower', col('name')), authorName.toLowerCase()),
|
||||||
{
|
{
|
||||||
libraryId
|
libraryId
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}))?.getOldAuthor()
|
})
|
||||||
|
)?.getOldAuthor()
|
||||||
return author
|
return author
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +125,8 @@ class Author extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -139,15 +137,18 @@ class Author extends Model {
|
|||||||
asin: DataTypes.STRING,
|
asin: DataTypes.STRING,
|
||||||
description: DataTypes.TEXT,
|
description: DataTypes.TEXT,
|
||||||
imagePath: DataTypes.STRING
|
imagePath: DataTypes.STRING
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'author',
|
modelName: 'author',
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
fields: [{
|
fields: [
|
||||||
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
collate: 'NOCASE'
|
collate: 'NOCASE'
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// fields: [{
|
// fields: [{
|
||||||
@ -159,7 +160,8 @@ class Author extends Model {
|
|||||||
fields: ['libraryId']
|
fields: ['libraryId']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const { library } = sequelize.models
|
const { library } = sequelize.models
|
||||||
library.hasMany(Author, {
|
library.hasMany(Author, {
|
||||||
|
@ -112,14 +112,15 @@ class Book extends Model {
|
|||||||
const bookExpanded = libraryItemExpanded.media
|
const bookExpanded = libraryItemExpanded.media
|
||||||
let authors = []
|
let authors = []
|
||||||
if (bookExpanded.authors?.length) {
|
if (bookExpanded.authors?.length) {
|
||||||
authors = bookExpanded.authors.map(au => {
|
authors = bookExpanded.authors.map((au) => {
|
||||||
return {
|
return {
|
||||||
id: au.id,
|
id: au.id,
|
||||||
name: au.name
|
name: au.name
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (bookExpanded.bookAuthors?.length) {
|
} else if (bookExpanded.bookAuthors?.length) {
|
||||||
authors = bookExpanded.bookAuthors.map(ba => {
|
authors = bookExpanded.bookAuthors
|
||||||
|
.map((ba) => {
|
||||||
if (ba.author) {
|
if (ba.author) {
|
||||||
return {
|
return {
|
||||||
id: ba.author.id,
|
id: ba.author.id,
|
||||||
@ -129,12 +130,13 @@ class Book extends Model {
|
|||||||
Logger.error(`[Book] Invalid bookExpanded bookAuthors: no author`, ba)
|
Logger.error(`[Book] Invalid bookExpanded bookAuthors: no author`, ba)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}).filter(a => a)
|
})
|
||||||
|
.filter((a) => a)
|
||||||
}
|
}
|
||||||
|
|
||||||
let series = []
|
let series = []
|
||||||
if (bookExpanded.series?.length) {
|
if (bookExpanded.series?.length) {
|
||||||
series = bookExpanded.series.map(se => {
|
series = bookExpanded.series.map((se) => {
|
||||||
return {
|
return {
|
||||||
id: se.id,
|
id: se.id,
|
||||||
name: se.name,
|
name: se.name,
|
||||||
@ -142,7 +144,8 @@ class Book extends Model {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (bookExpanded.bookSeries?.length) {
|
} else if (bookExpanded.bookSeries?.length) {
|
||||||
series = bookExpanded.bookSeries.map(bs => {
|
series = bookExpanded.bookSeries
|
||||||
|
.map((bs) => {
|
||||||
if (bs.series) {
|
if (bs.series) {
|
||||||
return {
|
return {
|
||||||
id: bs.series.id,
|
id: bs.series.id,
|
||||||
@ -153,7 +156,8 @@ class Book extends Model {
|
|||||||
Logger.error(`[Book] Invalid bookExpanded bookSeries: no series`, bs)
|
Logger.error(`[Book] Invalid bookExpanded bookSeries: no series`, bs)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}).filter(s => s)
|
})
|
||||||
|
.filter((s) => s)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -194,7 +198,9 @@ class Book extends Model {
|
|||||||
where: {
|
where: {
|
||||||
id: book.id
|
id: book.id
|
||||||
}
|
}
|
||||||
}).then(result => result[0] > 0).catch((error) => {
|
})
|
||||||
|
.then((result) => result[0] > 0)
|
||||||
|
.catch((error) => {
|
||||||
Logger.error(`[Book] Failed to save book ${book.id}`, error)
|
Logger.error(`[Book] Failed to save book ${book.id}`, error)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
@ -219,7 +225,7 @@ class Book extends Model {
|
|||||||
ebookFile: oldBook.ebookFile?.toJSON() || null,
|
ebookFile: oldBook.ebookFile?.toJSON() || null,
|
||||||
coverPath: oldBook.coverPath,
|
coverPath: oldBook.coverPath,
|
||||||
duration: oldBook.duration,
|
duration: oldBook.duration,
|
||||||
audioFiles: oldBook.audioFiles?.map(af => af.toJSON()) || [],
|
audioFiles: oldBook.audioFiles?.map((af) => af.toJSON()) || [],
|
||||||
chapters: oldBook.chapters,
|
chapters: oldBook.chapters,
|
||||||
tags: oldBook.tags,
|
tags: oldBook.tags,
|
||||||
genres: oldBook.metadata.genres
|
genres: oldBook.metadata.genres
|
||||||
@ -229,12 +235,12 @@ class Book extends Model {
|
|||||||
getAbsMetadataJson() {
|
getAbsMetadataJson() {
|
||||||
return {
|
return {
|
||||||
tags: this.tags || [],
|
tags: this.tags || [],
|
||||||
chapters: this.chapters?.map(c => ({ ...c })) || [],
|
chapters: this.chapters?.map((c) => ({ ...c })) || [],
|
||||||
title: this.title,
|
title: this.title,
|
||||||
subtitle: this.subtitle,
|
subtitle: this.subtitle,
|
||||||
authors: this.authors.map(a => a.name),
|
authors: this.authors.map((a) => a.name),
|
||||||
narrators: this.narrators,
|
narrators: this.narrators,
|
||||||
series: this.series.map(se => {
|
series: this.series.map((se) => {
|
||||||
const sequence = se.bookSeries?.sequence || ''
|
const sequence = se.bookSeries?.sequence || ''
|
||||||
if (!sequence) return se.name
|
if (!sequence) return se.name
|
||||||
return `${se.name} #${sequence}`
|
return `${se.name} #${sequence}`
|
||||||
@ -257,7 +263,8 @@ class Book extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -284,15 +291,18 @@ class Book extends Model {
|
|||||||
chapters: DataTypes.JSON,
|
chapters: DataTypes.JSON,
|
||||||
tags: DataTypes.JSON,
|
tags: DataTypes.JSON,
|
||||||
genres: DataTypes.JSON
|
genres: DataTypes.JSON
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'book',
|
modelName: 'book',
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
fields: [{
|
fields: [
|
||||||
|
{
|
||||||
name: 'title',
|
name: 'title',
|
||||||
collate: 'NOCASE'
|
collate: 'NOCASE'
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// fields: [{
|
// fields: [{
|
||||||
@ -302,12 +312,13 @@ class Book extends Model {
|
|||||||
// },
|
// },
|
||||||
{
|
{
|
||||||
fields: ['publishedYear']
|
fields: ['publishedYear']
|
||||||
},
|
}
|
||||||
// {
|
// {
|
||||||
// fields: ['duration']
|
// fields: ['duration']
|
||||||
// }
|
// }
|
||||||
]
|
]
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,18 +28,21 @@ class BookAuthor extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
primaryKey: true
|
primaryKey: true
|
||||||
}
|
}
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'bookAuthor',
|
modelName: 'bookAuthor',
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
updatedAt: false
|
updatedAt: false
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// Super Many-to-Many
|
// Super Many-to-Many
|
||||||
// ref: https://sequelize.org/docs/v6/advanced-association-concepts/advanced-many-to-many/#the-best-of-both-worlds-the-super-many-to-many-relationship
|
// ref: https://sequelize.org/docs/v6/advanced-association-concepts/advanced-many-to-many/#the-best-of-both-worlds-the-super-many-to-many-relationship
|
||||||
|
@ -30,19 +30,22 @@ class BookSeries extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
primaryKey: true
|
primaryKey: true
|
||||||
},
|
},
|
||||||
sequence: DataTypes.STRING
|
sequence: DataTypes.STRING
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'bookSeries',
|
modelName: 'bookSeries',
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
updatedAt: false
|
updatedAt: false
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// Super Many-to-Many
|
// Super Many-to-Many
|
||||||
// ref: https://sequelize.org/docs/v6/advanced-association-concepts/advanced-many-to-many/#the-best-of-both-worlds-the-super-many-to-many-relationship
|
// ref: https://sequelize.org/docs/v6/advanced-association-concepts/advanced-many-to-many/#the-best-of-both-worlds-the-super-many-to-many-relationship
|
||||||
|
@ -2,7 +2,6 @@ const { DataTypes, Model, Sequelize } = require('sequelize')
|
|||||||
|
|
||||||
const oldCollection = require('../objects/Collection')
|
const oldCollection = require('../objects/Collection')
|
||||||
|
|
||||||
|
|
||||||
class Collection extends Model {
|
class Collection extends Model {
|
||||||
constructor(values, options) {
|
constructor(values, options) {
|
||||||
super(values, options)
|
super(values, options)
|
||||||
@ -20,27 +19,13 @@ class Collection extends Model {
|
|||||||
/** @type {Date} */
|
/** @type {Date} */
|
||||||
this.createdAt
|
this.createdAt
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Get all old collections
|
|
||||||
* @returns {Promise<oldCollection[]>}
|
|
||||||
*/
|
|
||||||
static async getOldCollections() {
|
|
||||||
const collections = await this.findAll({
|
|
||||||
include: {
|
|
||||||
model: this.sequelize.models.book,
|
|
||||||
include: this.sequelize.models.libraryItem
|
|
||||||
},
|
|
||||||
order: [[this.sequelize.models.book, this.sequelize.models.collectionBook, 'order', 'ASC']]
|
|
||||||
})
|
|
||||||
return collections.map(c => this.getOldCollection(c))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all old collections toJSONExpanded, items filtered for user permissions
|
* Get all old collections toJSONExpanded, items filtered for user permissions
|
||||||
* @param {[oldUser]} user
|
* @param {oldUser} [user]
|
||||||
* @param {[string]} libraryId
|
* @param {string} [libraryId]
|
||||||
* @param {[string[]]} include
|
* @param {string[]} [include]
|
||||||
* @returns {Promise<object[]>} oldCollection.toJSONExpanded
|
* @returns {Promise<oldCollection[]>} oldCollection.toJSONExpanded
|
||||||
*/
|
*/
|
||||||
static async getOldCollectionsJsonExpanded(user, libraryId, include) {
|
static async getOldCollectionsJsonExpanded(user, libraryId, include) {
|
||||||
let collectionWhere = null
|
let collectionWhere = null
|
||||||
@ -78,8 +63,7 @@ class Collection extends Model {
|
|||||||
through: {
|
through: {
|
||||||
attributes: ['sequence']
|
attributes: ['sequence']
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
...collectionIncludes
|
...collectionIncludes
|
||||||
@ -87,11 +71,13 @@ class Collection extends Model {
|
|||||||
order: [[this.sequelize.models.book, this.sequelize.models.collectionBook, 'order', 'ASC']]
|
order: [[this.sequelize.models.book, this.sequelize.models.collectionBook, 'order', 'ASC']]
|
||||||
})
|
})
|
||||||
// TODO: Handle user permission restrictions on initial query
|
// TODO: Handle user permission restrictions on initial query
|
||||||
return collections.map(c => {
|
return collections
|
||||||
|
.map((c) => {
|
||||||
const oldCollection = this.getOldCollection(c)
|
const oldCollection = this.getOldCollection(c)
|
||||||
|
|
||||||
// Filter books using user permissions
|
// Filter books using user permissions
|
||||||
const books = c.books?.filter(b => {
|
const books =
|
||||||
|
c.books?.filter((b) => {
|
||||||
if (user) {
|
if (user) {
|
||||||
if (b.tags?.length && !user.checkCanAccessLibraryItemWithTags(b.tags)) {
|
if (b.tags?.length && !user.checkCanAccessLibraryItemWithTags(b.tags)) {
|
||||||
return false
|
return false
|
||||||
@ -104,7 +90,7 @@ class Collection extends Model {
|
|||||||
}) || []
|
}) || []
|
||||||
|
|
||||||
// Map to library items
|
// Map to library items
|
||||||
const libraryItems = books.map(b => {
|
const libraryItems = books.map((b) => {
|
||||||
const libraryItem = b.libraryItem
|
const libraryItem = b.libraryItem
|
||||||
delete b.libraryItem
|
delete b.libraryItem
|
||||||
libraryItem.media = b
|
libraryItem.media = b
|
||||||
@ -124,17 +110,19 @@ class Collection extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return collectionExpanded
|
return collectionExpanded
|
||||||
}).filter(c => c)
|
})
|
||||||
|
.filter((c) => c)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get old collection toJSONExpanded, items filtered for user permissions
|
* Get old collection toJSONExpanded, items filtered for user permissions
|
||||||
* @param {[oldUser]} user
|
* @param {oldUser} [user]
|
||||||
* @param {[string[]]} include
|
* @param {string[]} [include]
|
||||||
* @returns {Promise<object>} oldCollection.toJSONExpanded
|
* @returns {Promise<oldCollection>} oldCollection.toJSONExpanded
|
||||||
*/
|
*/
|
||||||
async getOldJsonExpanded(user, include) {
|
async getOldJsonExpanded(user, include) {
|
||||||
this.books = await this.getBooks({
|
this.books =
|
||||||
|
(await this.getBooks({
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: this.sequelize.models.libraryItem
|
model: this.sequelize.models.libraryItem
|
||||||
@ -150,17 +138,17 @@ class Collection extends Model {
|
|||||||
through: {
|
through: {
|
||||||
attributes: ['sequence']
|
attributes: ['sequence']
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
],
|
],
|
||||||
order: [Sequelize.literal('`collectionBook.order` ASC')]
|
order: [Sequelize.literal('`collectionBook.order` ASC')]
|
||||||
}) || []
|
})) || []
|
||||||
|
|
||||||
const oldCollection = this.sequelize.models.collection.getOldCollection(this)
|
const oldCollection = this.sequelize.models.collection.getOldCollection(this)
|
||||||
|
|
||||||
// Filter books using user permissions
|
// Filter books using user permissions
|
||||||
// TODO: Handle user permission restrictions on initial query
|
// TODO: Handle user permission restrictions on initial query
|
||||||
const books = this.books?.filter(b => {
|
const books =
|
||||||
|
this.books?.filter((b) => {
|
||||||
if (user) {
|
if (user) {
|
||||||
if (b.tags?.length && !user.checkCanAccessLibraryItemWithTags(b.tags)) {
|
if (b.tags?.length && !user.checkCanAccessLibraryItemWithTags(b.tags)) {
|
||||||
return false
|
return false
|
||||||
@ -173,7 +161,7 @@ class Collection extends Model {
|
|||||||
}) || []
|
}) || []
|
||||||
|
|
||||||
// Map to library items
|
// Map to library items
|
||||||
const libraryItems = books.map(b => {
|
const libraryItems = books.map((b) => {
|
||||||
const libraryItem = b.libraryItem
|
const libraryItem = b.libraryItem
|
||||||
delete b.libraryItem
|
delete b.libraryItem
|
||||||
libraryItem.media = b
|
libraryItem.media = b
|
||||||
@ -203,7 +191,7 @@ class Collection extends Model {
|
|||||||
* @returns {oldCollection}
|
* @returns {oldCollection}
|
||||||
*/
|
*/
|
||||||
static getOldCollection(collectionExpanded) {
|
static getOldCollection(collectionExpanded) {
|
||||||
const libraryItemIds = collectionExpanded.books?.map(b => b.libraryItem?.id || null).filter(lid => lid) || []
|
const libraryItemIds = collectionExpanded.books?.map((b) => b.libraryItem?.id || null).filter((lid) => lid) || []
|
||||||
return new oldCollection({
|
return new oldCollection({
|
||||||
id: collectionExpanded.id,
|
id: collectionExpanded.id,
|
||||||
libraryId: collectionExpanded.libraryId,
|
libraryId: collectionExpanded.libraryId,
|
||||||
@ -215,6 +203,11 @@ class Collection extends Model {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {oldCollection} oldCollection
|
||||||
|
* @returns {Promise<Collection>}
|
||||||
|
*/
|
||||||
static createFromOld(oldCollection) {
|
static createFromOld(oldCollection) {
|
||||||
const collection = this.getFromOld(oldCollection)
|
const collection = this.getFromOld(oldCollection)
|
||||||
return this.create(collection)
|
return this.create(collection)
|
||||||
@ -260,7 +253,8 @@ class Collection extends Model {
|
|||||||
* @returns {Promise<oldCollection>}
|
* @returns {Promise<oldCollection>}
|
||||||
*/
|
*/
|
||||||
async getOld() {
|
async getOld() {
|
||||||
this.books = await this.getBooks({
|
this.books =
|
||||||
|
(await this.getBooks({
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: this.sequelize.models.libraryItem
|
model: this.sequelize.models.libraryItem
|
||||||
@ -276,11 +270,10 @@ class Collection extends Model {
|
|||||||
through: {
|
through: {
|
||||||
attributes: ['sequence']
|
attributes: ['sequence']
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
],
|
],
|
||||||
order: [Sequelize.literal('`collectionBook.order` ASC')]
|
order: [Sequelize.literal('`collectionBook.order` ASC')]
|
||||||
}) || []
|
})) || []
|
||||||
|
|
||||||
return this.sequelize.models.collection.getOldCollection(this)
|
return this.sequelize.models.collection.getOldCollection(this)
|
||||||
}
|
}
|
||||||
@ -299,27 +292,13 @@ class Collection extends Model {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getAllForBook(bookId) {
|
|
||||||
const collections = await this.findAll({
|
|
||||||
include: {
|
|
||||||
model: this.sequelize.models.book,
|
|
||||||
where: {
|
|
||||||
id: bookId
|
|
||||||
},
|
|
||||||
required: true,
|
|
||||||
include: this.sequelize.models.libraryItem
|
|
||||||
},
|
|
||||||
order: [[this.sequelize.models.book, this.sequelize.models.collectionBook, 'order', 'ASC']]
|
|
||||||
})
|
|
||||||
return collections.map(c => this.getOldCollection(c))
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize model
|
* Initialize model
|
||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -327,10 +306,12 @@ class Collection extends Model {
|
|||||||
},
|
},
|
||||||
name: DataTypes.STRING,
|
name: DataTypes.STRING,
|
||||||
description: DataTypes.TEXT
|
description: DataTypes.TEXT
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'collection'
|
modelName: 'collection'
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const { library } = sequelize.models
|
const { library } = sequelize.models
|
||||||
|
|
||||||
|
@ -26,19 +26,22 @@ class CollectionBook extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
primaryKey: true
|
primaryKey: true
|
||||||
},
|
},
|
||||||
order: DataTypes.INTEGER
|
order: DataTypes.INTEGER
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
updatedAt: false,
|
updatedAt: false,
|
||||||
modelName: 'collectionBook'
|
modelName: 'collectionBook'
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// Super Many-to-Many
|
// Super Many-to-Many
|
||||||
// ref: https://sequelize.org/docs/v6/advanced-association-concepts/advanced-many-to-many/#the-best-of-both-worlds-the-super-many-to-many-relationship
|
// ref: https://sequelize.org/docs/v6/advanced-association-concepts/advanced-many-to-many/#the-best-of-both-worlds-the-super-many-to-many-relationship
|
||||||
|
@ -117,7 +117,8 @@ class Device extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -130,10 +131,12 @@ class Device extends Model {
|
|||||||
deviceName: DataTypes.STRING, // e.g. Windows 10 Chrome, Google Pixel 6, Apple iPhone 10,3
|
deviceName: DataTypes.STRING, // e.g. Windows 10 Chrome, Google Pixel 6, Apple iPhone 10,3
|
||||||
deviceVersion: DataTypes.STRING, // e.g. Browser version or Android SDK
|
deviceVersion: DataTypes.STRING, // e.g. Browser version or Android SDK
|
||||||
extraData: DataTypes.JSON
|
extraData: DataTypes.JSON
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'device'
|
modelName: 'device'
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const { user } = sequelize.models
|
const { user } = sequelize.models
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ class Feed extends Model {
|
|||||||
model: this.sequelize.models.feedEpisode
|
model: this.sequelize.models.feedEpisode
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return feeds.map(f => this.getOldFeed(f))
|
return feeds.map((f) => this.getOldFeed(f))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,7 +117,7 @@ class Feed extends Model {
|
|||||||
entityType: 'libraryItem'
|
entityType: 'libraryItem'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return feeds.map(f => f.entityId).filter(f => f) || []
|
return feeds.map((f) => f.entityId).filter((f) => f) || []
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -179,7 +179,7 @@ class Feed extends Model {
|
|||||||
|
|
||||||
// Remove and update existing feed episodes
|
// Remove and update existing feed episodes
|
||||||
for (const feedEpisode of existingFeed.feedEpisodes) {
|
for (const feedEpisode of existingFeed.feedEpisodes) {
|
||||||
const oldFeedEpisode = oldFeedEpisodes.find(ep => ep.id === feedEpisode.id)
|
const oldFeedEpisode = oldFeedEpisodes.find((ep) => ep.id === feedEpisode.id)
|
||||||
// Episode removed
|
// Episode removed
|
||||||
if (!oldFeedEpisode) {
|
if (!oldFeedEpisode) {
|
||||||
feedEpisode.destroy()
|
feedEpisode.destroy()
|
||||||
@ -200,7 +200,7 @@ class Feed extends Model {
|
|||||||
|
|
||||||
// Add new feed episodes
|
// Add new feed episodes
|
||||||
for (const episode of oldFeedEpisodes) {
|
for (const episode of oldFeedEpisodes) {
|
||||||
if (!existingFeed.feedEpisodes.some(fe => fe.id === episode.id)) {
|
if (!existingFeed.feedEpisodes.some((fe) => fe.id === episode.id)) {
|
||||||
await this.sequelize.models.feedEpisode.createFromOld(feedObj.id, episode)
|
await this.sequelize.models.feedEpisode.createFromOld(feedObj.id, episode)
|
||||||
hasUpdates = true
|
hasUpdates = true
|
||||||
}
|
}
|
||||||
@ -265,7 +265,8 @@ class Feed extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -289,10 +290,12 @@ class Feed extends Model {
|
|||||||
explicit: DataTypes.BOOLEAN,
|
explicit: DataTypes.BOOLEAN,
|
||||||
preventIndexing: DataTypes.BOOLEAN,
|
preventIndexing: DataTypes.BOOLEAN,
|
||||||
coverPath: DataTypes.STRING
|
coverPath: DataTypes.STRING
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'feed'
|
modelName: 'feed'
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const { user, libraryItem, collection, series, playlist } = sequelize.models
|
const { user, libraryItem, collection, series, playlist } = sequelize.models
|
||||||
|
|
||||||
@ -335,7 +338,7 @@ class Feed extends Model {
|
|||||||
})
|
})
|
||||||
Feed.belongsTo(playlist, { foreignKey: 'entityId', constraints: false })
|
Feed.belongsTo(playlist, { foreignKey: 'entityId', constraints: false })
|
||||||
|
|
||||||
Feed.addHook('afterFind', findResult => {
|
Feed.addHook('afterFind', (findResult) => {
|
||||||
if (!findResult) return
|
if (!findResult) return
|
||||||
|
|
||||||
if (!Array.isArray(findResult)) findResult = [findResult]
|
if (!Array.isArray(findResult)) findResult = [findResult]
|
||||||
|
@ -101,7 +101,8 @@ class FeedEpisode extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -121,10 +122,12 @@ class FeedEpisode extends Model {
|
|||||||
duration: DataTypes.FLOAT,
|
duration: DataTypes.FLOAT,
|
||||||
filePath: DataTypes.STRING,
|
filePath: DataTypes.STRING,
|
||||||
explicit: DataTypes.BOOLEAN
|
explicit: DataTypes.BOOLEAN
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'feedEpisode'
|
modelName: 'feedEpisode'
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const { feed } = sequelize.models
|
const { feed } = sequelize.models
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class Library extends Model {
|
|||||||
include: this.sequelize.models.libraryFolder,
|
include: this.sequelize.models.libraryFolder,
|
||||||
order: [['displayOrder', 'ASC']]
|
order: [['displayOrder', 'ASC']]
|
||||||
})
|
})
|
||||||
return libraries.map(lib => this.getOldLibrary(lib))
|
return libraries.map((lib) => this.getOldLibrary(lib))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,7 +63,7 @@ class Library extends Model {
|
|||||||
* @returns {Promise<oldLibrary>}
|
* @returns {Promise<oldLibrary>}
|
||||||
*/
|
*/
|
||||||
static getOldLibrary(libraryExpanded) {
|
static getOldLibrary(libraryExpanded) {
|
||||||
const folders = libraryExpanded.libraryFolders.map(folder => {
|
const folders = libraryExpanded.libraryFolders.map((folder) => {
|
||||||
return {
|
return {
|
||||||
id: folder.id,
|
id: folder.id,
|
||||||
fullPath: folder.path,
|
fullPath: folder.path,
|
||||||
@ -96,7 +96,7 @@ class Library extends Model {
|
|||||||
static async createFromOld(oldLibrary) {
|
static async createFromOld(oldLibrary) {
|
||||||
const library = this.getFromOld(oldLibrary)
|
const library = this.getFromOld(oldLibrary)
|
||||||
|
|
||||||
library.libraryFolders = oldLibrary.folders.map(folder => {
|
library.libraryFolders = oldLibrary.folders.map((folder) => {
|
||||||
return {
|
return {
|
||||||
id: folder.id,
|
id: folder.id,
|
||||||
path: folder.fullPath
|
path: folder.fullPath
|
||||||
@ -127,7 +127,7 @@ class Library extends Model {
|
|||||||
|
|
||||||
const library = this.getFromOld(oldLibrary)
|
const library = this.getFromOld(oldLibrary)
|
||||||
|
|
||||||
const libraryFolders = oldLibrary.folders.map(folder => {
|
const libraryFolders = oldLibrary.folders.map((folder) => {
|
||||||
return {
|
return {
|
||||||
id: folder.id,
|
id: folder.id,
|
||||||
path: folder.fullPath,
|
path: folder.fullPath,
|
||||||
@ -135,7 +135,7 @@ class Library extends Model {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
for (const libraryFolder of libraryFolders) {
|
for (const libraryFolder of libraryFolders) {
|
||||||
const existingLibraryFolder = existingLibrary.libraryFolders.find(lf => lf.id === libraryFolder.id)
|
const existingLibraryFolder = existingLibrary.libraryFolders.find((lf) => lf.id === libraryFolder.id)
|
||||||
if (!existingLibraryFolder) {
|
if (!existingLibraryFolder) {
|
||||||
await this.sequelize.models.libraryFolder.create(libraryFolder)
|
await this.sequelize.models.libraryFolder.create(libraryFolder)
|
||||||
} else if (existingLibraryFolder.path !== libraryFolder.path) {
|
} else if (existingLibraryFolder.path !== libraryFolder.path) {
|
||||||
@ -143,7 +143,7 @@ class Library extends Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const libraryFoldersRemoved = existingLibrary.libraryFolders.filter(lf => !libraryFolders.some(_lf => _lf.id === lf.id))
|
const libraryFoldersRemoved = existingLibrary.libraryFolders.filter((lf) => !libraryFolders.some((_lf) => _lf.id === lf.id))
|
||||||
for (const existingLibraryFolder of libraryFoldersRemoved) {
|
for (const existingLibraryFolder of libraryFoldersRemoved) {
|
||||||
await existingLibraryFolder.destroy()
|
await existingLibraryFolder.destroy()
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ class Library extends Model {
|
|||||||
attributes: ['id', 'displayOrder'],
|
attributes: ['id', 'displayOrder'],
|
||||||
order: [['displayOrder', 'ASC']]
|
order: [['displayOrder', 'ASC']]
|
||||||
})
|
})
|
||||||
return libraries.map(l => l.id)
|
return libraries.map((l) => l.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -247,7 +247,8 @@ class Library extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -262,10 +263,12 @@ class Library extends Model {
|
|||||||
lastScanVersion: DataTypes.STRING,
|
lastScanVersion: DataTypes.STRING,
|
||||||
settings: DataTypes.JSON,
|
settings: DataTypes.JSON,
|
||||||
extraData: DataTypes.JSON
|
extraData: DataTypes.JSON
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'library'
|
modelName: 'library'
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,33 +16,25 @@ class LibraryFolder extends Model {
|
|||||||
this.updatedAt
|
this.updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets all library folder path strings
|
|
||||||
* @returns {Promise<string[]>} array of library folder paths
|
|
||||||
*/
|
|
||||||
static async getAllLibraryFolderPaths() {
|
|
||||||
const libraryFolders = await this.findAll({
|
|
||||||
attributes: ['path']
|
|
||||||
})
|
|
||||||
return libraryFolders.map(l => l.path)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize model
|
* Initialize model
|
||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
primaryKey: true
|
primaryKey: true
|
||||||
},
|
},
|
||||||
path: DataTypes.STRING
|
path: DataTypes.STRING
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'libraryFolder'
|
modelName: 'libraryFolder'
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const { library } = sequelize.models
|
const { library } = sequelize.models
|
||||||
library.hasMany(LibraryFolder, {
|
library.hasMany(LibraryFolder, {
|
||||||
|
@ -154,7 +154,7 @@ class LibraryItem extends Model {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
return libraryItems.map(ti => this.getOldLibraryItem(ti))
|
return libraryItems.map((ti) => this.getOldLibraryItem(ti))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -280,14 +280,14 @@ class LibraryItem extends Model {
|
|||||||
|
|
||||||
for (const existingPodcastEpisode of existingPodcastEpisodes) {
|
for (const existingPodcastEpisode of existingPodcastEpisodes) {
|
||||||
// Episode was removed
|
// Episode was removed
|
||||||
if (!updatedPodcastEpisodes.some(ep => ep.id === existingPodcastEpisode.id)) {
|
if (!updatedPodcastEpisodes.some((ep) => ep.id === existingPodcastEpisode.id)) {
|
||||||
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" episode "${existingPodcastEpisode.title}" was removed`)
|
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" episode "${existingPodcastEpisode.title}" was removed`)
|
||||||
await existingPodcastEpisode.destroy()
|
await existingPodcastEpisode.destroy()
|
||||||
hasUpdates = true
|
hasUpdates = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const updatedPodcastEpisode of updatedPodcastEpisodes) {
|
for (const updatedPodcastEpisode of updatedPodcastEpisodes) {
|
||||||
const existingEpisodeMatch = existingPodcastEpisodes.find(ep => ep.id === updatedPodcastEpisode.id)
|
const existingEpisodeMatch = existingPodcastEpisodes.find((ep) => ep.id === updatedPodcastEpisode.id)
|
||||||
if (!existingEpisodeMatch) {
|
if (!existingEpisodeMatch) {
|
||||||
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" episode "${updatedPodcastEpisode.title}" was added`)
|
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" episode "${updatedPodcastEpisode.title}" was added`)
|
||||||
await this.sequelize.models.podcastEpisode.createFromOld(updatedPodcastEpisode)
|
await this.sequelize.models.podcastEpisode.createFromOld(updatedPodcastEpisode)
|
||||||
@ -316,12 +316,12 @@ class LibraryItem extends Model {
|
|||||||
const existingAuthors = libraryItemExpanded.media.authors || []
|
const existingAuthors = libraryItemExpanded.media.authors || []
|
||||||
const existingSeriesAll = libraryItemExpanded.media.series || []
|
const existingSeriesAll = libraryItemExpanded.media.series || []
|
||||||
const updatedAuthors = oldLibraryItem.media.metadata.authors || []
|
const updatedAuthors = oldLibraryItem.media.metadata.authors || []
|
||||||
const uniqueUpdatedAuthors = updatedAuthors.filter((au, idx) => updatedAuthors.findIndex(a => a.id === au.id) === idx)
|
const uniqueUpdatedAuthors = updatedAuthors.filter((au, idx) => updatedAuthors.findIndex((a) => a.id === au.id) === idx)
|
||||||
const updatedSeriesAll = oldLibraryItem.media.metadata.series || []
|
const updatedSeriesAll = oldLibraryItem.media.metadata.series || []
|
||||||
|
|
||||||
for (const existingAuthor of existingAuthors) {
|
for (const existingAuthor of existingAuthors) {
|
||||||
// Author was removed from Book
|
// Author was removed from Book
|
||||||
if (!uniqueUpdatedAuthors.some(au => au.id === existingAuthor.id)) {
|
if (!uniqueUpdatedAuthors.some((au) => au.id === existingAuthor.id)) {
|
||||||
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" author "${existingAuthor.name}" was removed`)
|
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" author "${existingAuthor.name}" was removed`)
|
||||||
await this.sequelize.models.bookAuthor.removeByIds(existingAuthor.id, libraryItemExpanded.media.id)
|
await this.sequelize.models.bookAuthor.removeByIds(existingAuthor.id, libraryItemExpanded.media.id)
|
||||||
hasUpdates = true
|
hasUpdates = true
|
||||||
@ -329,7 +329,7 @@ class LibraryItem extends Model {
|
|||||||
}
|
}
|
||||||
for (const updatedAuthor of uniqueUpdatedAuthors) {
|
for (const updatedAuthor of uniqueUpdatedAuthors) {
|
||||||
// Author was added
|
// Author was added
|
||||||
if (!existingAuthors.some(au => au.id === updatedAuthor.id)) {
|
if (!existingAuthors.some((au) => au.id === updatedAuthor.id)) {
|
||||||
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" author "${updatedAuthor.name}" was added`)
|
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" author "${updatedAuthor.name}" was added`)
|
||||||
await this.sequelize.models.bookAuthor.create({ authorId: updatedAuthor.id, bookId: libraryItemExpanded.media.id })
|
await this.sequelize.models.bookAuthor.create({ authorId: updatedAuthor.id, bookId: libraryItemExpanded.media.id })
|
||||||
hasUpdates = true
|
hasUpdates = true
|
||||||
@ -337,7 +337,7 @@ class LibraryItem extends Model {
|
|||||||
}
|
}
|
||||||
for (const existingSeries of existingSeriesAll) {
|
for (const existingSeries of existingSeriesAll) {
|
||||||
// Series was removed
|
// Series was removed
|
||||||
if (!updatedSeriesAll.some(se => se.id === existingSeries.id)) {
|
if (!updatedSeriesAll.some((se) => se.id === existingSeries.id)) {
|
||||||
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" series "${existingSeries.name}" was removed`)
|
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" series "${existingSeries.name}" was removed`)
|
||||||
await this.sequelize.models.bookSeries.removeByIds(existingSeries.id, libraryItemExpanded.media.id)
|
await this.sequelize.models.bookSeries.removeByIds(existingSeries.id, libraryItemExpanded.media.id)
|
||||||
hasUpdates = true
|
hasUpdates = true
|
||||||
@ -345,7 +345,7 @@ class LibraryItem extends Model {
|
|||||||
}
|
}
|
||||||
for (const updatedSeries of updatedSeriesAll) {
|
for (const updatedSeries of updatedSeriesAll) {
|
||||||
// Series was added/updated
|
// Series was added/updated
|
||||||
const existingSeriesMatch = existingSeriesAll.find(se => se.id === updatedSeries.id)
|
const existingSeriesMatch = existingSeriesAll.find((se) => se.id === updatedSeries.id)
|
||||||
if (!existingSeriesMatch) {
|
if (!existingSeriesMatch) {
|
||||||
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" series "${updatedSeries.name}" was added`)
|
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" series "${updatedSeries.name}" was added`)
|
||||||
await this.sequelize.models.bookSeries.create({ seriesId: updatedSeries.id, bookId: libraryItemExpanded.media.id, sequence: updatedSeries.sequence })
|
await this.sequelize.models.bookSeries.create({ seriesId: updatedSeries.id, bookId: libraryItemExpanded.media.id, sequence: updatedSeries.sequence })
|
||||||
@ -420,7 +420,7 @@ class LibraryItem extends Model {
|
|||||||
lastScanVersion: oldLibraryItem.scanVersion,
|
lastScanVersion: oldLibraryItem.scanVersion,
|
||||||
libraryId: oldLibraryItem.libraryId,
|
libraryId: oldLibraryItem.libraryId,
|
||||||
libraryFolderId: oldLibraryItem.folderId,
|
libraryFolderId: oldLibraryItem.folderId,
|
||||||
libraryFiles: oldLibraryItem.libraryFiles?.map(lf => lf.toJSON()) || [],
|
libraryFiles: oldLibraryItem.libraryFiles?.map((lf) => lf.toJSON()) || [],
|
||||||
extraData
|
extraData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -545,7 +545,7 @@ class LibraryItem extends Model {
|
|||||||
Logger.debug(`Loaded ${libraryItems.length} of ${count} items for libary page in ${((Date.now() - start) / 1000).toFixed(2)}s`)
|
Logger.debug(`Loaded ${libraryItems.length} of ${count} items for libary page in ${((Date.now() - start) / 1000).toFixed(2)}s`)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
libraryItems: libraryItems.map(li => {
|
libraryItems: libraryItems.map((li) => {
|
||||||
const oldLibraryItem = this.getOldLibraryItem(li).toJSONMinified()
|
const oldLibraryItem = this.getOldLibraryItem(li).toJSONMinified()
|
||||||
if (li.collapsedSeries) {
|
if (li.collapsedSeries) {
|
||||||
oldLibraryItem.collapsedSeries = li.collapsedSeries
|
oldLibraryItem.collapsedSeries = li.collapsedSeries
|
||||||
@ -588,8 +588,8 @@ class LibraryItem extends Model {
|
|||||||
// "Continue Listening" shelf
|
// "Continue Listening" shelf
|
||||||
const itemsInProgressPayload = await libraryFilters.getMediaItemsInProgress(library, user, include, limit, false)
|
const itemsInProgressPayload = await libraryFilters.getMediaItemsInProgress(library, user, include, limit, false)
|
||||||
if (itemsInProgressPayload.items.length) {
|
if (itemsInProgressPayload.items.length) {
|
||||||
const ebookOnlyItemsInProgress = itemsInProgressPayload.items.filter(li => li.media.isEBookOnly)
|
const ebookOnlyItemsInProgress = itemsInProgressPayload.items.filter((li) => li.media.isEBookOnly)
|
||||||
const audioOnlyItemsInProgress = itemsInProgressPayload.items.filter(li => !li.media.isEBookOnly)
|
const audioOnlyItemsInProgress = itemsInProgressPayload.items.filter((li) => !li.media.isEBookOnly)
|
||||||
|
|
||||||
shelves.push({
|
shelves.push({
|
||||||
id: 'continue-listening',
|
id: 'continue-listening',
|
||||||
@ -697,8 +697,8 @@ class LibraryItem extends Model {
|
|||||||
// "Listen Again" shelf
|
// "Listen Again" shelf
|
||||||
const mediaFinishedPayload = await libraryFilters.getMediaFinished(library, user, include, limit)
|
const mediaFinishedPayload = await libraryFilters.getMediaFinished(library, user, include, limit)
|
||||||
if (mediaFinishedPayload.items.length) {
|
if (mediaFinishedPayload.items.length) {
|
||||||
const ebookOnlyItemsInProgress = mediaFinishedPayload.items.filter(li => li.media.isEBookOnly)
|
const ebookOnlyItemsInProgress = mediaFinishedPayload.items.filter((li) => li.media.isEBookOnly)
|
||||||
const audioOnlyItemsInProgress = mediaFinishedPayload.items.filter(li => !li.media.isEBookOnly)
|
const audioOnlyItemsInProgress = mediaFinishedPayload.items.filter((li) => !li.media.isEBookOnly)
|
||||||
|
|
||||||
shelves.push({
|
shelves.push({
|
||||||
id: 'listen-again',
|
id: 'listen-again',
|
||||||
@ -753,7 +753,7 @@ class LibraryItem extends Model {
|
|||||||
*/
|
*/
|
||||||
static async getForAuthor(author, user = null) {
|
static async getForAuthor(author, user = null) {
|
||||||
const { libraryItems } = await libraryFilters.getLibraryItemsForAuthor(author, user, undefined, undefined)
|
const { libraryItems } = await libraryFilters.getLibraryItemsForAuthor(author, user, undefined, undefined)
|
||||||
return libraryItems.map(li => this.getOldLibraryItem(li))
|
return libraryItems.map((li) => this.getOldLibraryItem(li))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -763,7 +763,7 @@ class LibraryItem extends Model {
|
|||||||
*/
|
*/
|
||||||
static async getForCollection(collection) {
|
static async getForCollection(collection) {
|
||||||
const libraryItems = await libraryFilters.getLibraryItemsForCollection(collection)
|
const libraryItems = await libraryFilters.getLibraryItemsForCollection(collection)
|
||||||
return libraryItems.map(li => this.getOldLibraryItem(li))
|
return libraryItems.map((li) => this.getOldLibraryItem(li))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -887,18 +887,18 @@ class LibraryItem extends Model {
|
|||||||
const metadataFilePath = Path.join(metadataPath, `metadata.${global.ServerSettings.metadataFileFormat}`)
|
const metadataFilePath = Path.join(metadataPath, `metadata.${global.ServerSettings.metadataFileFormat}`)
|
||||||
|
|
||||||
// Expanded with series, authors, podcastEpisodes
|
// Expanded with series, authors, podcastEpisodes
|
||||||
const mediaExpanded = this.media || await this.getMediaExpanded()
|
const mediaExpanded = this.media || (await this.getMediaExpanded())
|
||||||
|
|
||||||
let jsonObject = {}
|
let jsonObject = {}
|
||||||
if (this.mediaType === 'book') {
|
if (this.mediaType === 'book') {
|
||||||
jsonObject = {
|
jsonObject = {
|
||||||
tags: mediaExpanded.tags || [],
|
tags: mediaExpanded.tags || [],
|
||||||
chapters: mediaExpanded.chapters?.map(c => ({ ...c })) || [],
|
chapters: mediaExpanded.chapters?.map((c) => ({ ...c })) || [],
|
||||||
title: mediaExpanded.title,
|
title: mediaExpanded.title,
|
||||||
subtitle: mediaExpanded.subtitle,
|
subtitle: mediaExpanded.subtitle,
|
||||||
authors: mediaExpanded.authors.map(a => a.name),
|
authors: mediaExpanded.authors.map((a) => a.name),
|
||||||
narrators: mediaExpanded.narrators,
|
narrators: mediaExpanded.narrators,
|
||||||
series: mediaExpanded.series.map(se => {
|
series: mediaExpanded.series.map((se) => {
|
||||||
const sequence = se.bookSeries?.sequence || ''
|
const sequence = se.bookSeries?.sequence || ''
|
||||||
if (!sequence) return se.name
|
if (!sequence) return se.name
|
||||||
return `${se.name} #${sequence}`
|
return `${se.name} #${sequence}`
|
||||||
@ -934,10 +934,11 @@ class LibraryItem extends Model {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fsExtra
|
||||||
return fsExtra.writeFile(metadataFilePath, JSON.stringify(jsonObject, null, 2)).then(async () => {
|
.writeFile(metadataFilePath, JSON.stringify(jsonObject, null, 2))
|
||||||
|
.then(async () => {
|
||||||
// Add metadata.json to libraryFiles array if it is new
|
// Add metadata.json to libraryFiles array if it is new
|
||||||
let metadataLibraryFile = this.libraryFiles.find(lf => lf.metadata.path === filePathToPOSIX(metadataFilePath))
|
let metadataLibraryFile = this.libraryFiles.find((lf) => lf.metadata.path === filePathToPOSIX(metadataFilePath))
|
||||||
if (storeMetadataWithItem) {
|
if (storeMetadataWithItem) {
|
||||||
if (!metadataLibraryFile) {
|
if (!metadataLibraryFile) {
|
||||||
const newLibraryFile = new LibraryFile()
|
const newLibraryFile = new LibraryFile()
|
||||||
@ -958,7 +959,7 @@ class LibraryItem extends Model {
|
|||||||
this.mtime = libraryItemDirTimestamps.mtimeMs
|
this.mtime = libraryItemDirTimestamps.mtimeMs
|
||||||
this.ctime = libraryItemDirTimestamps.ctimeMs
|
this.ctime = libraryItemDirTimestamps.ctimeMs
|
||||||
let size = 0
|
let size = 0
|
||||||
this.libraryFiles.forEach((lf) => size += (!isNaN(lf.metadata.size) ? Number(lf.metadata.size) : 0))
|
this.libraryFiles.forEach((lf) => (size += !isNaN(lf.metadata.size) ? Number(lf.metadata.size) : 0))
|
||||||
this.size = size
|
this.size = size
|
||||||
await this.save()
|
await this.save()
|
||||||
}
|
}
|
||||||
@ -967,7 +968,8 @@ class LibraryItem extends Model {
|
|||||||
Logger.debug(`Success saving abmetadata to "${metadataFilePath}"`)
|
Logger.debug(`Success saving abmetadata to "${metadataFilePath}"`)
|
||||||
|
|
||||||
return metadataLibraryFile
|
return metadataLibraryFile
|
||||||
}).catch((error) => {
|
})
|
||||||
|
.catch((error) => {
|
||||||
Logger.error(`Failed to save json file at "${metadataFilePath}"`, error)
|
Logger.error(`Failed to save json file at "${metadataFilePath}"`, error)
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
@ -978,7 +980,8 @@ class LibraryItem extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -1000,7 +1003,8 @@ class LibraryItem extends Model {
|
|||||||
lastScanVersion: DataTypes.STRING,
|
lastScanVersion: DataTypes.STRING,
|
||||||
libraryFiles: DataTypes.JSON,
|
libraryFiles: DataTypes.JSON,
|
||||||
extraData: DataTypes.JSON
|
extraData: DataTypes.JSON
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'libraryItem',
|
modelName: 'libraryItem',
|
||||||
indexes: [
|
indexes: [
|
||||||
@ -1023,7 +1027,8 @@ class LibraryItem extends Model {
|
|||||||
fields: ['mtime']
|
fields: ['mtime']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const { library, libraryFolder, book, podcast } = sequelize.models
|
const { library, libraryFolder, book, podcast } = sequelize.models
|
||||||
library.hasMany(LibraryItem)
|
library.hasMany(LibraryItem)
|
||||||
@ -1050,7 +1055,7 @@ class LibraryItem extends Model {
|
|||||||
})
|
})
|
||||||
LibraryItem.belongsTo(podcast, { foreignKey: 'mediaId', constraints: false })
|
LibraryItem.belongsTo(podcast, { foreignKey: 'mediaId', constraints: false })
|
||||||
|
|
||||||
LibraryItem.addHook('afterFind', findResult => {
|
LibraryItem.addHook('afterFind', (findResult) => {
|
||||||
if (!findResult) return
|
if (!findResult) return
|
||||||
|
|
||||||
if (!Array.isArray(findResult)) findResult = [findResult]
|
if (!Array.isArray(findResult)) findResult = [findResult]
|
||||||
@ -1070,7 +1075,7 @@ class LibraryItem extends Model {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
LibraryItem.addHook('afterDestroy', async instance => {
|
LibraryItem.addHook('afterDestroy', async (instance) => {
|
||||||
if (!instance) return
|
if (!instance) return
|
||||||
const media = await instance.getMedia()
|
const media = await instance.getMedia()
|
||||||
if (media) {
|
if (media) {
|
||||||
|
@ -107,7 +107,8 @@ class MediaProgress extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -123,7 +124,8 @@ class MediaProgress extends Model {
|
|||||||
ebookProgress: DataTypes.FLOAT,
|
ebookProgress: DataTypes.FLOAT,
|
||||||
finishedAt: DataTypes.DATE,
|
finishedAt: DataTypes.DATE,
|
||||||
extraData: DataTypes.JSON
|
extraData: DataTypes.JSON
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'mediaProgress',
|
modelName: 'mediaProgress',
|
||||||
indexes: [
|
indexes: [
|
||||||
@ -131,7 +133,8 @@ class MediaProgress extends Model {
|
|||||||
fields: ['updatedAt']
|
fields: ['updatedAt']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const { book, podcastEpisode, user } = sequelize.models
|
const { book, podcastEpisode, user } = sequelize.models
|
||||||
|
|
||||||
@ -153,7 +156,7 @@ class MediaProgress extends Model {
|
|||||||
})
|
})
|
||||||
MediaProgress.belongsTo(podcastEpisode, { foreignKey: 'mediaItemId', constraints: false })
|
MediaProgress.belongsTo(podcastEpisode, { foreignKey: 'mediaItemId', constraints: false })
|
||||||
|
|
||||||
MediaProgress.addHook('afterFind', findResult => {
|
MediaProgress.addHook('afterFind', (findResult) => {
|
||||||
if (!findResult) return
|
if (!findResult) return
|
||||||
|
|
||||||
if (!Array.isArray(findResult)) findResult = [findResult]
|
if (!Array.isArray(findResult)) findResult = [findResult]
|
||||||
|
@ -2,7 +2,6 @@ const { DataTypes, Model } = require('sequelize')
|
|||||||
|
|
||||||
const oldPlaybackSession = require('../objects/PlaybackSession')
|
const oldPlaybackSession = require('../objects/PlaybackSession')
|
||||||
|
|
||||||
|
|
||||||
class PlaybackSession extends Model {
|
class PlaybackSession extends Model {
|
||||||
constructor(values, options) {
|
constructor(values, options) {
|
||||||
super(values, options)
|
super(values, options)
|
||||||
@ -62,7 +61,7 @@ class PlaybackSession extends Model {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
return playbackSessions.map(session => this.getOldPlaybackSession(session))
|
return playbackSessions.map((session) => this.getOldPlaybackSession(session))
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getById(sessionId) {
|
static async getById(sessionId) {
|
||||||
@ -173,7 +172,8 @@ class PlaybackSession extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -195,10 +195,12 @@ class PlaybackSession extends Model {
|
|||||||
date: DataTypes.STRING,
|
date: DataTypes.STRING,
|
||||||
dayOfWeek: DataTypes.STRING,
|
dayOfWeek: DataTypes.STRING,
|
||||||
extraData: DataTypes.JSON
|
extraData: DataTypes.JSON
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'playbackSession'
|
modelName: 'playbackSession'
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const { book, podcastEpisode, user, device, library } = sequelize.models
|
const { book, podcastEpisode, user, device, library } = sequelize.models
|
||||||
|
|
||||||
@ -229,7 +231,7 @@ class PlaybackSession extends Model {
|
|||||||
})
|
})
|
||||||
PlaybackSession.belongsTo(podcastEpisode, { foreignKey: 'mediaItemId', constraints: false })
|
PlaybackSession.belongsTo(podcastEpisode, { foreignKey: 'mediaItemId', constraints: false })
|
||||||
|
|
||||||
PlaybackSession.addHook('afterFind', findResult => {
|
PlaybackSession.addHook('afterFind', (findResult) => {
|
||||||
if (!findResult) return
|
if (!findResult) return
|
||||||
|
|
||||||
if (!Array.isArray(findResult)) findResult = [findResult]
|
if (!Array.isArray(findResult)) findResult = [findResult]
|
||||||
|
@ -23,29 +23,6 @@ class Playlist extends Model {
|
|||||||
this.updatedAt
|
this.updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getOldPlaylists() {
|
|
||||||
const playlists = await this.findAll({
|
|
||||||
include: {
|
|
||||||
model: this.sequelize.models.playlistMediaItem,
|
|
||||||
include: [
|
|
||||||
{
|
|
||||||
model: this.sequelize.models.book,
|
|
||||||
include: this.sequelize.models.libraryItem
|
|
||||||
},
|
|
||||||
{
|
|
||||||
model: this.sequelize.models.podcastEpisode,
|
|
||||||
include: {
|
|
||||||
model: this.sequelize.models.podcast,
|
|
||||||
include: this.sequelize.models.libraryItem
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
order: [['playlistMediaItems', 'order', 'ASC']]
|
|
||||||
})
|
|
||||||
return playlists.map((p) => this.getOldPlaylist(p))
|
|
||||||
}
|
|
||||||
|
|
||||||
static getOldPlaylist(playlistExpanded) {
|
static getOldPlaylist(playlistExpanded) {
|
||||||
const items = playlistExpanded.playlistMediaItems
|
const items = playlistExpanded.playlistMediaItems
|
||||||
.map((pmi) => {
|
.map((pmi) => {
|
||||||
@ -76,8 +53,8 @@ class Playlist extends Model {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get old playlist toJSONExpanded
|
* Get old playlist toJSONExpanded
|
||||||
* @param {[string[]]} include
|
* @param {string[]} [include]
|
||||||
* @returns {Promise<object>} oldPlaylist.toJSONExpanded
|
* @returns {Promise<oldPlaylist>} oldPlaylist.toJSONExpanded
|
||||||
*/
|
*/
|
||||||
async getOldJsonExpanded(include) {
|
async getOldJsonExpanded(include) {
|
||||||
this.playlistMediaItems =
|
this.playlistMediaItems =
|
||||||
|
@ -38,7 +38,8 @@ class PlaylistMediaItem extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -47,12 +48,14 @@ class PlaylistMediaItem extends Model {
|
|||||||
mediaItemId: DataTypes.UUIDV4,
|
mediaItemId: DataTypes.UUIDV4,
|
||||||
mediaItemType: DataTypes.STRING,
|
mediaItemType: DataTypes.STRING,
|
||||||
order: DataTypes.INTEGER
|
order: DataTypes.INTEGER
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
updatedAt: false,
|
updatedAt: false,
|
||||||
modelName: 'playlistMediaItem'
|
modelName: 'playlistMediaItem'
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const { book, podcastEpisode, playlist } = sequelize.models
|
const { book, podcastEpisode, playlist } = sequelize.models
|
||||||
|
|
||||||
@ -74,7 +77,7 @@ class PlaylistMediaItem extends Model {
|
|||||||
})
|
})
|
||||||
PlaylistMediaItem.belongsTo(podcastEpisode, { foreignKey: 'mediaItemId', constraints: false })
|
PlaylistMediaItem.belongsTo(podcastEpisode, { foreignKey: 'mediaItemId', constraints: false })
|
||||||
|
|
||||||
PlaylistMediaItem.addHook('afterFind', findResult => {
|
PlaylistMediaItem.addHook('afterFind', (findResult) => {
|
||||||
if (!findResult) return
|
if (!findResult) return
|
||||||
|
|
||||||
if (!Array.isArray(findResult)) findResult = [findResult]
|
if (!Array.isArray(findResult)) findResult = [findResult]
|
||||||
|
@ -61,7 +61,7 @@ class Podcast extends Model {
|
|||||||
|
|
||||||
static getOldPodcast(libraryItemExpanded) {
|
static getOldPodcast(libraryItemExpanded) {
|
||||||
const podcastExpanded = libraryItemExpanded.media
|
const podcastExpanded = libraryItemExpanded.media
|
||||||
const podcastEpisodes = podcastExpanded.podcastEpisodes?.map(ep => ep.getOldPodcastEpisode(libraryItemExpanded.id).toJSON()).sort((a, b) => a.index - b.index)
|
const podcastEpisodes = podcastExpanded.podcastEpisodes?.map((ep) => ep.getOldPodcastEpisode(libraryItemExpanded.id).toJSON()).sort((a, b) => a.index - b.index)
|
||||||
return {
|
return {
|
||||||
id: podcastExpanded.id,
|
id: podcastExpanded.id,
|
||||||
libraryItemId: libraryItemExpanded.id,
|
libraryItemId: libraryItemExpanded.id,
|
||||||
@ -143,7 +143,8 @@ class Podcast extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -171,10 +172,12 @@ class Podcast extends Model {
|
|||||||
coverPath: DataTypes.STRING,
|
coverPath: DataTypes.STRING,
|
||||||
tags: DataTypes.JSON,
|
tags: DataTypes.JSON,
|
||||||
genres: DataTypes.JSON
|
genres: DataTypes.JSON
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'podcast'
|
modelName: 'podcast'
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,8 @@ class PodcastEpisode extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -150,7 +151,8 @@ class PodcastEpisode extends Model {
|
|||||||
audioFile: DataTypes.JSON,
|
audioFile: DataTypes.JSON,
|
||||||
chapters: DataTypes.JSON,
|
chapters: DataTypes.JSON,
|
||||||
extraData: DataTypes.JSON
|
extraData: DataTypes.JSON
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'podcastEpisode',
|
modelName: 'podcastEpisode',
|
||||||
indexes: [
|
indexes: [
|
||||||
@ -158,7 +160,8 @@ class PodcastEpisode extends Model {
|
|||||||
fields: ['createdAt']
|
fields: ['createdAt']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const { podcast } = sequelize.models
|
const { podcast } = sequelize.models
|
||||||
podcast.hasMany(PodcastEpisode, {
|
podcast.hasMany(PodcastEpisode, {
|
||||||
|
@ -24,7 +24,7 @@ class Series extends Model {
|
|||||||
|
|
||||||
static async getAllOldSeries() {
|
static async getAllOldSeries() {
|
||||||
const series = await this.findAll()
|
const series = await this.findAll()
|
||||||
return series.map(se => se.getOldSeries())
|
return series.map((se) => se.getOldSeries())
|
||||||
}
|
}
|
||||||
|
|
||||||
getOldSeries() {
|
getOldSeries() {
|
||||||
@ -103,14 +103,16 @@ class Series extends Model {
|
|||||||
* @returns {Promise<oldSeries>}
|
* @returns {Promise<oldSeries>}
|
||||||
*/
|
*/
|
||||||
static async getOldByNameAndLibrary(seriesName, libraryId) {
|
static async getOldByNameAndLibrary(seriesName, libraryId) {
|
||||||
const series = (await this.findOne({
|
const series = (
|
||||||
|
await this.findOne({
|
||||||
where: [
|
where: [
|
||||||
where(fn('lower', col('name')), seriesName.toLowerCase()),
|
where(fn('lower', col('name')), seriesName.toLowerCase()),
|
||||||
{
|
{
|
||||||
libraryId
|
libraryId
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}))?.getOldSeries()
|
})
|
||||||
|
)?.getOldSeries()
|
||||||
return series
|
return series
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +121,8 @@ class Series extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -128,15 +131,18 @@ class Series extends Model {
|
|||||||
name: DataTypes.STRING,
|
name: DataTypes.STRING,
|
||||||
nameIgnorePrefix: DataTypes.STRING,
|
nameIgnorePrefix: DataTypes.STRING,
|
||||||
description: DataTypes.TEXT
|
description: DataTypes.TEXT
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'series',
|
modelName: 'series',
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
fields: [{
|
fields: [
|
||||||
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
collate: 'NOCASE'
|
collate: 'NOCASE'
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
// fields: [{
|
// fields: [{
|
||||||
@ -148,7 +154,8 @@ class Series extends Model {
|
|||||||
fields: ['libraryId']
|
fields: ['libraryId']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const { library } = sequelize.models
|
const { library } = sequelize.models
|
||||||
library.hasMany(Series, {
|
library.hasMany(Series, {
|
||||||
|
@ -19,12 +19,11 @@ class Setting extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getOldSettings() {
|
static async getOldSettings() {
|
||||||
const settings = (await this.findAll()).map(se => se.value)
|
const settings = (await this.findAll()).map((se) => se.value)
|
||||||
|
|
||||||
|
const emailSettingsJson = settings.find((se) => se.id === 'email-settings')
|
||||||
const emailSettingsJson = settings.find(se => se.id === 'email-settings')
|
const serverSettingsJson = settings.find((se) => se.id === 'server-settings')
|
||||||
const serverSettingsJson = settings.find(se => se.id === 'server-settings')
|
const notificationSettingsJson = settings.find((se) => se.id === 'notification-settings')
|
||||||
const notificationSettingsJson = settings.find(se => se.id === 'notification-settings')
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
settings,
|
settings,
|
||||||
@ -46,16 +45,19 @@ class Setting extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
key: {
|
key: {
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
primaryKey: true
|
primaryKey: true
|
||||||
},
|
},
|
||||||
value: DataTypes.JSON
|
value: DataTypes.JSON
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'setting'
|
modelName: 'setting'
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const uuidv4 = require("uuid").v4
|
const uuidv4 = require('uuid').v4
|
||||||
const sequelize = require('sequelize')
|
const sequelize = require('sequelize')
|
||||||
const Logger = require('../Logger')
|
const Logger = require('../Logger')
|
||||||
const oldUser = require('../objects/user/User')
|
const oldUser = require('../objects/user/User')
|
||||||
@ -45,7 +45,7 @@ class User extends Model {
|
|||||||
const users = await this.findAll({
|
const users = await this.findAll({
|
||||||
include: this.sequelize.models.mediaProgress
|
include: this.sequelize.models.mediaProgress
|
||||||
})
|
})
|
||||||
return users.map(u => this.getOldUser(u))
|
return users.map((u) => this.getOldUser(u))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,7 +55,7 @@ class User extends Model {
|
|||||||
* @returns {oldUser}
|
* @returns {oldUser}
|
||||||
*/
|
*/
|
||||||
static getOldUser(userExpanded) {
|
static getOldUser(userExpanded) {
|
||||||
const mediaProgress = userExpanded.mediaProgresses.map(mp => mp.getOldMediaProgress())
|
const mediaProgress = userExpanded.mediaProgresses.map((mp) => mp.getOldMediaProgress())
|
||||||
|
|
||||||
const librariesAccessible = userExpanded.permissions?.librariesAccessible || []
|
const librariesAccessible = userExpanded.permissions?.librariesAccessible || []
|
||||||
const itemTagsSelected = userExpanded.permissions?.itemTagsSelected || []
|
const itemTagsSelected = userExpanded.permissions?.itemTagsSelected || []
|
||||||
@ -109,7 +109,9 @@ class User extends Model {
|
|||||||
where: {
|
where: {
|
||||||
id: user.id
|
id: user.id
|
||||||
}
|
}
|
||||||
}).then((result) => result[0] > 0).catch((error) => {
|
})
|
||||||
|
.then((result) => result[0] > 0)
|
||||||
|
.catch((error) => {
|
||||||
Logger.error(`[User] Failed to save user ${oldUser.id}`, error)
|
Logger.error(`[User] Failed to save user ${oldUser.id}`, error)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
@ -193,7 +195,7 @@ class User extends Model {
|
|||||||
const userId = uuidv4()
|
const userId = uuidv4()
|
||||||
// TODO: Ensure username is unique?
|
// TODO: Ensure username is unique?
|
||||||
const username = userinfo.preferred_username || userinfo.name || userinfo.sub
|
const username = userinfo.preferred_username || userinfo.name || userinfo.sub
|
||||||
const email = (userinfo.email && userinfo.email_verified) ? userinfo.email : null
|
const email = userinfo.email && userinfo.email_verified ? userinfo.email : null
|
||||||
|
|
||||||
const token = await auth.generateAccessToken({ id: userId, username })
|
const token = await auth.generateAccessToken({ id: userId, username })
|
||||||
|
|
||||||
@ -317,7 +319,7 @@ class User extends Model {
|
|||||||
const users = await this.findAll({
|
const users = await this.findAll({
|
||||||
attributes: ['id', 'username']
|
attributes: ['id', 'username']
|
||||||
})
|
})
|
||||||
return users.map(u => {
|
return users.map((u) => {
|
||||||
return {
|
return {
|
||||||
id: u.id,
|
id: u.id,
|
||||||
username: u.username
|
username: u.username
|
||||||
@ -343,7 +345,8 @@ class User extends Model {
|
|||||||
* @param {import('../Database').sequelize} sequelize
|
* @param {import('../Database').sequelize} sequelize
|
||||||
*/
|
*/
|
||||||
static init(sequelize) {
|
static init(sequelize) {
|
||||||
super.init({
|
super.init(
|
||||||
|
{
|
||||||
id: {
|
id: {
|
||||||
type: DataTypes.UUID,
|
type: DataTypes.UUID,
|
||||||
defaultValue: DataTypes.UUIDV4,
|
defaultValue: DataTypes.UUIDV4,
|
||||||
@ -366,10 +369,12 @@ class User extends Model {
|
|||||||
permissions: DataTypes.JSON,
|
permissions: DataTypes.JSON,
|
||||||
bookmarks: DataTypes.JSON,
|
bookmarks: DataTypes.JSON,
|
||||||
extraData: DataTypes.JSON
|
extraData: DataTypes.JSON
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
modelName: 'user'
|
modelName: 'user'
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user