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);
|
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,29 +64,27 @@ 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}`,
|
);
|
||||||
);
|
if (data.length > 0) {
|
||||||
if (data.length > 0) {
|
return new NextResponse(new Uint8Array(data), {
|
||||||
return new NextResponse(new Uint8Array(data), {
|
status: 200,
|
||||||
status: 200,
|
headers: {
|
||||||
headers: {
|
"Content-Type": contentType,
|
||||||
"Content-Type": contentType,
|
"Content-Disposition": `attachment; filename="${encodeURIComponent(filename)}"`,
|
||||||
"Content-Disposition": `attachment; filename="${encodeURIComponent(filename)}"`,
|
"Content-Length": String(data.length),
|
||||||
"Content-Length": String(data.length),
|
},
|
||||||
},
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Fall through to redirect
|
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// Fall through to redirect
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server-side download not available — redirect to eTerra direct URL
|
// Server-side download not available — redirect to eTerra direct URL
|
||||||
|
|||||||
Reference in New Issue
Block a user