mirror of https://github.com/usbharu/Hideout.git
feat: Spring Configurationを修正
This commit is contained in:
parent
bc186a4433
commit
aca1be114d
|
@ -8,13 +8,7 @@ hideout:
|
|||
private-key: "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC7VJTUt9Us8cKjMzEfYyjiWA4R4/M2bS1GB4t7NXp98C3SC6dVMvDuictGeurT8jNbvJZHtCSuYEvuNMoSfm76oqFvAp8Gy0iz5sxjZmSnXyCdPEovGhLa0VzMaQ8s+CLOyS56YyCFGeJZqgtzJ6GR3eqoYSW9b9UMvkBpZODSctWSNGj3P7jRFDO5VoTwCQAWbFnOjDfH5Ulgp2PKSQnSJP3AJLQNFNe7br1XbrhV//eO+t51mIpGSDCUv3E0DDFcWDTH9cXDTTlRZVEiR2BwpZOOkE/Z0/BVnhZYL71oZV34bKfWjQIt6V/isSMahdsAASACp4ZTGtwiVuNd9tybAgMBAAECggEBAKTmjaS6tkK8BlPXClTQ2vpz/N6uxDeS35mXpqasqskVlaAidgg/sWqpjXDbXr93otIMLlWsM+X0CqMDgSXKejLS2jx4GDjI1ZTXg++0AMJ8sJ74pWzVDOfmCEQ/7wXs3+cbnXhKriO8Z036q92Qc1+N87SI38nkGa0ABH9CN83HmQqt4fB7UdHzuIRe/me2PGhIq5ZBzj6h3BpoPGzEP+x3l9YmK8t/1cN0pqI+dQwYdgfGjackLu/2qH80MCF7IyQaseZUOJyKrCLtSD/Iixv/hzDEUPfOCjFDgTpzf3cwta8+oE4wHCo1iI1/4TlPkwmXx4qSXtmw4aQPz7IDQvECgYEA8KNThCO2gsC2I9PQDM/8Cw0O983WCDY+oi+7JPiNAJwv5DYBqEZB1QYdj06YD16XlC/HAZMsMku1na2TN0driwenQQWzoev3g2S7gRDoS/FCJSI3jJ+kjgtaA7Qmzlgk1TxODN+G1H91HW7t0l7VnL27IWyYo2qRRK3jzxqUiPUCgYEAx0oQs2reBQGMVZnApD1jeq7n4MvNLcPvt8b/eU9iUv6Y4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true
|
||||
endpoint: "http://localhost:8082/test-hideout"
|
||||
public-url: "http://localhost:8082/test-hideout"
|
||||
bucket: "test-hideout"
|
||||
region: "auto"
|
||||
access-key: ""
|
||||
secret-key: ""
|
||||
type: local
|
||||
|
||||
spring:
|
||||
flyway:
|
||||
|
|
|
@ -8,13 +8,7 @@ hideout:
|
|||
private-key: "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC7VJTUt9Us8cKjMzEfYyjiWA4R4/M2bS1GB4t7NXp98C3SC6dVMvDuictGeurT8jNbvJZHtCSuYEvuNMoSfm76oqFvAp8Gy0iz5sxjZmSnXyCdPEovGhLa0VzMaQ8s+CLOyS56YyCFGeJZqgtzJ6GR3eqoYSW9b9UMvkBpZODSctWSNGj3P7jRFDO5VoTwCQAWbFnOjDfH5Ulgp2PKSQnSJP3AJLQNFNe7br1XbrhV//eO+t51mIpGSDCUv3E0DDFcWDTH9cXDTTlRZVEiR2BwpZOOkE/Z0/BVnhZYL71oZV34bKfWjQIt6V/isSMahdsAASACp4ZTGtwiVuNd9tybAgMBAAECggEBAKTmjaS6tkK8BlPXClTQ2vpz/N6uxDeS35mXpqasqskVlaAidgg/sWqpjXDbXr93otIMLlWsM+X0CqMDgSXKejLS2jx4GDjI1ZTXg++0AMJ8sJ74pWzVDOfmCEQ/7wXs3+cbnXhKriO8Z036q92Qc1+N87SI38nkGa0ABH9CN83HmQqt4fB7UdHzuIRe/me2PGhIq5ZBzj6h3BpoPGzEP+x3l9YmK8t/1cN0pqI+dQwYdgfGjackLu/2qH80MCF7IyQaseZUOJyKrCLtSD/Iixv/hzDEUPfOCjFDgTpzf3cwta8+oE4wHCo1iI1/4TlPkwmXx4qSXtmw4aQPz7IDQvECgYEA8KNThCO2gsC2I9PQDM/8Cw0O983WCDY+oi+7JPiNAJwv5DYBqEZB1QYdj06YD16XlC/HAZMsMku1na2TN0driwenQQWzoev3g2S7gRDoS/FCJSI3jJ+kjgtaA7Qmzlgk1TxOD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2dPwVZ4WWC+9aGVd+Gyn1o0CLelf4rEjGoXbAAEgAqeGUxrcIlbjXfbcmwIDAQAB"
|
||||
storage:
|
||||
use-s3: true
|
||||
endpoint: "http://localhost:8082/test-hideout"
|
||||
public-url: "http://localhost:8082/test-hideout"
|
||||
bucket: "test-hideout"
|
||||
region: "auto"
|
||||
access-key: ""
|
||||
secret-key: ""
|
||||
type: local
|
||||
|
||||
spring:
|
||||
flyway:
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package dev.usbharu.hideout.application.config
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
|
||||
|
@ -10,6 +11,7 @@ import java.net.URI
|
|||
@Configuration
|
||||
class AwsConfig {
|
||||
@Bean
|
||||
@ConditionalOnProperty("hideout.storage.type", havingValue = "s3")
|
||||
fun s3Client(awsConfig: S3StorageConfig): S3Client {
|
||||
return S3Client.builder()
|
||||
.endpointOverride(URI.create(awsConfig.endpoint))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dev.usbharu.hideout.application.config
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
@ -13,9 +14,6 @@ class SpringConfig {
|
|||
@Autowired
|
||||
lateinit var config: ApplicationConfig
|
||||
|
||||
@Autowired
|
||||
lateinit var s3StorageConfig: S3StorageConfig
|
||||
|
||||
@Bean
|
||||
fun requestLoggingFilter(): CommonsRequestLoggingFilter {
|
||||
val loggingFilter = CommonsRequestLoggingFilter()
|
||||
|
@ -34,6 +32,7 @@ data class ApplicationConfig(
|
|||
)
|
||||
|
||||
@ConfigurationProperties("hideout.storage.s3")
|
||||
@ConditionalOnProperty("hideout.storage.type", havingValue = "s3")
|
||||
data class S3StorageConfig(
|
||||
val endpoint: String,
|
||||
val publicUrl: String,
|
||||
|
@ -51,8 +50,9 @@ data class S3StorageConfig(
|
|||
* @property publicUrl 公開用URL 省略可能 指定するとHideoutがファイルを配信しなくなります。
|
||||
*/
|
||||
@ConfigurationProperties("hideout.storage.local")
|
||||
@ConditionalOnProperty("hideout.storage.type", havingValue = "local", matchIfMissing = true)
|
||||
data class LocalStorageConfig(
|
||||
val path: String,
|
||||
val path: String = "files",
|
||||
val publicUrl: String?
|
||||
)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.usbharu.hideout.core.service.media
|
|||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||
import dev.usbharu.hideout.application.config.LocalStorageConfig
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||
import org.springframework.stereotype.Service
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.StandardOpenOption
|
||||
|
@ -12,6 +13,7 @@ import kotlin.io.path.deleteIfExists
|
|||
import kotlin.io.path.outputStream
|
||||
|
||||
@Service
|
||||
@ConditionalOnProperty("hideout.storage.type", havingValue = "local", matchIfMissing = true)
|
||||
/**
|
||||
* ローカルファイルシステムにメディアを保存します
|
||||
*
|
||||
|
|
|
@ -6,6 +6,7 @@ import kotlinx.coroutines.async
|
|||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||
import org.springframework.stereotype.Service
|
||||
import software.amazon.awssdk.core.sync.RequestBody
|
||||
import software.amazon.awssdk.services.s3.S3Client
|
||||
|
@ -14,6 +15,7 @@ import software.amazon.awssdk.services.s3.model.GetUrlRequest
|
|||
import software.amazon.awssdk.services.s3.model.PutObjectRequest
|
||||
|
||||
@Service
|
||||
@ConditionalOnProperty("hideout.storage.type", havingValue = "s3")
|
||||
class S3MediaDataStore(private val s3Client: S3Client, private val s3StorageConfig: S3StorageConfig) : MediaDataStore {
|
||||
override suspend fun save(dataMediaSave: MediaSave): SavedMedia {
|
||||
val fileUploadRequest = PutObjectRequest.builder()
|
||||
|
|
Loading…
Reference in New Issue