Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix: file downloads for unlisted types

Brad Barbinfdf12984a805
diff --git a/apps/erp/app/routes/file+/preview+/$bucket.$.tsx b/apps/erp/app/routes/file+/preview+/$bucket.$.tsx
index 1258897ae2..334c63ee39 100644
--- a/apps/erp/app/routes/file+/preview+/$bucket.$.tsx
+++ b/apps/erp/app/routes/file+/preview+/$bucket.$.tsx
@@ -1,6 +1,5 @@
import { getCarbonServiceRole } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
-import { supportedModelTypes } from "@carbon/utils";
import { type LoaderFunctionArgs } from "@vercel/remix";
const supportedFileTypes: Record<string, string> = {
@@ -44,14 +43,11 @@ export let loader = async ({ request, params }: LoaderFunctionArgs) => {
path = decodeURIComponent(path);
const fileType = path.split(".").pop()?.toLowerCase();
+ if (!fileType) {
+ return new Response(null, { status: 400 });
+ }
- if (
- !fileType ||
- (!(fileType in supportedFileTypes) &&
- !supportedModelTypes.includes(fileType))
- )
- throw new Error(`File type ${fileType} not supported`);
- const contentType = supportedFileTypes[fileType];
+ const contentType = supportedFileTypes[fileType ?? ""];
if (!path.includes(companyId)) {
return new Response(null, { status: 403 });
@@ -79,8 +75,12 @@ export let loader = async ({ request, params }: LoaderFunctionArgs) => {
}
const headers = new Headers({
- "Content-Type": contentType,
"Cache-Control": "private, max-age=31536000, immutable",
});
+
+ if (contentType) {
+ headers.set("Content-Type", contentType);
+ }
+
return new Response(fileData, { status: 200, headers });
};
diff --git a/apps/mes/app/routes/file+/preview+/$bucket.$.tsx b/apps/mes/app/routes/file+/preview+/$bucket.$.tsx
index 31e10382b8..bde505af3f 100644
--- a/apps/mes/app/routes/file+/preview+/$bucket.$.tsx
+++ b/apps/mes/app/routes/file+/preview+/$bucket.$.tsx
@@ -1,6 +1,5 @@
import { getCarbonServiceRole } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
-import { supportedModelTypes } from "@carbon/utils";
import { type LoaderFunctionArgs } from "@vercel/remix";
const supportedFileTypes: Record<string, string> = {
@@ -43,12 +42,9 @@ export let loader = async ({ request, params }: LoaderFunctionArgs) => {
const fileType = path.split(".").pop()?.toLowerCase();
- if (
- !fileType ||
- (!(fileType in supportedFileTypes) &&
- !supportedModelTypes.includes(fileType))
- )
- throw new Error(`File type ${fileType} not supported`);
+ if (!fileType) {
+ return new Response(null, { status: 400 });
+ }
const contentType = supportedFileTypes[fileType];
if (!path.includes(companyId)) {
@@ -77,8 +73,12 @@ export let loader = async ({ request, params }: LoaderFunctionArgs) => {
}
const headers = new Headers({
- "Content-Type": contentType,
"Cache-Control": "private, max-age=31536000, immutable",
});
+
+ if (contentType) {
+ headers.set("Content-Type", contentType);
+ }
+
return new Response(fileData, { status: 200, headers });
};