-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
29 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
save-backend/src/main/kotlin/com/saveourtool/save/backend/storage/AvatarS3Storage.kt
This file was deleted.
Oops, something went wrong.
56 changes: 25 additions & 31 deletions
56
save-backend/src/main/kotlin/com/saveourtool/save/backend/storage/AvatarStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,52 @@ | ||
/** | ||
* Storage for avatars + key for this storage | ||
*/ | ||
|
||
package com.saveourtool.save.backend.storage | ||
|
||
import com.saveourtool.save.backend.configs.ConfigProperties | ||
import com.saveourtool.save.storage.AbstractFileBasedStorage | ||
import com.saveourtool.save.storage.AbstractS3Storage | ||
import com.saveourtool.save.storage.concatS3Key | ||
import com.saveourtool.save.storage.s3KeyToParts | ||
import com.saveourtool.save.utils.AvatarType | ||
import com.saveourtool.save.utils.orNotFound | ||
import org.springframework.stereotype.Service | ||
import reactor.core.publisher.Flux | ||
import reactor.core.publisher.Mono | ||
import software.amazon.awssdk.services.s3.S3AsyncClient | ||
import java.nio.ByteBuffer | ||
import java.nio.file.Path | ||
import kotlin.io.path.div | ||
import kotlin.io.path.name | ||
|
||
/** | ||
* Storage for Avatars | ||
* Currently, key is (AvatarType, ObjectName) | ||
*/ | ||
@Service | ||
class AvatarStorage(configProperties: ConfigProperties) : | ||
AbstractFileBasedStorage<AvatarKey>(Path.of(configProperties.fileStorage.location) / "images" / "avatars") { | ||
/** | ||
* @param rootDir | ||
* @param pathToContent | ||
* @return [AvatarKey] object is built by [Path] | ||
*/ | ||
override fun buildKey(rootDir: Path, pathToContent: Path): AvatarKey = AvatarKey( | ||
type = AvatarType.findByUrlPath(pathToContent.parent.name) | ||
.orNotFound { | ||
"Not supported type for path: ${pathToContent.parent.name}" | ||
}, | ||
objectName = pathToContent.name, | ||
) | ||
class AvatarStorage( | ||
configProperties: ConfigProperties, | ||
s3Client: S3AsyncClient, | ||
) : AbstractS3Storage<AvatarKey>( | ||
s3Client, | ||
configProperties.s3Storage.bucketName, | ||
concatS3Key(configProperties.s3Storage.prefix, "images", "avatars") | ||
) { | ||
override fun buildKey(s3KeySuffix: String): AvatarKey { | ||
val (typeStr, objectName) = s3KeySuffix.s3KeyToParts() | ||
return AvatarKey( | ||
type = AvatarType.findByUrlPath(typeStr) | ||
.orNotFound { | ||
"Not supported type for path: $typeStr" | ||
}, | ||
objectName = objectName, | ||
) | ||
} | ||
|
||
override fun buildS3KeySuffix(key: AvatarKey): String = concatS3Key(key.type.urlPath, key.objectName) | ||
|
||
/** | ||
* @param key | ||
* @param content | ||
* @return `Mono` with file size | ||
*/ | ||
fun upsert(key: AvatarKey, content: Flux<ByteBuffer>): Mono<Long> = list() | ||
.filter { it.objectName == key.objectName } | ||
.filter { it == key } | ||
.singleOrEmpty() | ||
.flatMap { delete(it) } | ||
.switchIfEmpty(Mono.just(true)) | ||
.flatMap { upload(key, content) } | ||
|
||
/** | ||
* @param rootDir | ||
* @param key | ||
* @return [Path] is built by [AvatarKey] object | ||
*/ | ||
override fun buildPathToContent(rootDir: Path, key: AvatarKey): Path = rootDir.resolve(key.type.urlPath) | ||
.resolve(key.objectName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
save-backend/src/main/kotlin/com/saveourtool/save/backend/storage/MigrationAvatarStorage.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.