Add guest signature upload/download
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s

This commit is contained in:
androidlover5842
2026-01-29 05:09:12 +05:30
parent 71c70c8554
commit 3e984fdcb3
5 changed files with 111 additions and 5 deletions

View File

@@ -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)
}
}