Update:Create library endpoint to create using new model, adding additional validation

This commit is contained in:
advplyr 2024-08-22 17:39:28 -05:00
parent 1c0d6e9c67
commit 8774e6be71
4 changed files with 134 additions and 89 deletions

View file

@ -45,6 +45,35 @@ class Library extends Model {
this.updatedAt
}
/**
*
* @param {string} mediaType
* @returns
*/
static getDefaultLibrarySettingsForMediaType(mediaType) {
if (mediaType === 'podcast') {
return {
coverAspectRatio: 1, // Square
disableWatcher: false,
autoScanCronExpression: null,
podcastSearchRegion: 'us'
}
} else {
return {
coverAspectRatio: 1, // Square
disableWatcher: false,
autoScanCronExpression: null,
skipMatchingMediaWithAsin: false,
skipMatchingMediaWithIsbn: false,
audiobooksOnly: false,
epubsAllowScriptedContent: false,
hideSingleBookSeries: false,
onlyShowLaterBooksInContinueSeries: false,
metadataPrecedence: ['folderStructure', 'audioMetatags', 'nfoFile', 'txtFiles', 'opfFile', 'absMetadata']
}
}
}
/**
* Get all old libraries
* @returns {Promise<oldLibrary[]>}
@ -89,28 +118,6 @@ class Library extends Model {
})
}
/**
* @param {object} oldLibrary
* @returns {Library|null}
*/
static async createFromOld(oldLibrary) {
const library = this.getFromOld(oldLibrary)
library.libraryFolders = oldLibrary.folders.map((folder) => {
return {
id: folder.id,
path: folder.fullPath
}
})
return this.create(library, {
include: this.sequelize.models.libraryFolder
}).catch((error) => {
Logger.error(`[Library] Failed to create library ${library.id}`, error)
return null
})
}
/**
* Update library and library folders
* @param {object} oldLibrary