Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Prefer reporting filenames from response headers

rcourtman8c86c497da70
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 326c05d6c1..36dda0dc1d 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -274,6 +274,9 @@ optional metric/title field emission, canonical default-title fallback,
default fallback range window, and
attachment filename prefixes from the canonical reporting definition instead of
hardcoding a second local contract.
+Frontend consumers may still keep a local fallback filename for defensive
+download behavior, but when the server returns `Content-Disposition` they must
+prefer that attachment filename as the canonical transport output.
That same catalog contract is also authoritative for frontend request builders:
consumers may validate or reject malformed payloads, but they must not invent
replacement report endpoints, filename prefixes, export routes, or default
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index cc2c503151..98bf859a30 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -200,6 +200,9 @@ report endpoints, filename prefixes, default report titles, or range windows
when the catalog is
present; the first valid selection and all request semantics must come from the
parsed backend definition.
+That same reporting transport contract also means the frontend download path
+must prefer the backend `Content-Disposition` filename over any locally built
+fallback name when a report or inventory export response arrives.
That same settings shell must also read the reporting catalog for locked users,
not just entitled users, so the paywalled reporting panel does not drift onto a
separate frontend-owned title or description contract.
diff --git a/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts b/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts
index 25daaf3c51..7a717f387e 100644
--- a/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts
+++ b/frontend-modern/src/components/Settings/__tests__/settingsArchitecture.test.ts
@@ -1103,6 +1103,7 @@ describe('Settings architecture guardrails', () => {
expect(reportingPanelStateSource).not.toContain('!isReportingEnabled()');
expect(reportingPanelStateSource).toContain('buildVMInventoryExportRequest');
expect(reportingPanelStateSource).toContain('getReportingGenerateSuccessMessage');
+ expect(reportingPanelStateSource).toContain('resolveReportingDownloadFilename');
expect(reportingPanelStateSource).not.toContain("'advanced_reporting'");
expect(reportingPanelStateSource).not.toContain('getTrialAlreadyUsedMessage()');
expect(reportingCatalogModelSource).toContain('export function buildReportingCatalogRequest');
diff --git a/frontend-modern/src/components/Settings/useReportingPanelState.ts b/frontend-modern/src/components/Settings/useReportingPanelState.ts
index bbe9ebc595..6e2fb1d2c9 100644
--- a/frontend-modern/src/components/Settings/useReportingPanelState.ts
+++ b/frontend-modern/src/components/Settings/useReportingPanelState.ts
@@ -17,6 +17,7 @@ import {
getReportingGenerateSuccessMessage,
getReportingInventoryExportErrorMessage,
getReportingInventoryExportSuccessMessage,
+ resolveReportingDownloadFilename,
} from '@/utils/reportingPresentation';
import { runStartProTrialAction } from '@/utils/trialStartAction';
import {
@@ -139,7 +140,10 @@ export const useReportingPanelState = () => {
const url = window.URL.createObjectURL(blob);
const anchor = document.createElement('a');
anchor.href = url;
- anchor.download = filename;
+ anchor.download = resolveReportingDownloadFilename(
+ response.headers.get('Content-Disposition'),
+ filename,
+ );
document.body.appendChild(anchor);
anchor.click();
window.URL.revokeObjectURL(url);
diff --git a/frontend-modern/src/utils/__tests__/reportingPresentation.test.ts b/frontend-modern/src/utils/__tests__/reportingPresentation.test.ts
index 96e8e596d7..81cbcf0fc2 100644
--- a/frontend-modern/src/utils/__tests__/reportingPresentation.test.ts
+++ b/frontend-modern/src/utils/__tests__/reportingPresentation.test.ts
@@ -4,6 +4,7 @@ import {
getReportingGenerateErrorMessage,
getReportingGenerateSelectionRequiredMessage,
getReportingGenerateSuccessMessage,
+ resolveReportingDownloadFilename,
} from '@/utils/reportingPresentation';
describe('reportingPresentation', () => {
@@ -15,4 +16,22 @@ describe('reportingPresentation', () => {
expect(getReportingGenerateSuccessMessage()).toBe('Report generated successfully');
expect(getReportingGenerateErrorMessage()).toBe('Failed to generate report');
});
+
+ it('prefers backend attachment filenames and falls back locally when needed', () => {
+ expect(
+ resolveReportingDownloadFilename(
+ 'attachment; filename="canonical-report.pdf"',
+ 'fallback-report.pdf',
+ ),
+ ).toBe('canonical-report.pdf');
+ expect(
+ resolveReportingDownloadFilename(
+ "attachment; filename*=UTF-8''fleet%20report%20march.csv",
+ 'fallback-report.csv',
+ ),
+ ).toBe('fleet report march.csv');
+ expect(resolveReportingDownloadFilename(null, 'fallback-report.csv')).toBe(
+ 'fallback-report.csv',
+ );
+ });
});
diff --git a/frontend-modern/src/utils/reportingPresentation.ts b/frontend-modern/src/utils/reportingPresentation.ts
index d6c97bc406..449cc7ca07 100644
--- a/frontend-modern/src/utils/reportingPresentation.ts
+++ b/frontend-modern/src/utils/reportingPresentation.ts
@@ -21,3 +21,37 @@ export function getReportingInventoryExportSuccessMessage(): string {
export function getReportingInventoryExportErrorMessage(): string {
return 'Failed to generate VM inventory export';
}
+
+function decodeRFC5987Value(value: string): string {
+ try {
+ return decodeURIComponent(value);
+ } catch {
+ return value;
+ }
+}
+
+export function resolveReportingDownloadFilename(
+ contentDisposition: string | null,
+ fallbackFilename: string,
+): string {
+ if (typeof contentDisposition !== 'string' || contentDisposition.trim() === '') {
+ return fallbackFilename;
+ }
+
+ const encodedMatch = contentDisposition.match(/filename\*=UTF-8''([^;]+)/i);
+ if (encodedMatch && encodedMatch[1]) {
+ return decodeRFC5987Value(encodedMatch[1].trim());
+ }
+
+ const quotedMatch = contentDisposition.match(/filename="([^"]+)"/i);
+ if (quotedMatch && quotedMatch[1]) {
+ return quotedMatch[1];
+ }
+
+ const plainMatch = contentDisposition.match(/filename=([^;]+)/i);
+ if (plainMatch && plainMatch[1]) {
+ return plainMatch[1].trim();
+ }
+
+ return fallbackFilename;
+}