mirror of https://github.com/usbharu/Hideout.git
feat: メディア処理を追加
This commit is contained in:
parent
d903d558c1
commit
a93131b5dc
|
@ -16,4 +16,31 @@
|
|||
|
||||
package dev.usbharu.hideout.core.application.media
|
||||
|
||||
class Media
|
||||
import dev.usbharu.hideout.core.domain.model.media.FileType
|
||||
import dev.usbharu.hideout.core.domain.model.media.Media
|
||||
import dev.usbharu.hideout.core.domain.model.media.MimeType
|
||||
import java.net.URI
|
||||
|
||||
data class Media(
|
||||
val name: String,
|
||||
val url: URI,
|
||||
val thumbprintURI: URI?,
|
||||
val type: FileType,
|
||||
val mimeType: MimeType,
|
||||
val blurHash: String?,
|
||||
val description: String?
|
||||
) {
|
||||
companion object {
|
||||
fun of(media: Media): dev.usbharu.hideout.core.application.media.Media {
|
||||
return Media(
|
||||
media.name.name,
|
||||
media.url,
|
||||
media.thumbnailUrl,
|
||||
media.type,
|
||||
media.mimeType,
|
||||
media.blurHash?.hash,
|
||||
media.description?.description
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package dev.usbharu.hideout.core.application.media
|
||||
|
||||
import java.net.URI
|
||||
import java.nio.file.Path
|
||||
|
||||
data class UploadMedia(val path: Path)
|
||||
data class UploadMedia(val path: Path, val name: String, val remoteUri: URI?, val description: String?)
|
||||
|
|
|
@ -19,9 +19,22 @@ package dev.usbharu.hideout.core.application.media
|
|||
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
|
||||
import dev.usbharu.hideout.core.application.shared.CommandExecutor
|
||||
import dev.usbharu.hideout.core.application.shared.Transaction
|
||||
import dev.usbharu.hideout.core.domain.model.media.*
|
||||
import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService
|
||||
import dev.usbharu.hideout.core.external.media.MediaProcessor
|
||||
import dev.usbharu.hideout.core.external.mediastore.MediaStore
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.stereotype.Service
|
||||
import dev.usbharu.hideout.core.domain.model.media.Media as MediaModel
|
||||
|
||||
class UploadMediaApplicationService(transaction: Transaction) : AbstractApplicationService<UploadMedia, Media>(
|
||||
@Service
|
||||
class UploadMediaApplicationService(
|
||||
private val mediaProcessor: MediaProcessor,
|
||||
private val mediaStore: MediaStore,
|
||||
private val mediaRepository: MediaRepository,
|
||||
private val idGenerateService: IdGenerateService,
|
||||
transaction: Transaction
|
||||
) : AbstractApplicationService<UploadMedia, Media>(
|
||||
transaction, logger
|
||||
) {
|
||||
companion object {
|
||||
|
@ -29,6 +42,30 @@ class UploadMediaApplicationService(transaction: Transaction) : AbstractApplicat
|
|||
}
|
||||
|
||||
override suspend fun internalExecute(command: UploadMedia, executor: CommandExecutor): Media {
|
||||
TODO()
|
||||
val process = mediaProcessor.process(command.path)
|
||||
val id = idGenerateService.generateId()
|
||||
val thumbnailUri = if (process.thumbnailPath != null) {
|
||||
mediaStore.upload(process.thumbnailPath, "thumbnail-$id")
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val uri = mediaStore.upload(process.path, id.toString())
|
||||
|
||||
val media = MediaModel(
|
||||
MediaId(id),
|
||||
MediaName(command.name),
|
||||
uri,
|
||||
command.remoteUri,
|
||||
thumbnailUri,
|
||||
process.fileType,
|
||||
process.mimeType,
|
||||
MediaBlurHash(process.blurHash),
|
||||
command.description?.let { MediaDescription(it) }
|
||||
)
|
||||
|
||||
mediaRepository.save(media)
|
||||
|
||||
return Media.of(media)
|
||||
|
||||
}
|
||||
}
|
|
@ -18,10 +18,10 @@ package dev.usbharu.hideout.core.domain.model.media
|
|||
|
||||
import java.net.URI
|
||||
|
||||
data class Media(
|
||||
class Media(
|
||||
val id: MediaId,
|
||||
val name: MediaName,
|
||||
val url: URI,
|
||||
url: URI,
|
||||
val remoteUrl: URI?,
|
||||
val thumbnailUrl: URI?,
|
||||
val type: FileType,
|
||||
|
@ -29,6 +29,12 @@ data class Media(
|
|||
val blurHash: MediaBlurHash?,
|
||||
val description: MediaDescription? = null,
|
||||
) {
|
||||
var url = url
|
||||
private set
|
||||
|
||||
fun setUrl(url: URI) {
|
||||
this.url = url
|
||||
}
|
||||
override fun toString(): String {
|
||||
return "Media(" +
|
||||
"id=$id, " +
|
||||
|
|
8
hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/mediastore/MediaStore.kt
vendored
Normal file
8
hideout-core/src/main/kotlin/dev/usbharu/hideout/core/external/mediastore/MediaStore.kt
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
package dev.usbharu.hideout.core.external.mediastore
|
||||
|
||||
import java.net.URI
|
||||
import java.nio.file.Path
|
||||
|
||||
interface MediaStore {
|
||||
suspend fun upload(path: Path, id: String): URI
|
||||
}
|
Loading…
Reference in New Issue