mirror of https://github.com/usbharu/Hideout.git
fix: リモートのメディアを取得するときにResourceResolverを使用するように変更
This commit is contained in:
parent
3fd051d014
commit
717756deac
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue