include compose
This commit is contained in:
@@ -17,12 +17,7 @@ value class ContentId(val string: String)
|
||||
* @see ContentSerializersModuleConfigurator.Element
|
||||
* @see ContentSerializersModuleConfigurator
|
||||
*/
|
||||
sealed interface Content
|
||||
|
||||
/**
|
||||
* This type of content represents simple content which is easy to serialize/deserialize and to use
|
||||
*/
|
||||
interface SimpleContent : Content
|
||||
interface Content
|
||||
|
||||
/**
|
||||
* This type represents some binary data which can be sent with multipart and deserialized from it
|
||||
|
@@ -1,22 +0,0 @@
|
||||
package dev.inmo.postssystem.features.content.server
|
||||
|
||||
import com.benasher44.uuid.uuid4
|
||||
import dev.inmo.micro_utils.common.FileName
|
||||
import io.ktor.http.content.PartData
|
||||
import java.io.File
|
||||
|
||||
suspend fun PartData.loadContent() {
|
||||
when (this) {
|
||||
is PartData.FormItem -> TODO()
|
||||
is PartData.FileItem -> {
|
||||
val fileName = FileName(originalFileName ?: return null)
|
||||
val downloadTo = File.createTempFile(
|
||||
uuid4().toString(),
|
||||
fileName.extension
|
||||
)
|
||||
headers["data"]
|
||||
return
|
||||
}
|
||||
is PartData.BinaryItem -> return null/* Currently impossible state */
|
||||
}
|
||||
}
|
@@ -3,6 +3,8 @@ package dev.inmo.postssystem.features.files.common
|
||||
import com.benasher44.uuid.uuid4
|
||||
import dev.inmo.postssystem.features.files.common.storage.WriteFilesStorage
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
import io.ktor.utils.io.core.copyTo
|
||||
import io.ktor.utils.io.streams.asOutput
|
||||
import kotlinx.coroutines.flow.*
|
||||
import java.io.File
|
||||
|
||||
@@ -36,7 +38,7 @@ class WriteDistFilesStorage(
|
||||
file = newId.file
|
||||
} while (file.exists())
|
||||
metasKeyValueRepo.set(newId, it.toMetaFileInfo())
|
||||
file.writeBytes(it.inputProvider())
|
||||
it.inputProvider().copyTo(file.outputStream().asOutput())
|
||||
FullFileInfoStorageWrapper(newId, it)
|
||||
}
|
||||
|
||||
@@ -52,13 +54,15 @@ class WriteDistFilesStorage(
|
||||
override suspend fun update(
|
||||
id: FileId,
|
||||
value: FullFileInfo
|
||||
): FullFileInfoStorageWrapper? = id.file.takeIf { it.exists() } ?.writeBytes(value.inputProvider()) ?.let {
|
||||
): FullFileInfoStorageWrapper? {
|
||||
val file = id.file.takeIf { it.exists() } ?: return null
|
||||
value.inputProvider().copyTo(file.outputStream().asOutput())
|
||||
val result = FullFileInfoStorageWrapper(id, value.copy())
|
||||
|
||||
metasKeyValueRepo.set(id, value.toMetaFileInfo())
|
||||
_updatedObjectsFlow.emit(result)
|
||||
|
||||
result
|
||||
return result
|
||||
}
|
||||
|
||||
override suspend fun update(
|
||||
|
Reference in New Issue
Block a user