mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-09-10 17:58:02 +02:00
Fixed a few type issues
This commit is contained in:
parent
311ac7104e
commit
d8f07eb956
@ -18,14 +18,14 @@ class FolderWatcher extends EventEmitter {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
|
|
||||||
/** @type {{id:string, name:string, libraryFolders:import('./models/Folder')[], paths:string[], watcher:Watcher[]}[]} */
|
/** @type {{id:string, name:string, libraryFolders:import('./models/LibraryFolder')[], paths:string[], watcher:Watcher[]}[]} */
|
||||||
this.libraryWatchers = []
|
this.libraryWatchers = []
|
||||||
/** @type {PendingFileUpdate[]} */
|
/** @type {PendingFileUpdate[]} */
|
||||||
this.pendingFileUpdates = []
|
this.pendingFileUpdates = []
|
||||||
this.pendingDelay = 10000
|
this.pendingDelay = 10000
|
||||||
/** @type {NodeJS.Timeout} */
|
/** @type {NodeJS.Timeout | null} */
|
||||||
this.pendingTimeout = null
|
this.pendingTimeout = null
|
||||||
/** @type {Task} */
|
/** @type {Task | null} */
|
||||||
this.pendingTask = null
|
this.pendingTask = null
|
||||||
|
|
||||||
this.filesBeingAdded = new Set()
|
this.filesBeingAdded = new Set()
|
||||||
@ -36,7 +36,7 @@ class FolderWatcher extends EventEmitter {
|
|||||||
this.ignoreDirs = []
|
this.ignoreDirs = []
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
this.pendingDirsToRemoveFromIgnore = []
|
this.pendingDirsToRemoveFromIgnore = []
|
||||||
/** @type {NodeJS.Timeout} */
|
/** @type {NodeJS.Timeout | null} */
|
||||||
this.removeFromIgnoreTimer = null
|
this.removeFromIgnoreTimer = null
|
||||||
|
|
||||||
this.disabled = false
|
this.disabled = false
|
||||||
|
@ -110,12 +110,12 @@ class LogManager {
|
|||||||
const exists = await fs.pathExists(fullPath)
|
const exists = await fs.pathExists(fullPath)
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
Logger.error(TAG, 'Invalid log dne ' + fullPath)
|
Logger.error(TAG, 'Invalid log dne ' + fullPath)
|
||||||
this.dailyLogFiles = this.dailyLogFiles.filter(dlf => dlf !== filename)
|
this.dailyLogFiles = this.dailyLogFiles.filter((dlf) => dlf !== filename)
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
await fs.unlink(fullPath)
|
await fs.unlink(fullPath)
|
||||||
Logger.info(TAG, 'Removed daily log: ' + filename)
|
Logger.info(TAG, 'Removed daily log: ' + filename)
|
||||||
this.dailyLogFiles = this.dailyLogFiles.filter(dlf => dlf !== filename)
|
this.dailyLogFiles = this.dailyLogFiles.filter((dlf) => dlf !== filename)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(TAG, 'Failed to unlink log file ' + fullPath)
|
Logger.error(TAG, 'Failed to unlink log file ' + fullPath)
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ class LogManager {
|
|||||||
const logsDir = Path.join(global.MetadataPath, 'logs')
|
const logsDir = Path.join(global.MetadataPath, 'logs')
|
||||||
await fs.ensureDir(logsDir)
|
await fs.ensureDir(logsDir)
|
||||||
const crashLogPath = Path.join(logsDir, 'crash_logs.txt')
|
const crashLogPath = Path.join(logsDir, 'crash_logs.txt')
|
||||||
return fs.writeFile(crashLogPath, line, { flag: "a+" }).catch((error) => {
|
return fs.writeFile(crashLogPath, line, { flag: 'a+' }).catch((error) => {
|
||||||
console.log('[LogManager] Appended crash log', error)
|
console.log('[LogManager] Appended crash log', error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@ async function writeMetadataFileForItem(libraryItem) {
|
|||||||
const storeMetadataWithItem = global.ServerSettings.storeMetadataWithItem && !libraryItem.isFile
|
const storeMetadataWithItem = global.ServerSettings.storeMetadataWithItem && !libraryItem.isFile
|
||||||
const metadataPath = storeMetadataWithItem ? libraryItem.path : Path.join(global.MetadataPath, 'items', libraryItem.id)
|
const metadataPath = storeMetadataWithItem ? libraryItem.path : Path.join(global.MetadataPath, 'items', libraryItem.id)
|
||||||
const metadataFilepath = fileUtils.filePathToPOSIX(Path.join(metadataPath, 'metadata.json'))
|
const metadataFilepath = fileUtils.filePathToPOSIX(Path.join(metadataPath, 'metadata.json'))
|
||||||
if ((await fsExtra.pathExists(metadataFilepath))) {
|
if (await fsExtra.pathExists(metadataFilepath)) {
|
||||||
// Metadata file already exists do nothing
|
// Metadata file already exists do nothing
|
||||||
return null
|
return false
|
||||||
}
|
}
|
||||||
Logger.info(`[absMetadataMigration] metadata file not found at "${metadataFilepath}" - creating`)
|
Logger.info(`[absMetadataMigration] metadata file not found at "${metadataFilepath}" - creating`)
|
||||||
|
|
||||||
@ -27,20 +27,24 @@ async function writeMetadataFileForItem(libraryItem) {
|
|||||||
const metadataJson = libraryItem.media.getAbsMetadataJson()
|
const metadataJson = libraryItem.media.getAbsMetadataJson()
|
||||||
|
|
||||||
// Save to file
|
// Save to file
|
||||||
const success = await fsExtra.writeFile(metadataFilepath, JSON.stringify(metadataJson, null, 2)).then(() => true).catch((error) => {
|
const success = await fsExtra
|
||||||
Logger.error(`[absMetadataMigration] failed to save metadata file at "${metadataFilepath}"`, error.message || error)
|
.writeFile(metadataFilepath, JSON.stringify(metadataJson, null, 2))
|
||||||
return false
|
.then(() => true)
|
||||||
})
|
.catch((error) => {
|
||||||
|
Logger.error(`[absMetadataMigration] failed to save metadata file at "${metadataFilepath}"`, error.message || error)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
|
||||||
if (!success) return false
|
if (!success) return false
|
||||||
if (!storeMetadataWithItem) return true // No need to do anything else
|
if (!storeMetadataWithItem) return true // No need to do anything else
|
||||||
|
|
||||||
// Safety check to make sure library file with the same path isnt already there
|
// Safety check to make sure library file with the same path isnt already there
|
||||||
libraryItem.libraryFiles = libraryItem.libraryFiles.filter(lf => lf.metadata.path !== metadataFilepath)
|
libraryItem.libraryFiles = libraryItem.libraryFiles.filter((lf) => lf.metadata.path !== metadataFilepath)
|
||||||
|
|
||||||
// Put new library file in library item
|
// Put new library file in library item
|
||||||
const newLibraryFile = new LibraryFile()
|
const newLibraryFile = new LibraryFile()
|
||||||
await newLibraryFile.setDataFromPath(metadataFilepath, 'metadata.json')
|
await newLibraryFile.setDataFromPath(metadataFilepath, 'metadata.json')
|
||||||
|
// TODO: BUGBUG - this shouldn't be JSON and it may not be the right type LibraryFileObject
|
||||||
libraryItem.libraryFiles.push(newLibraryFile.toJSON())
|
libraryItem.libraryFiles.push(newLibraryFile.toJSON())
|
||||||
|
|
||||||
// Update library item timestamps and total size
|
// Update library item timestamps and total size
|
||||||
@ -49,15 +53,18 @@ async function writeMetadataFileForItem(libraryItem) {
|
|||||||
libraryItem.mtime = libraryItemDirTimestamps.mtimeMs
|
libraryItem.mtime = libraryItemDirTimestamps.mtimeMs
|
||||||
libraryItem.ctime = libraryItemDirTimestamps.ctimeMs
|
libraryItem.ctime = libraryItemDirTimestamps.ctimeMs
|
||||||
let size = 0
|
let size = 0
|
||||||
libraryItem.libraryFiles.forEach((lf) => size += (!isNaN(lf.metadata.size) ? Number(lf.metadata.size) : 0))
|
libraryItem.libraryFiles.forEach((lf) => (size += !isNaN(lf.metadata.size) ? Number(lf.metadata.size) : 0))
|
||||||
libraryItem.size = size
|
libraryItem.size = size
|
||||||
}
|
}
|
||||||
|
|
||||||
libraryItem.changed('libraryFiles', true)
|
libraryItem.changed('libraryFiles', true)
|
||||||
return libraryItem.save().then(() => true).catch((error) => {
|
return libraryItem
|
||||||
Logger.error(`[absMetadataMigration] failed to save libraryItem "${libraryItem.id}"`, error.message || error)
|
.save()
|
||||||
return false
|
.then(() => true)
|
||||||
})
|
.catch((error) => {
|
||||||
|
Logger.error(`[absMetadataMigration] failed to save libraryItem "${libraryItem.id}"`, error.message || error)
|
||||||
|
return false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user