feat: ファイルの削除に対応

This commit is contained in:
usbharu 2023-10-05 00:20:42 +09:00
parent 60242693f9
commit 97cf5eac65
2 changed files with 8 additions and 3 deletions

View File

@ -5,5 +5,5 @@ import dev.usbharu.hideout.domain.model.hideout.dto.SavedMedia
interface MediaDataStore { interface MediaDataStore {
suspend fun save(dataMediaSave: MediaSave): SavedMedia suspend fun save(dataMediaSave: MediaSave): SavedMedia
suspend fun delete(id: Long) suspend fun delete(id: String)
} }

View File

@ -11,6 +11,7 @@ import kotlinx.coroutines.withContext
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import software.amazon.awssdk.core.sync.RequestBody import software.amazon.awssdk.core.sync.RequestBody
import software.amazon.awssdk.services.s3.S3Client import software.amazon.awssdk.services.s3.S3Client
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest
import software.amazon.awssdk.services.s3.model.GetUrlRequest import software.amazon.awssdk.services.s3.model.GetUrlRequest
import software.amazon.awssdk.services.s3.model.PutObjectRequest import software.amazon.awssdk.services.s3.model.PutObjectRequest
@ -53,7 +54,11 @@ class S3MediaDataStore(private val s3Client: S3Client, private val storageConfig
) )
} }
override suspend fun delete(id: Long) { override suspend fun delete(id: String) {
TODO("Not yet implemented") val fileDeleteRequest = DeleteObjectRequest.builder().bucket(storageConfig.bucket).key(id).build()
val thumbnailDeleteRequest =
DeleteObjectRequest.builder().bucket(storageConfig.bucket).key("thumbnail-$id").build()
s3Client.deleteObject(fileDeleteRequest)
s3Client.deleteObject(thumbnailDeleteRequest)
} }
} }