From 717756deac10489e9a6665ee7b95b897ad41f36c Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 30 Nov 2023 01:19:22 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=83=AA=E3=83=A2=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=81=AE=E3=83=A1=E3=83=87=E3=82=A3=E3=82=A2=E3=82=92=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=99=E3=82=8B=E3=81=A8=E3=81=8D=E3=81=ABResourceR?= =?UTF-8?q?esolver=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../media/RemoteMediaDownloadServiceImpl.kt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMediaDownloadServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMediaDownloadServiceImpl.kt index 6bc9040c..bd1014f8 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMediaDownloadServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/media/RemoteMediaDownloadServiceImpl.kt @@ -1,10 +1,6 @@ package dev.usbharu.hideout.core.service.media -import io.ktor.client.* -import io.ktor.client.request.* -import io.ktor.client.statement.* -import io.ktor.http.* -import io.ktor.utils.io.jvm.javaio.* +import dev.usbharu.hideout.core.service.resource.KtorResourceResolveService import org.slf4j.LoggerFactory import org.springframework.stereotype.Service import java.nio.file.Files @@ -12,16 +8,16 @@ import java.nio.file.Path import kotlin.io.path.outputStream @Service -class RemoteMediaDownloadServiceImpl(private val httpClient: HttpClient) : RemoteMediaDownloadService { +class RemoteMediaDownloadServiceImpl(private val resourceResolveService: KtorResourceResolveService) : + RemoteMediaDownloadService { override suspend fun download(url: String): Path { logger.info("START Download remote file. url: {}", url) - val httpResponse = httpClient.get(url) - httpResponse.contentLength() + val httpResponse = resourceResolveService.resolve(url).body() val createTempFile = Files.createTempFile("hideout-remote-download", ".tmp") logger.debug("Save to {} url: {} ", createTempFile, url) - httpResponse.bodyAsChannel().toInputStream().use { inputStream -> + httpResponse.use { inputStream -> createTempFile.outputStream().use { inputStream.transferTo(it) }