fix(rgi): set application context before download attempt

Before downloading, now calls:
1. verifyCurrentActorAuthenticated — sets actor context in session
2. appdetail/details — loads application context

Then tries download regardless of fileVisibility result.
The session context might be what enables downloads that previously
returned 404.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-24 22:50:27 +02:00
parent 4beac959c8
commit 3614c2fc4a
+22 -5
View File
@@ -34,7 +34,26 @@ export async function GET(req: NextRequest) {
const client = await EterraClient.create(username, password); const client = await EterraClient.create(username, password);
// Try fileVisibility first (fast check) // Step 0: Set application context (like the web UI does)
// This call sets session-level attributes required for document access
try {
await client.rgiGet(
`appDetail/verifyCurrentActorAuthenticated/${applicationId}/${workspaceId}`,
);
} catch {
// Non-critical
}
// Also load application details (sets more session context)
try {
await client.rgiPost(
`rgi/appdetail/details?applicationid=${applicationId}`,
);
} catch {
// Non-critical
}
// Try fileVisibility
let available = false; let available = false;
if (documentTypeId) { if (documentTypeId) {
try { try {
@@ -45,12 +64,11 @@ export async function GET(req: NextRequest) {
available = true; available = true;
} }
} catch { } catch {
// Not available server-side // Not available — will try direct download anyway
} }
} }
// If fileVisibility passed, try download // Try download (even if fileVisibility failed — context might be enough)
if (available) {
try { try {
const { data, contentType, filename } = await client.rgiDownload( const { data, contentType, filename } = await client.rgiDownload(
`rgi/appdetail/loadDocument/downloadFile/${workspaceId}/${documentPk}`, `rgi/appdetail/loadDocument/downloadFile/${workspaceId}/${documentPk}`,
@@ -68,7 +86,6 @@ export async function GET(req: NextRequest) {
} catch { } catch {
// Fall through to redirect // Fall through to redirect
} }
}
// Server-side download not available — redirect to eTerra direct URL // Server-side download not available — redirect to eTerra direct URL
// User's browser session (if logged into eTerra) can download it // User's browser session (if logged into eTerra) can download it