Add:Tasks widget in appbar for merging m4bs & remove old m4b merge routes

This commit is contained in:
advplyr 2022-10-02 14:16:17 -05:00
parent 441b8c5bb7
commit 39979ff8a3
16 changed files with 285 additions and 457 deletions

View file

@ -1,122 +0,0 @@
const { AudioMimeType } = require('../utils/constants')
const { getAudioMimeTypeFromExtname } = require('../utils/fileUtils')
const DEFAULT_EXPIRATION = 1000 * 60 * 60 // 60 minutes
const DEFAULT_TIMEOUT = 1000 * 60 * 30 // 30 minutes
class AbManagerTask {
constructor() {
this.id = null
this.libraryItemId = null
this.libraryItemPath = null
this.type = null
this.dirpath = null
this.path = null
this.ext = null
this.filename = null
this.size = 0
this.toneMetadataObject = null
this.originalTrackPaths = []
this.userId = null
this.isReady = false
this.isTimedOut = false
this.startedAt = null
this.finishedAt = null
this.expiresAt = null
this.expirationTimeMs = 0
this.timeoutTimeMs = 0
this.timeoutTimer = null
this.expirationTimer = null
}
get mimeType() {
return getAudioMimeTypeFromExtname(this.ext) || AudioMimeType.MP3
}
toJSON() {
return {
id: this.id,
libraryItemId: this.libraryItemId,
type: this.type,
dirpath: this.dirpath,
path: this.path,
ext: this.ext,
filename: this.filename,
size: this.size,
userId: this.userId,
isReady: this.isReady,
startedAt: this.startedAt,
finishedAt: this.finishedAt,
expirationSeconds: this.expirationSeconds,
toneMetadataObject: this.toneMetadataObject
}
}
setData(downloadData) {
downloadData.startedAt = Date.now()
downloadData.isProcessing = true
this.construct(downloadData)
}
construct(download) {
this.id = download.id
this.libraryItemId = download.libraryItemId
this.libraryItemPath = download.libraryItemPath
this.type = download.type
this.dirpath = download.dirpath
this.path = download.path
this.ext = download.ext
this.filename = download.filename
this.size = download.size || 0
this.originalTrackPaths = download.originalTrackPaths
this.userId = download.userId
this.isReady = !!download.isReady
this.startedAt = download.startedAt
this.finishedAt = download.finishedAt || null
this.expirationTimeMs = download.expirationTimeMs || DEFAULT_EXPIRATION
this.timeoutTimeMs = download.timeoutTimeMs || DEFAULT_TIMEOUT
this.expiresAt = download.expiresAt || null
}
setComplete(fileSize) {
this.finishedAt = Date.now()
this.size = fileSize
this.isReady = true
this.expiresAt = this.finishedAt + this.expirationTimeMs
}
setExpirationTimer(callback) {
this.expirationTimer = setTimeout(() => {
if (callback) {
callback(this)
}
}, this.expirationTimeMs)
}
setTimeoutTimer(callback) {
this.timeoutTimer = setTimeout(() => {
if (callback) {
this.isTimedOut = true
callback(this)
}
}, this.timeoutTimeMs)
}
clearTimeoutTimer() {
clearTimeout(this.timeoutTimer)
}
clearExpirationTimer() {
clearTimeout(this.expirationTimer)
}
}
module.exports = AbManagerTask

56
server/objects/Task.js Normal file
View file

@ -0,0 +1,56 @@
const { getId } = require('../utils/index')
class Task {
constructor() {
this.id = null
this.action = null // e.g. embed-metadata, encode-m4b, etc
this.data = null // additional info for the action like libraryItemId
this.title = null
this.description = null
this.error = null
this.isFailed = false
this.isFinished = false
this.startedAt = null
this.finishedAt = null
}
toJSON() {
return {
id: this.id,
action: this.action,
data: this.data ? { ...this.data } : {},
title: this.title,
description: this.description,
error: this.error,
isFailed: this.isFailed,
isFinished: this.isFinished,
startedAt: this.startedAt,
finishedAt: this.finishedAt
}
}
setData(action, title, description, data = {}) {
this.id = getId(action)
this.action = action
this.data = { ...data }
this.title = title
this.description = description
this.startedAt = Date.now()
}
setFailed(message) {
this.error = message
this.isFailed = true
this.failedAt = Date.now()
this.setFinished()
}
setFinished() {
this.isFinished = true
this.finishedAt = Date.now()
}
}
module.exports = Task