mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-03 21:54:53 -04:00
Update jsdocs
This commit is contained in:
parent
09bcc1191f
commit
903b685e1a
@ -1,6 +1,6 @@
|
|||||||
|
const { Op } = require('sequelize')
|
||||||
const Logger = require('../Logger')
|
const Logger = require('../Logger')
|
||||||
const Database = require('../Database')
|
const Database = require('../Database')
|
||||||
const { Op } = require('sequelize')
|
|
||||||
|
|
||||||
const ShareManager = require('../managers/ShareManager')
|
const ShareManager = require('../managers/ShareManager')
|
||||||
|
|
||||||
@ -34,6 +34,7 @@ class ShareController {
|
|||||||
if (!mediaItemShare.mediaItem) {
|
if (!mediaItemShare.mediaItem) {
|
||||||
return res.status(404).send('Media item not found')
|
return res.status(404).send('Media item not found')
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json(mediaItemShare)
|
res.json(mediaItemShare)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(`[ShareController] Failed`, error)
|
Logger.error(`[ShareController] Failed`, error)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const uuidv4 = require("uuid").v4
|
const uuidv4 = require('uuid').v4
|
||||||
const Path = require('path')
|
const Path = require('path')
|
||||||
const serverVersion = require('../../package.json').version
|
const serverVersion = require('../../package.json').version
|
||||||
const Logger = require('../Logger')
|
const Logger = require('../Logger')
|
||||||
@ -25,10 +25,10 @@ class PlaybackSessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSession(sessionId) {
|
getSession(sessionId) {
|
||||||
return this.sessions.find(s => s.id === sessionId)
|
return this.sessions.find((s) => s.id === sessionId)
|
||||||
}
|
}
|
||||||
getUserSession(userId) {
|
getUserSession(userId) {
|
||||||
return this.sessions.find(s => s.userId === userId)
|
return this.sessions.find((s) => s.userId === userId)
|
||||||
}
|
}
|
||||||
getStream(sessionId) {
|
getStream(sessionId) {
|
||||||
const session = this.getSession(sessionId)
|
const session = this.getSession(sessionId)
|
||||||
@ -59,6 +59,12 @@ class PlaybackSessionManager {
|
|||||||
return deviceInfo
|
return deviceInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {import('express').Request} req
|
||||||
|
* @param {import('express').Response} res
|
||||||
|
* @param {string} [episodeId]
|
||||||
|
*/
|
||||||
async startSessionRequest(req, res, episodeId) {
|
async startSessionRequest(req, res, episodeId) {
|
||||||
const deviceInfo = await this.getDeviceInfo(req)
|
const deviceInfo = await this.getDeviceInfo(req)
|
||||||
Logger.debug(`[PlaybackSessionManager] startSessionRequest for device ${deviceInfo.deviceDescription}`)
|
Logger.debug(`[PlaybackSessionManager] startSessionRequest for device ${deviceInfo.deviceDescription}`)
|
||||||
@ -94,7 +100,7 @@ class PlaybackSessionManager {
|
|||||||
|
|
||||||
async syncLocalSession(user, sessionJson, deviceInfo) {
|
async syncLocalSession(user, sessionJson, deviceInfo) {
|
||||||
const libraryItem = await Database.libraryItemModel.getOldById(sessionJson.libraryItemId)
|
const libraryItem = await Database.libraryItemModel.getOldById(sessionJson.libraryItemId)
|
||||||
const episode = (sessionJson.episodeId && libraryItem && libraryItem.isPodcast) ? libraryItem.media.getEpisode(sessionJson.episodeId) : null
|
const episode = sessionJson.episodeId && libraryItem && libraryItem.isPodcast ? libraryItem.media.getEpisode(sessionJson.episodeId) : null
|
||||||
if (!libraryItem || (libraryItem.isPodcast && !episode)) {
|
if (!libraryItem || (libraryItem.isPodcast && !episode)) {
|
||||||
Logger.error(`[PlaybackSessionManager] syncLocalSession: Media item not found for session "${sessionJson.displayTitle}" (${sessionJson.id})`)
|
Logger.error(`[PlaybackSessionManager] syncLocalSession: Media item not found for session "${sessionJson.displayTitle}" (${sessionJson.id})`)
|
||||||
return {
|
return {
|
||||||
@ -209,9 +215,18 @@ class PlaybackSessionManager {
|
|||||||
res.sendStatus(200)
|
res.sendStatus(200)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {import('../objects/user/User')} user
|
||||||
|
* @param {DeviceInfo} deviceInfo
|
||||||
|
* @param {import('../objects/LibraryItem')} libraryItem
|
||||||
|
* @param {string|null} episodeId
|
||||||
|
* @param {{forceDirectPlay?:boolean, forceTranscode?:boolean, mediaPlayer:string, supportedMimeTypes?:string[]}} options
|
||||||
|
* @returns {Promise<PlaybackSession>}
|
||||||
|
*/
|
||||||
async startSession(user, deviceInfo, libraryItem, episodeId, options) {
|
async startSession(user, deviceInfo, libraryItem, episodeId, options) {
|
||||||
// Close any sessions already open for user and device
|
// Close any sessions already open for user and device
|
||||||
const userSessions = this.sessions.filter(playbackSession => playbackSession.userId === user.id && playbackSession.deviceId === deviceInfo.id)
|
const userSessions = this.sessions.filter((playbackSession) => playbackSession.userId === user.id && playbackSession.deviceId === deviceInfo.id)
|
||||||
for (const session of userSessions) {
|
for (const session of userSessions) {
|
||||||
Logger.info(`[PlaybackSessionManager] startSession: Closing open session "${session.displayTitle}" for user "${user.username}" (Device: ${session.deviceDescription})`)
|
Logger.info(`[PlaybackSessionManager] startSession: Closing open session "${session.displayTitle}" for user "${user.username}" (Device: ${session.deviceDescription})`)
|
||||||
await this.closeSession(user, session, null)
|
await this.closeSession(user, session, null)
|
||||||
@ -231,7 +246,7 @@ class PlaybackSessionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const newPlaybackSession = new PlaybackSession()
|
const newPlaybackSession = new PlaybackSession()
|
||||||
newPlaybackSession.setData(libraryItem, user, mediaPlayer, deviceInfo, userStartTime, episodeId)
|
newPlaybackSession.setData(libraryItem, user.id, mediaPlayer, deviceInfo, userStartTime, episodeId)
|
||||||
|
|
||||||
if (libraryItem.mediaType === 'video') {
|
if (libraryItem.mediaType === 'video') {
|
||||||
if (shouldDirectPlay) {
|
if (shouldDirectPlay) {
|
||||||
@ -328,12 +343,12 @@ class PlaybackSessionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async removeSession(sessionId) {
|
async removeSession(sessionId) {
|
||||||
const session = this.sessions.find(s => s.id === sessionId)
|
const session = this.sessions.find((s) => s.id === sessionId)
|
||||||
if (!session) return
|
if (!session) return
|
||||||
if (session.stream) {
|
if (session.stream) {
|
||||||
await session.stream.close()
|
await session.stream.close()
|
||||||
}
|
}
|
||||||
this.sessions = this.sessions.filter(s => s.id !== sessionId)
|
this.sessions = this.sessions.filter((s) => s.id !== sessionId)
|
||||||
Logger.debug(`[PlaybackSessionManager] Removed session "${sessionId}"`)
|
Logger.debug(`[PlaybackSessionManager] Removed session "${sessionId}"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,8 +360,9 @@ class PlaybackSessionManager {
|
|||||||
try {
|
try {
|
||||||
const streamsInPath = await fs.readdir(this.StreamsPath)
|
const streamsInPath = await fs.readdir(this.StreamsPath)
|
||||||
for (const streamId of streamsInPath) {
|
for (const streamId of streamsInPath) {
|
||||||
if (/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/.test(streamId)) { // Ensure is uuidv4
|
if (/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/.test(streamId)) {
|
||||||
const session = this.sessions.find(se => se.id === streamId)
|
// Ensure is uuidv4
|
||||||
|
const session = this.sessions.find((se) => se.id === streamId)
|
||||||
if (!session) {
|
if (!session) {
|
||||||
const streamPath = Path.join(this.StreamsPath, streamId)
|
const streamPath = Path.join(this.StreamsPath, streamId)
|
||||||
Logger.debug(`[PlaybackSessionManager] Removing orphan stream "${streamPath}"`)
|
Logger.debug(`[PlaybackSessionManager] Removing orphan stream "${streamPath}"`)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const date = require('../libs/dateAndTime')
|
const date = require('../libs/dateAndTime')
|
||||||
const uuidv4 = require("uuid").v4
|
const uuidv4 = require('uuid').v4
|
||||||
const serverVersion = require('../../package.json').version
|
const serverVersion = require('../../package.json').version
|
||||||
const BookMetadata = require('./metadata/BookMetadata')
|
const BookMetadata = require('./metadata/BookMetadata')
|
||||||
const PodcastMetadata = require('./metadata/PodcastMetadata')
|
const PodcastMetadata = require('./metadata/PodcastMetadata')
|
||||||
@ -59,7 +59,7 @@ class PlaybackSession {
|
|||||||
episodeId: this.episodeId,
|
episodeId: this.episodeId,
|
||||||
mediaType: this.mediaType,
|
mediaType: this.mediaType,
|
||||||
mediaMetadata: this.mediaMetadata?.toJSON() || null,
|
mediaMetadata: this.mediaMetadata?.toJSON() || null,
|
||||||
chapters: (this.chapters || []).map(c => ({ ...c })),
|
chapters: (this.chapters || []).map((c) => ({ ...c })),
|
||||||
displayTitle: this.displayTitle,
|
displayTitle: this.displayTitle,
|
||||||
displayAuthor: this.displayAuthor,
|
displayAuthor: this.displayAuthor,
|
||||||
coverPath: this.coverPath,
|
coverPath: this.coverPath,
|
||||||
@ -93,7 +93,7 @@ class PlaybackSession {
|
|||||||
episodeId: this.episodeId,
|
episodeId: this.episodeId,
|
||||||
mediaType: this.mediaType,
|
mediaType: this.mediaType,
|
||||||
mediaMetadata: this.mediaMetadata?.toJSON() || null,
|
mediaMetadata: this.mediaMetadata?.toJSON() || null,
|
||||||
chapters: (this.chapters || []).map(c => ({ ...c })),
|
chapters: (this.chapters || []).map((c) => ({ ...c })),
|
||||||
displayTitle: this.displayTitle,
|
displayTitle: this.displayTitle,
|
||||||
displayAuthor: this.displayAuthor,
|
displayAuthor: this.displayAuthor,
|
||||||
coverPath: this.coverPath,
|
coverPath: this.coverPath,
|
||||||
@ -109,7 +109,7 @@ class PlaybackSession {
|
|||||||
currentTime: this.currentTime,
|
currentTime: this.currentTime,
|
||||||
startedAt: this.startedAt,
|
startedAt: this.startedAt,
|
||||||
updatedAt: this.updatedAt,
|
updatedAt: this.updatedAt,
|
||||||
audioTracks: this.audioTracks.map(at => at.toJSON()),
|
audioTracks: this.audioTracks.map((at) => at.toJSON()),
|
||||||
videoTrack: this.videoTrack?.toJSON() || null,
|
videoTrack: this.videoTrack?.toJSON() || null,
|
||||||
libraryItem: libraryItem?.toJSONExpanded() || null
|
libraryItem: libraryItem?.toJSONExpanded() || null
|
||||||
}
|
}
|
||||||
@ -182,7 +182,8 @@ class PlaybackSession {
|
|||||||
return this.libraryItemId
|
return this.libraryItemId
|
||||||
}
|
}
|
||||||
|
|
||||||
get progress() { // Value between 0 and 1
|
get progress() {
|
||||||
|
// Value between 0 and 1
|
||||||
if (!this.duration) return 0
|
if (!this.duration) return 0
|
||||||
return Math.max(0, Math.min(this.currentTime / this.duration, 1))
|
return Math.max(0, Math.min(this.currentTime / this.duration, 1))
|
||||||
}
|
}
|
||||||
@ -205,9 +206,9 @@ class PlaybackSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setData(libraryItem, user, mediaPlayer, deviceInfo, startTime, episodeId = null) {
|
setData(libraryItem, userId, mediaPlayer, deviceInfo, startTime, episodeId = null) {
|
||||||
this.id = uuidv4()
|
this.id = uuidv4()
|
||||||
this.userId = user.id
|
this.userId = userId
|
||||||
this.libraryId = libraryItem.libraryId
|
this.libraryId = libraryItem.libraryId
|
||||||
this.libraryItemId = libraryItem.id
|
this.libraryItemId = libraryItem.id
|
||||||
this.bookId = episodeId ? null : libraryItem.media.id
|
this.bookId = episodeId ? null : libraryItem.media.id
|
||||||
@ -258,4 +259,4 @@ class PlaybackSession {
|
|||||||
return date.format(new Date(), 'YYYY-MM-DD') !== this.date
|
return date.format(new Date(), 'YYYY-MM-DD') !== this.date
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = PlaybackSession
|
module.exports = PlaybackSession
|
||||||
|
Loading…
x
Reference in New Issue
Block a user