fix(rgi): fast download with fileVisibility gate + clear error message

Download route simplified:
1. fileVisibility check — if 404, returns "indisponibil" + eTerra URL
2. Single download pattern (the one that works)

When document not available server-side, response includes direct
eTerra URL as fallback. No more 7 pattern attempts = much faster.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-24 22:39:53 +02:00
parent 5966a11f7e
commit b0a5918bd7
2 changed files with 48 additions and 114 deletions
+10 -19
View File
@@ -295,30 +295,21 @@ function IssuedDocsPanel({
</div>
</div>
<div className="flex items-center gap-1 shrink-0">
{/* Server-side download (works when fileVisibility returns OK) */}
<Button
size="sm"
variant="outline"
className="gap-1"
onClick={() => {
// Open eTerra directly — user's browser session has download permission
// First open confirmOnView, then download
const base = "https://eterra.ancpi.ro/eterra/api";
const wid = doc.workspaceId || workspaceId;
const appId = doc.applicationId || applicationPk;
const dpk = doc.documentPk;
// Open confirm in hidden iframe, then download
const iframe = document.createElement("iframe");
iframe.style.display = "none";
iframe.src = `${base}/rgi/appdetail/issueddocs/confirmOnView/${wid}/${appId}/${dpk}`;
document.body.appendChild(iframe);
setTimeout(() => {
window.open(`${base}/rgi/appdetail/loadDocument/downloadFile/${wid}/${dpk}`, "_blank");
iframe.remove();
}, 500);
}}
asChild
>
<Download className="h-3.5 w-3.5" />
Descarca
<a
href={`/api/eterra/rgi/download-doc?workspaceId=${doc.workspaceId || workspaceId}&applicationId=${doc.applicationId || applicationPk}&documentPk=${doc.documentPk}&documentTypeId=${doc.documentTypeId}`}
target="_blank"
rel="noopener noreferrer"
>
<Download className="h-3.5 w-3.5" />
Descarca
</a>
</Button>
</div>
</div>