send doc has base64
All checks were successful
build-and-deploy / build-deploy (push) Successful in 35s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 35s
This commit is contained in:
@@ -27,6 +27,7 @@ import java.time.OffsetDateTime
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.util.UUID
|
||||
import java.util.Base64
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/properties/{propertyId}/guests/{guestId}/documents")
|
||||
@@ -141,9 +142,7 @@ class GuestDocuments(
|
||||
extractionQueue.enqueue {
|
||||
val document = guestDocumentRepo.findById(documentId).orElse(null) ?: return@enqueue
|
||||
try {
|
||||
val token = tokenService.createToken(document.id.toString())
|
||||
val imageUrl =
|
||||
"${publicBaseUrl}/properties/$propertyId/guests/$guestId/documents/${document.id}/file?token=$token"
|
||||
val imageUrl = buildImageDataUrl(document) ?: return@enqueue
|
||||
|
||||
val results = linkedMapOf<String, String>()
|
||||
results["hasAadhar"] = llamaClient.ask(imageUrl, "CONTAINS AADHAAR? Answer YES or NO only.")
|
||||
@@ -201,6 +200,24 @@ class GuestDocuments(
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildImageDataUrl(document: GuestDocument): String? {
|
||||
val contentType = document.contentType?.trim()?.lowercase()
|
||||
if (contentType == null || !contentType.startsWith("image/")) {
|
||||
return null
|
||||
}
|
||||
val path = Paths.get(document.storagePath)
|
||||
if (!Files.exists(path)) {
|
||||
return null
|
||||
}
|
||||
return try {
|
||||
val bytes = Files.readAllBytes(path)
|
||||
val encoded = Base64.getEncoder().encodeToString(bytes)
|
||||
"data:$contentType;base64,$encoded"
|
||||
} catch (_: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class GuestDocumentResponse(
|
||||
|
||||
Reference in New Issue
Block a user