mirror of
https://github.com/pischule/memevizor.git
synced 2025-12-19 15:06:43 +00:00
Add content type to uploaded index.html
This commit is contained in:
@@ -28,7 +28,7 @@ class ThisCommandHandlerService(
|
||||
val fileBytes = env.bot.downloadFileBytes(maxResPhotoId) ?: return
|
||||
logger.info { "Downloaded a file from Telegram" }
|
||||
|
||||
fileUploaderService.uploadFile(fileBytes, "_.jpeg")
|
||||
fileUploaderService.uploadFile(fileBytes, "_.jpeg", "image/jpeg")
|
||||
|
||||
reactToMessage(env, "👍")
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ private val logger = KotlinLogging.logger {}
|
||||
@Service
|
||||
class DummyFileUploadService() : FileUploaderService {
|
||||
|
||||
override suspend fun uploadFile(fileBytes: ByteArray, filename: String) {
|
||||
override suspend fun uploadFile(fileBytes: ByteArray, filename: String, contentType: String) {
|
||||
logger.info { "File $filename has been successfully uploaded to nowhere" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,5 @@ import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
interface FileUploaderService {
|
||||
suspend fun uploadFile(fileBytes: ByteArray, filename: String)
|
||||
suspend fun uploadFile(fileBytes: ByteArray, filename: String, contentType: String)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class IndexInitializer(val fileUploaderService: FileUploaderService) {
|
||||
fun applicationStartedHandler(event: ApplicationStartedEvent) {
|
||||
try {
|
||||
val fileBytes = readResourceAsByteArray("static/index.html")
|
||||
runBlocking { fileUploaderService.uploadFile(fileBytes, "index.html") }
|
||||
runBlocking { fileUploaderService.uploadFile(fileBytes, "index.html", "text/html") }
|
||||
} catch (e: Error) {
|
||||
logger.warn(e) { "Failed to upload " }
|
||||
}
|
||||
|
||||
@@ -13,12 +13,13 @@ private val logger = KotlinLogging.logger {}
|
||||
@Service
|
||||
class S3FileUploaderService(private val s3Client: S3Client, private val s3Props: S3Props) :
|
||||
FileUploaderService {
|
||||
override suspend fun uploadFile(fileBytes: ByteArray, filename: String) {
|
||||
override suspend fun uploadFile(fileBytes: ByteArray, filename: String, contentType: String) {
|
||||
s3Client.putObject(
|
||||
PutObjectRequest {
|
||||
body = ByteStream.fromBytes(fileBytes)
|
||||
bucket = s3Props.bucket
|
||||
key = filename
|
||||
this.contentType = contentType
|
||||
}
|
||||
)
|
||||
logger.info { "File $filename has been uploaded to S3" }
|
||||
|
||||
Reference in New Issue
Block a user