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) }