fix: リモートのメディアを取得するときにResourceResolverを使用するように変更

This commit is contained in:
usbharu 2023-11-30 01:19:22 +09:00
parent 3fd051d014
commit 717756deac
1 changed files with 5 additions and 9 deletions

View File

@ -1,10 +1,6 @@
package dev.usbharu.hideout.core.service.media package dev.usbharu.hideout.core.service.media
import io.ktor.client.* import dev.usbharu.hideout.core.service.resource.KtorResourceResolveService
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.utils.io.jvm.javaio.*
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import java.nio.file.Files import java.nio.file.Files
@ -12,16 +8,16 @@ import java.nio.file.Path
import kotlin.io.path.outputStream import kotlin.io.path.outputStream
@Service @Service
class RemoteMediaDownloadServiceImpl(private val httpClient: HttpClient) : RemoteMediaDownloadService { class RemoteMediaDownloadServiceImpl(private val resourceResolveService: KtorResourceResolveService) :
RemoteMediaDownloadService {
override suspend fun download(url: String): Path { override suspend fun download(url: String): Path {
logger.info("START Download remote file. url: {}", url) logger.info("START Download remote file. url: {}", url)
val httpResponse = httpClient.get(url) val httpResponse = resourceResolveService.resolve(url).body()
httpResponse.contentLength()
val createTempFile = Files.createTempFile("hideout-remote-download", ".tmp") val createTempFile = Files.createTempFile("hideout-remote-download", ".tmp")
logger.debug("Save to {} url: {} ", createTempFile, url) logger.debug("Save to {} url: {} ", createTempFile, url)
httpResponse.bodyAsChannel().toInputStream().use { inputStream -> httpResponse.use { inputStream ->
createTempFile.outputStream().use { createTempFile.outputStream().use {
inputStream.transferTo(it) inputStream.transferTo(it)
} }