fix(ex/retirement): document

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-10-28 13:32:53 +07:00
parent 05c38b8d8e
commit 11586a8fb2

View file

@ -100,7 +100,7 @@ export class ExRetirementController extends Controller {
}
@Get("/document/{documentId}")
async getDocument(@Path("documentId") officerDocumentID: string) {
async getDocument(@Path("documentId") officerDocumentID: string, @Request() req: any) {
let retryCount = 0;
const maxRetries = 2;
while (retryCount < maxRetries) {
@ -118,8 +118,18 @@ export class ExRetirementController extends Controller {
headers: {
Authorization: `Bearer ${token}`,
},
responseType: "arraybuffer",
});
return res.data;
if (!req.res.headersSent && !req.res.destroyed) {
// Set response headers
req.res.setHeader("Content-Type", "application/pdf");
req.res.setHeader("Content-Disposition", `inline; filename="${officerDocumentID}.pdf"`);
req.res.setHeader("Content-Length", res.data.byteLength.toString());
req.res.end(Buffer.from(res.data));
return;
}
} catch (error: any) {
if (error.response?.status === 500 && retryCount < maxRetries - 1) {
TokenCache.delete(`${clientId}:${clientSecret}`);