Skip to content

Commit

Permalink
Clean out old unused functions, Device updates for replacing DeviceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Sep 12, 2024
1 parent 3d9af89 commit 01fbea0
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 143 deletions.
20 changes: 5 additions & 15 deletions server/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class Database {
return this.models.mediaItemShare
}

/** @type {typeof import('./models/Device')} */
get deviceModel() {
return this.models.device
}

/**
* Check if db file exists
* @returns {boolean}
Expand Down Expand Up @@ -489,21 +494,6 @@ class Database {
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) {
for (const libraryId in this.libraryFilterData) {
const indexOf = this.libraryFilterData[libraryId].tags.findIndex((n) => n === oldTag)
Expand Down
6 changes: 3 additions & 3 deletions server/managers/PlaybackSessionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ class PlaybackSessionManager {
deviceInfo.setData(ip, ua, clientDeviceInfo, serverVersion, req.user?.id)

if (clientDeviceInfo?.deviceId) {
const existingDevice = await Database.getDeviceByDeviceId(clientDeviceInfo.deviceId)
const existingDevice = await Database.deviceModel.getOldDeviceByDeviceId(clientDeviceInfo.deviceId)
if (existingDevice) {
if (existingDevice.update(deviceInfo)) {
await Database.updateDevice(existingDevice)
await Database.deviceModel.updateFromOld(existingDevice)
}
return existingDevice
}
}

await Database.createDevice(deviceInfo)
await Database.deviceModel.createFromOld(deviceInfo)

return deviceInfo
}
Expand Down
79 changes: 41 additions & 38 deletions server/models/CustomMetadataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,11 @@ class CustomMetadataProvider extends Model {
this.updatedAt
}

getSlug() {
return `custom-${this.id}`
}

/**
* Safe for clients
* @returns {ClientCustomMetadataProvider}
*/
toClientJson() {
return {
id: this.id,
name: this.name,
mediaType: this.mediaType,
slug: this.getSlug()
}
}

/**
* Get providers for client by media type
* Currently only available for "book" media type
*
* @param {string} mediaType
*
* @param {string} mediaType
* @returns {Promise<ClientCustomMetadataProvider[]>}
*/
static async getForClientByMediaType(mediaType) {
Expand All @@ -61,13 +44,13 @@ class CustomMetadataProvider extends Model {
mediaType
}
})
return customMetadataProviders.map(cmp => cmp.toClientJson())
return customMetadataProviders.map((cmp) => cmp.toClientJson())
}

/**
* Check if provider exists by slug
*
* @param {string} providerSlug
*
* @param {string} providerSlug
* @returns {Promise<boolean>}
*/
static async checkExistsBySlug(providerSlug) {
Expand All @@ -79,25 +62,45 @@ class CustomMetadataProvider extends Model {

/**
* Initialize model
* @param {import('../Database').sequelize} sequelize
* @param {import('../Database').sequelize} sequelize
*/
static init(sequelize) {
super.init({
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
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
},
name: DataTypes.STRING,
mediaType: DataTypes.STRING,
url: DataTypes.STRING,
authHeaderValue: DataTypes.STRING,
extraData: DataTypes.JSON
}, {
sequelize,
modelName: 'customMetadataProvider'
})
{
sequelize,
modelName: 'customMetadataProvider'
}
)
}

getSlug() {
return `custom-${this.id}`
}

/**
* Safe for clients
* @returns {ClientCustomMetadataProvider}
*/
toClientJson() {
return {
id: this.id,
name: this.name,
mediaType: this.mediaType,
slug: this.getSlug()
}
}
}

module.exports = CustomMetadataProvider
module.exports = CustomMetadataProvider
81 changes: 54 additions & 27 deletions server/models/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,6 @@ class Device extends Model {
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) {
const device = await this.findOne({
where: {
Expand Down Expand Up @@ -145,6 +118,60 @@ class Device extends Model {
})
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
10 changes: 2 additions & 8 deletions server/objects/PlaybackSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class PlaybackSession {

/**
* Session data to send to clients
* @param {[oldLibraryItem]} libraryItem optional
* @returns {object}
* @param {Object} [libraryItem] - old library item
* @returns
*/
toJSONForClient(libraryItem) {
return {
Expand Down Expand Up @@ -255,11 +255,5 @@ class PlaybackSession {
this.timeListening += Number.parseFloat(timeListened)
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
9 changes: 0 additions & 9 deletions server/objects/mediaTypes/Podcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,6 @@ class Podcast {
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) {
const episode = this.episodes.find((ep) => ep.id === episodeId)
if (episode) {
Expand Down
Loading

0 comments on commit 01fbea0

Please sign in to comment.