feat: ALTの永続化

This commit is contained in:
usbharu 2023-11-15 20:17:02 +09:00
parent 58b0931a49
commit 94065578b4
6 changed files with 18 additions and 7 deletions

View File

@ -133,7 +133,8 @@ class APNoteServiceImpl(
RemoteMedia(
(it.name ?: it.url)!!,
it.url!!,
it.mediaType ?: "application/octet-stream"
it.mediaType ?: "application/octet-stream",
description = it.name
)
)
}

View File

@ -13,7 +13,7 @@ class HttpClientConfig {
fun httpClient(): HttpClient = HttpClient(CIO).config {
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.INFO
level = LogLevel.ALL
}
install(HttpCache) {
}

View File

@ -11,5 +11,6 @@ data class Media(
val thumbnailUrl: String?,
val type: FileType,
val mimeType: MimeType,
val blurHash: String?
val blurHash: String?,
val description: String? = null
)

View File

@ -28,6 +28,8 @@ class MediaRepositoryImpl(private val idGenerateService: IdGenerateService) : Me
it[thumbnailUrl] = media.thumbnailUrl
it[type] = media.type.ordinal
it[blurhash] = media.blurHash
it[mimeType] = media.mimeType.type + "/" + media.mimeType.subtype
it[description] = media.description
}
} else {
Media.insert {
@ -38,6 +40,8 @@ class MediaRepositoryImpl(private val idGenerateService: IdGenerateService) : Me
it[thumbnailUrl] = media.thumbnailUrl
it[type] = media.type.ordinal
it[blurhash] = media.blurHash
it[mimeType] = media.mimeType.type + "/" + media.mimeType.subtype
it[description] = media.description
}
}
return media
@ -71,7 +75,8 @@ fun ResultRow.toMedia(): EntityMedia {
thumbnailUrl = this[Media.thumbnailUrl],
type = fileType,
blurHash = this[Media.blurhash],
mimeType = MimeType(mimeType.substringBefore("/"), mimeType.substringAfter("/"), fileType)
mimeType = MimeType(mimeType.substringBefore("/"), mimeType.substringAfter("/"), fileType),
description = this[Media.description]
)
}
@ -86,7 +91,8 @@ fun ResultRow.toMediaOrNull(): EntityMedia? {
thumbnailUrl = this[Media.thumbnailUrl],
type = FileType.values().first { it.ordinal == this.getOrNull(Media.type) },
blurHash = this[Media.blurhash],
mimeType = MimeType(mimeType.substringBefore("/"), mimeType.substringAfter("/"), fileType)
mimeType = MimeType(mimeType.substringBefore("/"), mimeType.substringAfter("/"), fileType),
description = this[Media.description]
)
}
@ -99,5 +105,6 @@ object Media : Table("media") {
val type = integer("type")
val blurhash = varchar("blurhash", 255).nullable()
val mimeType = varchar("mime_type", 255)
val description = varchar("description", 4000).nullable()
override val primaryKey = PrimaryKey(id)
}

View File

@ -80,7 +80,8 @@ open class MediaServiceImpl(
thumbnailUrl = save.thumbnailUrl,
type = process.fileMimeType.fileType,
mimeType = process.fileMimeType,
blurHash = blurHash
blurHash = blurHash,
description = mediaRequest.description
)
)
}

View File

@ -3,5 +3,6 @@ package dev.usbharu.hideout.core.service.media
data class RemoteMedia(
val name: String,
val url: String,
val mediaType: String
val mediaType: String,
val description: String? = null
)