more codes
This commit is contained in:
@@ -101,6 +101,18 @@ class EmailStorage(
|
||||
return path.toString()
|
||||
}
|
||||
|
||||
fun storeUploadedPdf(propertyId: UUID, originalName: String?, bytes: ByteArray): String {
|
||||
val dir = Paths.get(rootPath, propertyId.toString(), "manual")
|
||||
Files.createDirectories(dir)
|
||||
val safeName = (originalName ?: UUID.randomUUID().toString()).replace(Regex("[^A-Za-z0-9._-]"), "_")
|
||||
val fileName = "${safeName}_${OffsetDateTime.now().toEpochSecond()}.pdf"
|
||||
val path = dir.resolve(fileName).normalize()
|
||||
val tmp = dir.resolve("${fileName}.tmp").normalize()
|
||||
Files.write(tmp, bytes)
|
||||
atomicMove(tmp, path)
|
||||
return path.toString()
|
||||
}
|
||||
|
||||
private fun atomicMove(tmp: Path, target: Path) {
|
||||
try {
|
||||
Files.move(tmp, target, java.nio.file.StandardCopyOption.ATOMIC_MOVE, java.nio.file.StandardCopyOption.REPLACE_EXISTING)
|
||||
|
||||
Reference in New Issue
Block a user