mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-10 09:24:56 +02:00
Init sqlite take 2
This commit is contained in:
parent
d86a3b3dc2
commit
cf7fd315b6
88 changed files with 7017 additions and 692 deletions
|
@ -1,5 +1,9 @@
|
|||
const uuidv4 = require("uuid").v4
|
||||
|
||||
class DeviceInfo {
|
||||
constructor(deviceInfo = null) {
|
||||
this.id = null
|
||||
this.userId = null
|
||||
this.deviceId = null
|
||||
this.ipAddress = null
|
||||
|
||||
|
@ -16,7 +20,8 @@ class DeviceInfo {
|
|||
this.model = null
|
||||
this.sdkVersion = null // Android Only
|
||||
|
||||
this.serverVersion = null
|
||||
this.clientName = null
|
||||
this.deviceName = null
|
||||
|
||||
if (deviceInfo) {
|
||||
this.construct(deviceInfo)
|
||||
|
@ -33,6 +38,8 @@ class DeviceInfo {
|
|||
|
||||
toJSON() {
|
||||
const obj = {
|
||||
id: this.id,
|
||||
userId: this.userId,
|
||||
deviceId: this.deviceId,
|
||||
ipAddress: this.ipAddress,
|
||||
browserName: this.browserName,
|
||||
|
@ -44,7 +51,8 @@ class DeviceInfo {
|
|||
manufacturer: this.manufacturer,
|
||||
model: this.model,
|
||||
sdkVersion: this.sdkVersion,
|
||||
serverVersion: this.serverVersion
|
||||
clientName: this.clientName,
|
||||
deviceName: this.deviceName
|
||||
}
|
||||
for (const key in obj) {
|
||||
if (obj[key] === null || obj[key] === undefined) {
|
||||
|
@ -65,6 +73,7 @@ class DeviceInfo {
|
|||
// When client doesn't send a device id
|
||||
getTempDeviceId() {
|
||||
const keys = [
|
||||
this.userId,
|
||||
this.browserName,
|
||||
this.browserVersion,
|
||||
this.osName,
|
||||
|
@ -78,7 +87,9 @@ class DeviceInfo {
|
|||
return 'temp-' + Buffer.from(keys.join('-'), 'utf-8').toString('base64')
|
||||
}
|
||||
|
||||
setData(ip, ua, clientDeviceInfo, serverVersion) {
|
||||
setData(ip, ua, clientDeviceInfo, serverVersion, userId) {
|
||||
this.id = uuidv4()
|
||||
this.userId = userId
|
||||
this.deviceId = clientDeviceInfo?.deviceId || null
|
||||
this.ipAddress = ip || null
|
||||
|
||||
|
@ -88,16 +99,54 @@ class DeviceInfo {
|
|||
this.osVersion = ua?.os.version || null
|
||||
this.deviceType = ua?.device.type || null
|
||||
|
||||
this.clientVersion = clientDeviceInfo?.clientVersion || null
|
||||
this.clientVersion = clientDeviceInfo?.clientVersion || serverVersion
|
||||
this.manufacturer = clientDeviceInfo?.manufacturer || null
|
||||
this.model = clientDeviceInfo?.model || null
|
||||
this.sdkVersion = clientDeviceInfo?.sdkVersion || null
|
||||
|
||||
this.serverVersion = serverVersion || null
|
||||
this.clientName = clientDeviceInfo?.clientName || null
|
||||
if (this.sdkVersion) {
|
||||
if (!this.clientName) this.clientName = 'Abs Android'
|
||||
this.deviceName = `${this.manufacturer || 'Unknown'} ${this.model || ''}`
|
||||
} else if (this.model) {
|
||||
if (!this.clientName) this.clientName = 'Abs iOS'
|
||||
this.deviceName = `${this.manufacturer || 'Unknown'} ${this.model || ''}`
|
||||
} else if (this.osName && this.browserName) {
|
||||
if (!this.clientName) this.clientName = 'Abs Web'
|
||||
this.deviceName = `${this.osName} ${this.osVersion || 'N/A'} ${this.browserName}`
|
||||
} else if (!this.clientName) {
|
||||
this.clientName = 'Unknown'
|
||||
}
|
||||
|
||||
if (!this.deviceId) {
|
||||
this.deviceId = this.getTempDeviceId()
|
||||
}
|
||||
}
|
||||
|
||||
update(deviceInfo) {
|
||||
const deviceInfoJson = deviceInfo.toJSON ? deviceInfo.toJSON() : deviceInfo
|
||||
const existingDeviceInfoJson = this.toJSON()
|
||||
|
||||
let hasUpdates = false
|
||||
for (const key in deviceInfoJson) {
|
||||
if (['id', 'deviceId'].includes(key)) continue
|
||||
|
||||
if (deviceInfoJson[key] !== existingDeviceInfoJson[key]) {
|
||||
this[key] = deviceInfoJson[key]
|
||||
hasUpdates = true
|
||||
}
|
||||
}
|
||||
|
||||
for (const key in existingDeviceInfoJson) {
|
||||
if (['id', 'deviceId'].includes(key)) continue
|
||||
|
||||
if (existingDeviceInfoJson[key] && !deviceInfoJson[key]) {
|
||||
this[key] = null
|
||||
hasUpdates = true
|
||||
}
|
||||
}
|
||||
|
||||
return hasUpdates
|
||||
}
|
||||
}
|
||||
module.exports = DeviceInfo
|
Loading…
Add table
Add a link
Reference in a new issue