Add guest signature upload/download
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package com.android.trisolarisserver.component
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.stereotype.Component
|
||||
import org.springframework.web.multipart.MultipartFile
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.util.UUID
|
||||
|
||||
data class StoredSignature(
|
||||
val storagePath: String,
|
||||
val sizeBytes: Long
|
||||
)
|
||||
|
||||
@Component
|
||||
class GuestSignatureStorage(
|
||||
@Value("\${storage.documents.root}") private val root: String
|
||||
) {
|
||||
init {
|
||||
val rootPath = Paths.get(root)
|
||||
Files.createDirectories(rootPath)
|
||||
if (!Files.isWritable(rootPath)) {
|
||||
throw IllegalStateException("Guest signature root not writable: $root")
|
||||
}
|
||||
}
|
||||
|
||||
fun store(propertyId: UUID, guestId: UUID, file: MultipartFile): StoredSignature {
|
||||
val dir = Paths.get(root, "guests", propertyId.toString(), guestId.toString())
|
||||
Files.createDirectories(dir)
|
||||
val path = dir.resolve("signature.svg")
|
||||
file.inputStream.use { input ->
|
||||
Files.newOutputStream(path).use { output -> input.copyTo(output) }
|
||||
}
|
||||
return StoredSignature(
|
||||
storagePath = path.toString(),
|
||||
sizeBytes = Files.size(path)
|
||||
)
|
||||
}
|
||||
|
||||
fun resolvePath(storagePath: String): Path {
|
||||
return Paths.get(storagePath)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user