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:
@@ -34,7 +34,26 @@ export async function GET(req: NextRequest) {
|
||||
|
||||
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;
|
||||
if (documentTypeId) {
|
||||
try {
|
||||
@@ -45,12 +64,11 @@ export async function GET(req: NextRequest) {
|
||||
available = true;
|
||||
}
|
||||
} catch {
|
||||
// Not available server-side
|
||||
// Not available — will try direct download anyway
|
||||
}
|
||||
}
|
||||
|
||||
// If fileVisibility passed, try download
|
||||
if (available) {
|
||||
// Try download (even if fileVisibility failed — context might be enough)
|
||||
try {
|
||||
const { data, contentType, filename } = await client.rgiDownload(
|
||||
`rgi/appdetail/loadDocument/downloadFile/${workspaceId}/${documentPk}`,
|
||||
@@ -68,7 +86,6 @@ export async function GET(req: NextRequest) {
|
||||
} catch {
|
||||
// Fall through to redirect
|
||||
}
|
||||
}
|
||||
|
||||
// Server-side download not available — redirect to eTerra direct URL
|
||||
// User's browser session (if logged into eTerra) can download it
|
||||
|
||||
Reference in New Issue
Block a user