mirror of https://github.com/usbharu/Hideout.git
feat: ファイルの削除に対応
This commit is contained in:
parent
60242693f9
commit
97cf5eac65
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue