Fallback chapter name if it ends up as blank (#9220)

* change the directory's name for a download when the chapter's name is only composed of numbers or is blank

* maj in case the chapter name is blank or empty

* clean code
This commit is contained in:
Pauline 2023-04-22 17:11:56 +02:00 committed by GitHub
parent 03a344e9c1
commit 41cc1fe723
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -138,14 +138,26 @@ class DownloadProvider(
* @param chapterScanlator scanlator of the chapter to query * @param chapterScanlator scanlator of the chapter to query
*/ */
fun getChapterDirName(chapterName: String, chapterScanlator: String?): String { fun getChapterDirName(chapterName: String, chapterScanlator: String?): String {
val newChapterName = sanitizeChapterName(chapterName)
return DiskUtil.buildValidFilename( return DiskUtil.buildValidFilename(
when { when {
chapterScanlator.isNullOrBlank().not() -> "${chapterScanlator}_$chapterName" chapterScanlator.isNullOrBlank().not() -> "${chapterScanlator}_$newChapterName"
else -> chapterName else -> newChapterName
}, },
) )
} }
/**
* Return the new name for the chapter (in case it's empty or blank)
*
* @param chapterName the name of the chapter
*/
private fun sanitizeChapterName(chapterName: String): String {
return chapterName.ifBlank {
"Chapter"
}
}
fun isChapterDirNameChanged(oldChapter: Chapter, newChapter: Chapter): Boolean { fun isChapterDirNameChanged(oldChapter: Chapter, newChapter: Chapter): Boolean {
return oldChapter.name != newChapter.name || return oldChapter.name != newChapter.name ||
oldChapter.scanlator?.takeIf { it.isNotBlank() } != newChapter.scanlator?.takeIf { it.isNotBlank() } oldChapter.scanlator?.takeIf { it.isNotBlank() } != newChapter.scanlator?.takeIf { it.isNotBlank() }