mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Clean out old unused functions, Device updates for replacing DeviceInfo
This commit is contained in:
parent
3d9af89e24
commit
01fbea02f1
@ -144,6 +144,11 @@ class Database {
|
|||||||
return this.models.mediaItemShare
|
return this.models.mediaItemShare
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type {typeof import('./models/Device')} */
|
||||||
|
get deviceModel() {
|
||||||
|
return this.models.device
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if db file exists
|
* Check if db file exists
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
@ -489,21 +494,6 @@ class Database {
|
|||||||
return this.models.playbackSession.removeById(sessionId)
|
return this.models.playbackSession.removeById(sessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
getDeviceByDeviceId(deviceId) {
|
|
||||||
if (!this.sequelize) return false
|
|
||||||
return this.models.device.getOldDeviceByDeviceId(deviceId)
|
|
||||||
}
|
|
||||||
|
|
||||||
updateDevice(oldDevice) {
|
|
||||||
if (!this.sequelize) return false
|
|
||||||
return this.models.device.updateFromOld(oldDevice)
|
|
||||||
}
|
|
||||||
|
|
||||||
createDevice(oldDevice) {
|
|
||||||
if (!this.sequelize) return false
|
|
||||||
return this.models.device.createFromOld(oldDevice)
|
|
||||||
}
|
|
||||||
|
|
||||||
replaceTagInFilterData(oldTag, newTag) {
|
replaceTagInFilterData(oldTag, newTag) {
|
||||||
for (const libraryId in this.libraryFilterData) {
|
for (const libraryId in this.libraryFilterData) {
|
||||||
const indexOf = this.libraryFilterData[libraryId].tags.findIndex((n) => n === oldTag)
|
const indexOf = this.libraryFilterData[libraryId].tags.findIndex((n) => n === oldTag)
|
||||||
|
@ -51,16 +51,16 @@ class PlaybackSessionManager {
|
|||||||
deviceInfo.setData(ip, ua, clientDeviceInfo, serverVersion, req.user?.id)
|
deviceInfo.setData(ip, ua, clientDeviceInfo, serverVersion, req.user?.id)
|
||||||
|
|
||||||
if (clientDeviceInfo?.deviceId) {
|
if (clientDeviceInfo?.deviceId) {
|
||||||
const existingDevice = await Database.getDeviceByDeviceId(clientDeviceInfo.deviceId)
|
const existingDevice = await Database.deviceModel.getOldDeviceByDeviceId(clientDeviceInfo.deviceId)
|
||||||
if (existingDevice) {
|
if (existingDevice) {
|
||||||
if (existingDevice.update(deviceInfo)) {
|
if (existingDevice.update(deviceInfo)) {
|
||||||
await Database.updateDevice(existingDevice)
|
await Database.deviceModel.updateFromOld(existingDevice)
|
||||||
}
|
}
|
||||||
return existingDevice
|
return existingDevice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Database.createDevice(deviceInfo)
|
await Database.deviceModel.createFromOld(deviceInfo)
|
||||||
|
|
||||||
return deviceInfo
|
return deviceInfo
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,61 @@ class CustomMetadataProvider extends Model {
|
|||||||
this.updatedAt
|
this.updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get providers for client by media type
|
||||||
|
* Currently only available for "book" media type
|
||||||
|
*
|
||||||
|
* @param {string} mediaType
|
||||||
|
* @returns {Promise<ClientCustomMetadataProvider[]>}
|
||||||
|
*/
|
||||||
|
static async getForClientByMediaType(mediaType) {
|
||||||
|
if (mediaType !== 'book') return []
|
||||||
|
const customMetadataProviders = await this.findAll({
|
||||||
|
where: {
|
||||||
|
mediaType
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return customMetadataProviders.map((cmp) => cmp.toClientJson())
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if provider exists by slug
|
||||||
|
*
|
||||||
|
* @param {string} providerSlug
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
*/
|
||||||
|
static async checkExistsBySlug(providerSlug) {
|
||||||
|
const providerId = providerSlug?.split?.('custom-')[1]
|
||||||
|
if (!providerId) return false
|
||||||
|
|
||||||
|
return (await this.count({ where: { id: providerId } })) > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize model
|
||||||
|
* @param {import('../Database').sequelize} sequelize
|
||||||
|
*/
|
||||||
|
static init(sequelize) {
|
||||||
|
super.init(
|
||||||
|
{
|
||||||
|
id: {
|
||||||
|
type: DataTypes.UUID,
|
||||||
|
defaultValue: DataTypes.UUIDV4,
|
||||||
|
primaryKey: true
|
||||||
|
},
|
||||||
|
name: DataTypes.STRING,
|
||||||
|
mediaType: DataTypes.STRING,
|
||||||
|
url: DataTypes.STRING,
|
||||||
|
authHeaderValue: DataTypes.STRING,
|
||||||
|
extraData: DataTypes.JSON
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sequelize,
|
||||||
|
modelName: 'customMetadataProvider'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
getSlug() {
|
getSlug() {
|
||||||
return `custom-${this.id}`
|
return `custom-${this.id}`
|
||||||
}
|
}
|
||||||
@ -46,58 +101,6 @@ class CustomMetadataProvider extends Model {
|
|||||||
slug: this.getSlug()
|
slug: this.getSlug()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get providers for client by media type
|
|
||||||
* Currently only available for "book" media type
|
|
||||||
*
|
|
||||||
* @param {string} mediaType
|
|
||||||
* @returns {Promise<ClientCustomMetadataProvider[]>}
|
|
||||||
*/
|
|
||||||
static async getForClientByMediaType(mediaType) {
|
|
||||||
if (mediaType !== 'book') return []
|
|
||||||
const customMetadataProviders = await this.findAll({
|
|
||||||
where: {
|
|
||||||
mediaType
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return customMetadataProviders.map(cmp => cmp.toClientJson())
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if provider exists by slug
|
|
||||||
*
|
|
||||||
* @param {string} providerSlug
|
|
||||||
* @returns {Promise<boolean>}
|
|
||||||
*/
|
|
||||||
static async checkExistsBySlug(providerSlug) {
|
|
||||||
const providerId = providerSlug?.split?.('custom-')[1]
|
|
||||||
if (!providerId) return false
|
|
||||||
|
|
||||||
return (await this.count({ where: { id: providerId } })) > 0
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize model
|
|
||||||
* @param {import('../Database').sequelize} sequelize
|
|
||||||
*/
|
|
||||||
static init(sequelize) {
|
|
||||||
super.init({
|
|
||||||
id: {
|
|
||||||
type: DataTypes.UUID,
|
|
||||||
defaultValue: DataTypes.UUIDV4,
|
|
||||||
primaryKey: true
|
|
||||||
},
|
|
||||||
name: DataTypes.STRING,
|
|
||||||
mediaType: DataTypes.STRING,
|
|
||||||
url: DataTypes.STRING,
|
|
||||||
authHeaderValue: DataTypes.STRING,
|
|
||||||
extraData: DataTypes.JSON
|
|
||||||
}, {
|
|
||||||
sequelize,
|
|
||||||
modelName: 'customMetadataProvider'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = CustomMetadataProvider
|
module.exports = CustomMetadataProvider
|
||||||
|
@ -29,33 +29,6 @@ class Device extends Model {
|
|||||||
this.updatedAt
|
this.updatedAt
|
||||||
}
|
}
|
||||||
|
|
||||||
getOldDevice() {
|
|
||||||
let browserVersion = null
|
|
||||||
let sdkVersion = null
|
|
||||||
if (this.clientName === 'Abs Android') {
|
|
||||||
sdkVersion = this.deviceVersion || null
|
|
||||||
} else {
|
|
||||||
browserVersion = this.deviceVersion || null
|
|
||||||
}
|
|
||||||
|
|
||||||
return new oldDevice({
|
|
||||||
id: this.id,
|
|
||||||
deviceId: this.deviceId,
|
|
||||||
userId: this.userId,
|
|
||||||
ipAddress: this.ipAddress,
|
|
||||||
browserName: this.extraData.browserName || null,
|
|
||||||
browserVersion,
|
|
||||||
osName: this.extraData.osName || null,
|
|
||||||
osVersion: this.extraData.osVersion || null,
|
|
||||||
clientVersion: this.clientVersion || null,
|
|
||||||
manufacturer: this.extraData.manufacturer || null,
|
|
||||||
model: this.extraData.model || null,
|
|
||||||
sdkVersion,
|
|
||||||
deviceName: this.deviceName,
|
|
||||||
clientName: this.clientName
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getOldDeviceByDeviceId(deviceId) {
|
static async getOldDeviceByDeviceId(deviceId) {
|
||||||
const device = await this.findOne({
|
const device = await this.findOne({
|
||||||
where: {
|
where: {
|
||||||
@ -145,6 +118,60 @@ class Device extends Model {
|
|||||||
})
|
})
|
||||||
Device.belongsTo(user)
|
Device.belongsTo(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toOldJSON() {
|
||||||
|
let browserVersion = null
|
||||||
|
let sdkVersion = null
|
||||||
|
if (this.clientName === 'Abs Android') {
|
||||||
|
sdkVersion = this.deviceVersion || null
|
||||||
|
} else {
|
||||||
|
browserVersion = this.deviceVersion || null
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: this.id,
|
||||||
|
deviceId: this.deviceId,
|
||||||
|
userId: this.userId,
|
||||||
|
ipAddress: this.ipAddress,
|
||||||
|
browserName: this.extraData.browserName || null,
|
||||||
|
browserVersion,
|
||||||
|
osName: this.extraData.osName || null,
|
||||||
|
osVersion: this.extraData.osVersion || null,
|
||||||
|
clientVersion: this.clientVersion || null,
|
||||||
|
manufacturer: this.extraData.manufacturer || null,
|
||||||
|
model: this.extraData.model || null,
|
||||||
|
sdkVersion,
|
||||||
|
deviceName: this.deviceName,
|
||||||
|
clientName: this.clientName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getOldDevice() {
|
||||||
|
let browserVersion = null
|
||||||
|
let sdkVersion = null
|
||||||
|
if (this.clientName === 'Abs Android') {
|
||||||
|
sdkVersion = this.deviceVersion || null
|
||||||
|
} else {
|
||||||
|
browserVersion = this.deviceVersion || null
|
||||||
|
}
|
||||||
|
|
||||||
|
return new oldDevice({
|
||||||
|
id: this.id,
|
||||||
|
deviceId: this.deviceId,
|
||||||
|
userId: this.userId,
|
||||||
|
ipAddress: this.ipAddress,
|
||||||
|
browserName: this.extraData.browserName || null,
|
||||||
|
browserVersion,
|
||||||
|
osName: this.extraData.osName || null,
|
||||||
|
osVersion: this.extraData.osVersion || null,
|
||||||
|
clientVersion: this.clientVersion || null,
|
||||||
|
manufacturer: this.extraData.manufacturer || null,
|
||||||
|
model: this.extraData.model || null,
|
||||||
|
sdkVersion,
|
||||||
|
deviceName: this.deviceName,
|
||||||
|
clientName: this.clientName
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Device
|
module.exports = Device
|
||||||
|
@ -82,8 +82,8 @@ class PlaybackSession {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Session data to send to clients
|
* Session data to send to clients
|
||||||
* @param {[oldLibraryItem]} libraryItem optional
|
* @param {Object} [libraryItem] - old library item
|
||||||
* @returns {object}
|
* @returns
|
||||||
*/
|
*/
|
||||||
toJSONForClient(libraryItem) {
|
toJSONForClient(libraryItem) {
|
||||||
return {
|
return {
|
||||||
@ -255,11 +255,5 @@ class PlaybackSession {
|
|||||||
this.timeListening += Number.parseFloat(timeListened)
|
this.timeListening += Number.parseFloat(timeListened)
|
||||||
this.updatedAt = Date.now()
|
this.updatedAt = Date.now()
|
||||||
}
|
}
|
||||||
|
|
||||||
// New date since start of listening session
|
|
||||||
checkDateRollover() {
|
|
||||||
if (!this.date) return false
|
|
||||||
return date.format(new Date(), 'YYYY-MM-DD') !== this.date
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
module.exports = PlaybackSession
|
module.exports = PlaybackSession
|
||||||
|
@ -233,15 +233,6 @@ class Podcast {
|
|||||||
this.episodes.push(podcastEpisode)
|
this.episodes.push(podcastEpisode)
|
||||||
}
|
}
|
||||||
|
|
||||||
addNewEpisodeFromAudioFile(audioFile, index) {
|
|
||||||
const pe = new PodcastEpisode()
|
|
||||||
pe.libraryItemId = this.libraryItemId
|
|
||||||
pe.podcastId = this.id
|
|
||||||
audioFile.index = 1 // Only 1 audio file per episode
|
|
||||||
pe.setDataFromAudioFile(audioFile, index)
|
|
||||||
this.episodes.push(pe)
|
|
||||||
}
|
|
||||||
|
|
||||||
removeEpisode(episodeId) {
|
removeEpisode(episodeId) {
|
||||||
const episode = this.episodes.find((ep) => ep.id === episodeId)
|
const episode = this.episodes.find((ep) => ep.id === episodeId)
|
||||||
if (episode) {
|
if (episode) {
|
||||||
|
@ -6,7 +6,7 @@ class BookMetadata {
|
|||||||
this.title = null
|
this.title = null
|
||||||
this.subtitle = null
|
this.subtitle = null
|
||||||
this.authors = []
|
this.authors = []
|
||||||
this.narrators = [] // Array of strings
|
this.narrators = [] // Array of strings
|
||||||
this.series = []
|
this.series = []
|
||||||
this.genres = [] // Array of strings
|
this.genres = [] // Array of strings
|
||||||
this.publishedYear = null
|
this.publishedYear = null
|
||||||
@ -27,9 +27,9 @@ class BookMetadata {
|
|||||||
construct(metadata) {
|
construct(metadata) {
|
||||||
this.title = metadata.title
|
this.title = metadata.title
|
||||||
this.subtitle = metadata.subtitle
|
this.subtitle = metadata.subtitle
|
||||||
this.authors = (metadata.authors?.map) ? metadata.authors.map(a => ({ ...a })) : []
|
this.authors = metadata.authors?.map ? metadata.authors.map((a) => ({ ...a })) : []
|
||||||
this.narrators = metadata.narrators ? [...metadata.narrators].filter(n => n) : []
|
this.narrators = metadata.narrators ? [...metadata.narrators].filter((n) => n) : []
|
||||||
this.series = (metadata.series?.map) ? metadata.series.map(s => ({ ...s })) : []
|
this.series = metadata.series?.map ? metadata.series.map((s) => ({ ...s })) : []
|
||||||
this.genres = metadata.genres ? [...metadata.genres] : []
|
this.genres = metadata.genres ? [...metadata.genres] : []
|
||||||
this.publishedYear = metadata.publishedYear || null
|
this.publishedYear = metadata.publishedYear || null
|
||||||
this.publishedDate = metadata.publishedDate || null
|
this.publishedDate = metadata.publishedDate || null
|
||||||
@ -46,9 +46,9 @@ class BookMetadata {
|
|||||||
return {
|
return {
|
||||||
title: this.title,
|
title: this.title,
|
||||||
subtitle: this.subtitle,
|
subtitle: this.subtitle,
|
||||||
authors: this.authors.map(a => ({ ...a })), // Author JSONMinimal with name and id
|
authors: this.authors.map((a) => ({ ...a })), // Author JSONMinimal with name and id
|
||||||
narrators: [...this.narrators],
|
narrators: [...this.narrators],
|
||||||
series: this.series.map(s => ({ ...s })), // Series JSONMinimal with name, id and sequence
|
series: this.series.map((s) => ({ ...s })), // Series JSONMinimal with name, id and sequence
|
||||||
genres: [...this.genres],
|
genres: [...this.genres],
|
||||||
publishedYear: this.publishedYear,
|
publishedYear: this.publishedYear,
|
||||||
publishedDate: this.publishedDate,
|
publishedDate: this.publishedDate,
|
||||||
@ -89,9 +89,9 @@ class BookMetadata {
|
|||||||
title: this.title,
|
title: this.title,
|
||||||
titleIgnorePrefix: this.titlePrefixAtEnd,
|
titleIgnorePrefix: this.titlePrefixAtEnd,
|
||||||
subtitle: this.subtitle,
|
subtitle: this.subtitle,
|
||||||
authors: this.authors.map(a => ({ ...a })), // Author JSONMinimal with name and id
|
authors: this.authors.map((a) => ({ ...a })), // Author JSONMinimal with name and id
|
||||||
narrators: [...this.narrators],
|
narrators: [...this.narrators],
|
||||||
series: this.series.map(s => ({ ...s })),
|
series: this.series.map((s) => ({ ...s })),
|
||||||
genres: [...this.genres],
|
genres: [...this.genres],
|
||||||
publishedYear: this.publishedYear,
|
publishedYear: this.publishedYear,
|
||||||
publishedDate: this.publishedDate,
|
publishedDate: this.publishedDate,
|
||||||
@ -111,8 +111,8 @@ class BookMetadata {
|
|||||||
|
|
||||||
toJSONForMetadataFile() {
|
toJSONForMetadataFile() {
|
||||||
const json = this.toJSON()
|
const json = this.toJSON()
|
||||||
json.authors = json.authors.map(au => au.name)
|
json.authors = json.authors.map((au) => au.name)
|
||||||
json.series = json.series.map(se => {
|
json.series = json.series.map((se) => {
|
||||||
if (!se.sequence) return se.name
|
if (!se.sequence) return se.name
|
||||||
return `${se.name} #${se.sequence}`
|
return `${se.name} #${se.sequence}`
|
||||||
})
|
})
|
||||||
@ -131,36 +131,31 @@ class BookMetadata {
|
|||||||
}
|
}
|
||||||
get authorName() {
|
get authorName() {
|
||||||
if (!this.authors.length) return ''
|
if (!this.authors.length) return ''
|
||||||
return this.authors.map(au => au.name).join(', ')
|
return this.authors.map((au) => au.name).join(', ')
|
||||||
}
|
}
|
||||||
get authorNameLF() { // Last, First
|
get authorNameLF() {
|
||||||
|
// Last, First
|
||||||
if (!this.authors.length) return ''
|
if (!this.authors.length) return ''
|
||||||
return this.authors.map(au => parseNameString.nameToLastFirst(au.name)).join(', ')
|
return this.authors.map((au) => parseNameString.nameToLastFirst(au.name)).join(', ')
|
||||||
}
|
}
|
||||||
get seriesName() {
|
get seriesName() {
|
||||||
if (!this.series.length) return ''
|
if (!this.series.length) return ''
|
||||||
return this.series.map(se => {
|
return this.series
|
||||||
if (!se.sequence) return se.name
|
.map((se) => {
|
||||||
return `${se.name} #${se.sequence}`
|
if (!se.sequence) return se.name
|
||||||
}).join(', ')
|
return `${se.name} #${se.sequence}`
|
||||||
}
|
})
|
||||||
get firstSeriesName() {
|
.join(', ')
|
||||||
if (!this.series.length) return ''
|
|
||||||
return this.series[0].name
|
|
||||||
}
|
|
||||||
get firstSeriesSequence() {
|
|
||||||
if (!this.series.length) return ''
|
|
||||||
return this.series[0].sequence
|
|
||||||
}
|
}
|
||||||
get narratorName() {
|
get narratorName() {
|
||||||
return this.narrators.join(', ')
|
return this.narrators.join(', ')
|
||||||
}
|
}
|
||||||
|
|
||||||
getSeries(seriesId) {
|
getSeries(seriesId) {
|
||||||
return this.series.find(se => se.id == seriesId)
|
return this.series.find((se) => se.id == seriesId)
|
||||||
}
|
}
|
||||||
getSeriesSequence(seriesId) {
|
getSeriesSequence(seriesId) {
|
||||||
const series = this.series.find(se => se.id == seriesId)
|
const series = this.series.find((se) => se.id == seriesId)
|
||||||
if (!series) return null
|
if (!series) return null
|
||||||
return series.sequence || ''
|
return series.sequence || ''
|
||||||
}
|
}
|
||||||
@ -180,21 +175,5 @@ class BookMetadata {
|
|||||||
}
|
}
|
||||||
return hasUpdates
|
return hasUpdates
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates author name
|
|
||||||
updateAuthor(updatedAuthor) {
|
|
||||||
const author = this.authors.find(au => au.id === updatedAuthor.id)
|
|
||||||
if (!author || author.name == updatedAuthor.name) return false
|
|
||||||
author.name = updatedAuthor.name
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
replaceAuthor(oldAuthor, newAuthor) {
|
|
||||||
this.authors = this.authors.filter(au => au.id !== oldAuthor.id) // Remove old author
|
|
||||||
this.authors.push({
|
|
||||||
id: newAuthor.id,
|
|
||||||
name: newAuthor.name
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
module.exports = BookMetadata
|
module.exports = BookMetadata
|
||||||
|
Loading…
Reference in New Issue
Block a user