add gitlab ci
This commit is contained in:
@@ -6,6 +6,7 @@ import com.vaultdrop.mobile.data.remote.dto.ApiEnvelope
|
||||
import com.vaultdrop.mobile.data.remote.dto.ApiErrorEnvelope
|
||||
import com.vaultdrop.mobile.data.remote.dto.DeviceRegistrationDto
|
||||
import com.vaultdrop.mobile.data.remote.dto.FileDto
|
||||
import com.vaultdrop.mobile.data.remote.dto.FileOcrDto
|
||||
import com.vaultdrop.mobile.data.remote.dto.FolderDto
|
||||
import com.vaultdrop.mobile.data.remote.dto.LoginRequestDto
|
||||
import com.vaultdrop.mobile.data.remote.dto.LoginResponseDto
|
||||
@@ -105,6 +106,10 @@ class ApiClient @Inject constructor(
|
||||
suspend fun getOcrJob(jobId: String): OcrJobDto =
|
||||
unwrap({ apiService.getOcrJob(jobId) })
|
||||
|
||||
/** Extrait OCR server-side d'un fichier visible (viewer+, own ou shared). */
|
||||
suspend fun getFileOcr(fileId: String): FileOcrDto =
|
||||
unwrap({ apiService.getFileOcr(fileId) })
|
||||
|
||||
private suspend fun <T> unwrap(
|
||||
call: suspend () -> Response<ApiEnvelope<T>>,
|
||||
skipUnauthorizedHandling: Boolean = false,
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.vaultdrop.mobile.data.remote
|
||||
import com.vaultdrop.mobile.data.remote.dto.ApiEnvelope
|
||||
import com.vaultdrop.mobile.data.remote.dto.DeviceRegistrationDto
|
||||
import com.vaultdrop.mobile.data.remote.dto.FileDto
|
||||
import com.vaultdrop.mobile.data.remote.dto.FileOcrDto
|
||||
import com.vaultdrop.mobile.data.remote.dto.FolderDto
|
||||
import com.vaultdrop.mobile.data.remote.dto.LoginRequestDto
|
||||
import com.vaultdrop.mobile.data.remote.dto.LoginResponseDto
|
||||
@@ -96,4 +97,14 @@ interface ApiService {
|
||||
suspend fun getOcrJob(
|
||||
@Path("id") jobId: String,
|
||||
): Response<ApiEnvelope<OcrJobDto>>
|
||||
|
||||
/**
|
||||
* Extrait OCR déjà calculé côté serveur pour un fichier visible (viewer+,
|
||||
* own ou shared). Permet à un second device de récupérer le texte sans
|
||||
* re-téléverser les octets (docs/api-v1.md §5).
|
||||
*/
|
||||
@GET("files/{id}/ocr")
|
||||
suspend fun getFileOcr(
|
||||
@Path("id") fileId: String,
|
||||
): Response<ApiEnvelope<FileOcrDto>>
|
||||
}
|
||||
@@ -152,4 +152,14 @@ data class OcrJobDto(
|
||||
/** Requête `POST /ocr/jobs` — `{ "fileId": "…32-hex" }` (docs/api-v1.md §5). */
|
||||
data class OcrSubmitDto(
|
||||
@Json(name = "fileId") val fileId: String,
|
||||
)
|
||||
|
||||
/**
|
||||
* Réponse `GET /files/{id}/ocr` — extrait OCR server-side du fichier,
|
||||
* consultable par le user et les grantees (viewer+). `text` "" tant que
|
||||
* l'OCR n'a pas encore atterri sur la ressource (docs/api-v1.md §5).
|
||||
*/
|
||||
data class FileOcrDto(
|
||||
@Json(name = "text") val text: String,
|
||||
@Json(name = "updatedAt") val updatedAt: String? = null,
|
||||
)
|
||||
@@ -26,6 +26,8 @@ import javax.inject.Singleton
|
||||
*
|
||||
* Séquence pour un fichier SAF `processed` + `local-cloud` (resource_id déjà
|
||||
* connu du serveur via l'outbox `create_resource`) :
|
||||
* 0. [syncFromServer] — si un autre device a déjà OCRisé le fichier, le texte
|
||||
* est rapatrié via `GET /files/:id/ocr` (viewer+) **sans** upload ni job ;
|
||||
* 1. [ensurePhysical] — upload multipart **ciblé** (`resourceId`) des octets
|
||||
* locaux : pipeline séparé, hors outbox, qui écrit
|
||||
* `UPLOAD_DIR/<user>/<resource_id>.<ext>` — sans lequel le job OCR
|
||||
@@ -75,6 +77,20 @@ class OcrRepository @Inject constructor(
|
||||
fileDao.updateOcrText(resourceId, text?.takeIf { it.isNotBlank() }, System.currentTimeMillis())
|
||||
}
|
||||
|
||||
/**
|
||||
* Rapatrie l'extrait OCR déjà calculé côté serveur pour un fichier visible
|
||||
* (viewer+, own ou shared). Renvoie le texte persisté en Room, ou null si le
|
||||
* serveur n'a pas encore d'extrait — un second device récupère ainsi le
|
||||
* résultat d'un OCR fait par un autre device, **sans re-téléverser les
|
||||
* octets ni re-soumettre un job** (docs/api-v1.md §5, GET /files/:id/ocr).
|
||||
*/
|
||||
suspend fun syncFromServer(file: FileEntity): String? {
|
||||
val dto = apiClient.getFileOcr(file.resourceId)
|
||||
if (dto.text.isBlank()) return null
|
||||
saveResult(file.resourceId, dto.text)
|
||||
return dto.text
|
||||
}
|
||||
|
||||
/**
|
||||
* OCR auto d'un fichier (un seul à la fois) : marqueur « en cours », upload
|
||||
* multipart ciblé, soumission du job serveur, poll jusqu'au terminal puis
|
||||
@@ -86,6 +102,12 @@ class OcrRepository @Inject constructor(
|
||||
val now = System.currentTimeMillis()
|
||||
fileDao.markOcrQueued(file.resourceId, now, now)
|
||||
return try {
|
||||
// 0. Un autre device a peut-être déjà OCRisé le fichier : si le
|
||||
// serveur a le texte, on le rapatrie sans upload ni job.
|
||||
if (syncFromServer(file) != null) {
|
||||
fileDao.clearOcrQueued(file.resourceId, System.currentTimeMillis())
|
||||
return OcrAutoOutcome.Done
|
||||
}
|
||||
ensurePhysical(file)
|
||||
val jobId = submit(file.resourceId)
|
||||
val final = poll(jobId)
|
||||
|
||||
@@ -77,6 +77,21 @@ class OcrViewModel @Inject constructor(
|
||||
_uiState.value = OcrUiState(resourceId = file.resourceId, uploading = true)
|
||||
activeJob = viewModelScope.launch {
|
||||
try {
|
||||
// Un autre device a peut-être déjà OCRisé ce document : le
|
||||
// serveur a le texte (GET /files/:id/ocr) → on l'affiche sans
|
||||
// re-téléverser les octets ni re-soumettre un job (docs §5).
|
||||
val synced = ocrRepository.syncFromServer(file)
|
||||
if (synced != null) {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
resourceId = file.resourceId,
|
||||
uploading = false,
|
||||
status = OcrJobStatus.DONE,
|
||||
text = synced,
|
||||
)
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
ocrRepository.ensurePhysical(file)
|
||||
val jobId = ocrRepository.submit(file.resourceId)
|
||||
val final = ocrRepository.poll(jobId) { job ->
|
||||
|
||||
Reference in New Issue
Block a user