From 99a8aa0ce01d8634fe69459b0257a04562aa6c8c Mon Sep 17 00:00:00 2001 From: dev-claw <53543762+dev-claw@users.noreply.github.com> Date: Fri, 26 Sep 2025 12:10:50 +0100 Subject: [PATCH] fixes #267 (#269) --- .../main/kotlin/me/vripper/host/ImxHost.kt | 56 +++---------------- 1 file changed, 7 insertions(+), 49 deletions(-) diff --git a/vripper-core/src/main/kotlin/me/vripper/host/ImxHost.kt b/vripper-core/src/main/kotlin/me/vripper/host/ImxHost.kt index 1fe1501..626832d 100644 --- a/vripper-core/src/main/kotlin/me/vripper/host/ImxHost.kt +++ b/vripper-core/src/main/kotlin/me/vripper/host/ImxHost.kt @@ -1,14 +1,9 @@ package me.vripper.host -import com.github.benmanes.caffeine.cache.Cache -import com.github.benmanes.caffeine.cache.Caffeine import me.vripper.entities.ImageEntity import me.vripper.exception.HostException import me.vripper.services.DownloadService.ImageDownloadContext -import me.vripper.utilities.ApplicationProperties.IMX_SUBDOMAINS import me.vripper.utilities.LoggerDelegate -import me.vripper.utilities.RequestLimit -import org.apache.hc.client5.http.classic.methods.HttpHead import org.apache.hc.client5.http.config.ConnectionConfig import org.apache.hc.client5.http.impl.classic.HttpClients import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager @@ -16,10 +11,6 @@ import java.util.concurrent.TimeUnit internal class ImxHost : Host("imx.to", 8) { - companion object { - private val resolvedHosts: Cache = - Caffeine.newBuilder().expireAfterAccess(5, TimeUnit.MINUTES).build() - } private val log by LoggerDelegate() @@ -39,47 +30,14 @@ internal class ImxHost : Host("imx.to", 8) { ): Pair { log.debug("Resolving name and image url for ${image.url}") val imgTitle = String.format("IMG_%04d", image.index + 1) - synchronized(image.postId.toString().intern()) { - val subDomain = resolvedHosts.getIfPresent(image.postId) - if (subDomain != null) { - val imgUrl = findPattern(image, subDomain) - return Pair( - imgTitle.ifEmpty { getDefaultImageName(imgUrl) }, imgUrl - ) - } else { - IMX_SUBDOMAINS.forEach { subDomain -> - val imgUrl = findPattern(image, subDomain) - val result = runCatching { - RequestLimit.getPermit(1) - val httpHead = HttpHead(imgUrl) - .also { - it.setAbsoluteRequestUri(true) - context.requests.add(it) - } - log.info("{}", httpHead) - failFastHttpClient.execute(httpHead) { response -> - if (response.code / 100 != 2) { - throw HostException("Invalid response code ${response.code}") - } - } - } - if (result.isSuccess) { - resolvedHosts.put(image.postId, subDomain) - return Pair( - imgTitle.ifEmpty { getDefaultImageName(imgUrl) }, imgUrl - ) - } - } - } - } - throw HostException("Unable to find full size image for ${image.url}") + val imgUrl = findPattern(image) + return Pair( + imgTitle.ifEmpty { getDefaultImageName(imgUrl) }, imgUrl + ) } - private fun findPattern(image: ImageEntity, subDomain: String): String = image.thumbUrl + private fun findPattern(image: ImageEntity): String = image.thumbUrl .replace("http:", "https:") - .replace("imx.to", subDomain) - .replace("upload/small/", "i/") - .replace("u/i/", "i/") - .replace("u/t/", "i/") - .replace("t/", "i/") + .replace("upload/small/", "u/i/") + .replace("u/t/", "u/i/") } \ No newline at end of file