Fixed thumbnail on gallery info

This commit is contained in:
Pupil
2020-01-15 11:28:38 +09:00
parent e0ccac13c1
commit e81c189afc
3 changed files with 13 additions and 24 deletions

View File

@@ -54,17 +54,9 @@ fun subdomainFromURL(url: String, base: String? = null) : String {
if (!base.isNullOrBlank()) if (!base.isNullOrBlank())
retval = base retval = base
val r = Regex("""/galleries/\d*(\d)/""") val b = 16
var m = r.find(url) val r = Regex("""/[0-9a-f]/([0-9a-f]{2})/""")
var b = 10 val m = r.find(url) ?: return retval
if (m == null) {
b = 16
val r2 = Regex("""/[0-9a-f]/([0-9a-f]{2})/""")
m = r2.find(url)
if (m == null)
return retval
}
val g = m.groupValues[1].toIntOrNull(b) ?: return retval val g = m.groupValues[1].toIntOrNull(b) ?: return retval
@@ -84,15 +76,12 @@ fun fullPathFromHash(hash: String?) : String? {
} }
} }
fun urlFromHash(galleryID: Int, image: GalleryInfo, webp: String? = null) : String { @Suppress("NAME_SHADOWING", "UNUSED_PARAMETER")
val ext = webp ?: image.name.split('.').last() fun urlFromHash(galleryID: Int, image: GalleryInfo, dir: String? = null, ext: String? = null) : String {
return when { val ext = ext ?: dir ?: image.name.split('.').last()
image.hash.isNullOrBlank() -> val dir = dir ?: "images"
"$protocol//a.hitomi.la/galleries/$galleryID/${image.name}" return "$protocol//a.hitomi.la/$dir/${fullPathFromHash(image.hash)}.$ext"
else ->
"$protocol//a.hitomi.la/${webp?:"images"}/${fullPathFromHash(image.hash)}.$ext"
}
} }
fun urlFromUrlFromHash(galleryID: Int, image: GalleryInfo, webp: String? = null) = fun urlFromUrlFromHash(galleryID: Int, image: GalleryInfo, dir: String? = null, ext: String? = null, base: String? = null) =
urlFromURL(urlFromHash(galleryID, image, webp)) urlFromURL(urlFromHash(galleryID, image, dir, ext), base)

View File

@@ -68,8 +68,8 @@ fun getGallery(galleryID: Int) : Gallery {
href.slice(5 until href.indexOf('-')) href.slice(5 until href.indexOf('-'))
} }
val thumbnails = getGalleryInfo(galleryID).map { val thumbnails = getGalleryInfo(galleryID).map { galleryInfo ->
"$protocol//tn.hitomi.la/smalltn/$galleryID/${it.name}.jpg" urlFromUrlFromHash(galleryID, galleryInfo, "smalltn", "jpg", "tn")
} }
return Gallery(related, langList, cover, title, artists, groups, type, language, series, characters, tags, thumbnails) return Gallery(related, langList, cover, title, artists, groups, type, language, series, characters, tags, thumbnails)

View File

@@ -68,7 +68,7 @@ class UnitTest {
@Test @Test
fun test_getGallery() { fun test_getGallery() {
val gallery = getGallery(1510566) val gallery = getGallery(1552751)
print(gallery) print(gallery)
} }