fixed #31 on libpupil
#TODO: fix app side to completely resolve the issue
This commit is contained in:
@@ -51,7 +51,7 @@ fun subdomainFromGalleryID(g: Int) : String {
|
||||
fun subdomainFromURL(url: String, base: String? = null) : String {
|
||||
var retval = "a"
|
||||
|
||||
if (!base.isNullOrEmpty())
|
||||
if (!base.isNullOrBlank())
|
||||
retval = base
|
||||
|
||||
val r = Regex("""/galleries/\d*(\d)/""")
|
||||
@@ -60,7 +60,7 @@ fun subdomainFromURL(url: String, base: String? = null) : String {
|
||||
|
||||
if (m == null) {
|
||||
b = 16
|
||||
val r2 = Regex("""/images/[0-9a-f]/([0-9a-f]{2})/""")
|
||||
val r2 = Regex("""/[0-9a-f]/([0-9a-f]{2})/""")
|
||||
m = r2.find(url)
|
||||
if (m == null)
|
||||
return retval
|
||||
@@ -84,12 +84,15 @@ fun fullPathFromHash(hash: String?) : String? {
|
||||
}
|
||||
}
|
||||
|
||||
fun urlFromHash(galleryID: Int, image: GalleryInfo, oldMethod: Boolean) : String {
|
||||
fun urlFromHash(galleryID: Int, image: GalleryInfo, webp: String? = null) : String {
|
||||
val ext = webp ?: image.name.split('.').last()
|
||||
return when {
|
||||
oldMethod or image.hash.isNullOrEmpty() -> "$protocol//a.hitomi.la/galleries/$galleryID/${image.name}"
|
||||
else -> "$protocol//a.hitomi.la/images/${fullPathFromHash(image.hash)}.${image.name.split('.').last()}"
|
||||
image.hash.isNullOrBlank() ->
|
||||
"$protocol//a.hitomi.la/galleries/$galleryID/${image.name}"
|
||||
else ->
|
||||
"$protocol//a.hitomi.la/${webp?:"images"}/${fullPathFromHash(image.hash)}.$ext"
|
||||
}
|
||||
}
|
||||
|
||||
fun urlFromUrlFromHash(galleryID: Int, image: GalleryInfo, oldMethod: Boolean = false) =
|
||||
urlFromURL(urlFromHash(galleryID, image, oldMethod))
|
||||
fun urlFromUrlFromHash(galleryID: Int, image: GalleryInfo, webp: String? = null) =
|
||||
urlFromURL(urlFromHash(galleryID, image, webp))
|
||||
@@ -87,9 +87,9 @@ class UnitTest {
|
||||
|
||||
@Test
|
||||
fun test_urlFromUrlFromHash() {
|
||||
val url = urlFromUrlFromHash(1510702, GalleryInfo(
|
||||
210, "56e9e1b8bb72194777ed93fee11b06070b905039dd11348b070bcf1793aaed7b", 1, "6.jpg", 300
|
||||
))
|
||||
val url = urlFromUrlFromHash(1531795, GalleryInfo(
|
||||
212, "719d46a7556be0d0021c5105878507129b5b3308b02cf67f18901b69dbb3b5ef", 1, "00.jpg", 300
|
||||
), "webp")
|
||||
|
||||
print(url)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user