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(models): show as-uploaded size; optimized-file indicator; always offer download

Sidwebworks2a04f2ebb796
diff --git a/apps/erp/app/components/Documents.tsx b/apps/erp/app/components/Documents.tsx
index 8982c86ad6..caba610b6c 100644
--- a/apps/erp/app/components/Documents.tsx
+++ b/apps/erp/app/components/Documents.tsx
@@ -21,17 +21,18 @@ import {
Tr,
toast
} from "@carbon/react";
-import {
- convertKbToString,
- isModelRawDownloadable,
- MODEL_RAW_KEEP_MAX_BYTES
-} from "@carbon/utils";
+import { convertKbToString, MODEL_RAW_KEEP_MAX_BYTES } from "@carbon/utils";
import { Trans, useLingui } from "@lingui/react/macro";
import type { ChangeEvent } from "react";
import { useCallback } from "react";
import { LuAxis3D, LuEllipsisVertical, LuUpload } from "react-icons/lu";
import { Link, useFetchers, useRevalidator, useSubmit } from "react-router";
-import { DocumentPreview, FileDropzone, Hyperlink } from "~/components";
+import {
+ DocumentPreview,
+ FileDropzone,
+ Hyperlink,
+ ModelOptimizedIndicator
+} from "~/components";
import DocumentIcon from "~/components/DocumentIcon";
import { useDateFormatter, usePermissions, useUser } from "~/hooks";
import type { OptimisticFileObject } from "~/modules/shared";
@@ -297,6 +298,9 @@ const Documents = ({
>
{modelUpload.modelName}
</Hyperlink>
+ <ModelOptimizedIndicator
+ modelPath={modelUpload.modelPath}
+ />
</HStack>
</Td>
<Td className="text-xs font-mono">
@@ -318,13 +322,14 @@ const Documents = ({
/>
</DropdownMenuTrigger>
<DropdownMenuContent>
- {isModelRawDownloadable(modelUpload.modelPath) && (
- <DropdownMenuItem
- onClick={() => downloadModel(modelUpload)}
- >
- <Trans>Download</Trans>
- </DropdownMenuItem>
- )}
+ {/* Always offered: the server resolves the retained
+ original (xbf rows included); only legacy rows
+ 404 → surfaced as a toast. */}
+ <DropdownMenuItem
+ onClick={() => downloadModel(modelUpload)}
+ >
+ <Trans>Download</Trans>
+ </DropdownMenuItem>
<DropdownMenuItem asChild>
<Link
to={
diff --git a/apps/erp/app/components/ItemThumnailUpload.tsx b/apps/erp/app/components/ItemThumnailUpload.tsx
index 51ae5fc069..1df59950b7 100644
--- a/apps/erp/app/components/ItemThumnailUpload.tsx
+++ b/apps/erp/app/components/ItemThumnailUpload.tsx
@@ -1,6 +1,15 @@
import { SUPABASE_URL, useCarbon } from "@carbon/auth";
import { getLogger } from "@carbon/logger";
-import { Button, File as FileUpload, HStack, toast } from "@carbon/react";
+import {
+ Button,
+ File as FileUpload,
+ HStack,
+ IconButton,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ toast
+} from "@carbon/react";
import { Trans, useLingui } from "@lingui/react/macro";
import { nanoid } from "nanoid";
import type { ChangeEvent } from "react";
@@ -231,21 +240,27 @@ export function ItemThumbnailUpload({
</span>
</div>
)}
- {!isReadOnly && (
- <HStack className="absolute bottom-2 right-2">
- {modelId && (
- <Button
+ {!isReadOnly && modelId && (
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <IconButton
+ aria-label={t`Regenerate thumbnail from the 3D model`}
+ icon={<LuRefreshCw />}
variant="secondary"
- className="bg-card opacity-100"
size="sm"
- leftIcon={<LuRefreshCw />}
+ className="absolute top-2 right-2 bg-card opacity-100"
isLoading={isRegenerating}
isDisabled={isRegenerating}
onClick={onRegenerate}
- >
- <Trans>Regenerate</Trans>
- </Button>
- )}
+ />
+ </TooltipTrigger>
+ <TooltipContent>
+ <Trans>Regenerate thumbnail from the 3D model</Trans>
+ </TooltipContent>
+ </Tooltip>
+ )}
+ {!isReadOnly && (
+ <HStack className="absolute bottom-2 right-2">
{thumbnailPath && (
<Button
variant="secondary"
diff --git a/apps/erp/app/components/ModelOptimizedIndicator.tsx b/apps/erp/app/components/ModelOptimizedIndicator.tsx
new file mode 100644
index 0000000000..a00a780e48
--- /dev/null
+++ b/apps/erp/app/components/ModelOptimizedIndicator.tsx
@@ -0,0 +1,30 @@
+import { Tooltip, TooltipContent, TooltipTrigger } from "@carbon/react";
+import { Trans } from "@lingui/react/macro";
+import { LuZap } from "react-icons/lu";
+
+/**
+ * Small indicator on a model file row when the upload has been through the
+ * optimise/compact pipeline (its `modelPath` was repointed at a compacted
+ * `.zst` artifact). Reassures that this is internal-only: the customer's
+ * original file is preserved and is exactly what a download serves.
+ */
+export function ModelOptimizedIndicator({
+ modelPath
+}: {
+ modelPath: string | null;
+}) {
+ if (!modelPath?.toLowerCase().endsWith(".zst")) return null;
+ return (
+ <Tooltip>
+ <TooltipTrigger>
+ <LuZap className="size-3 text-emerald-500" />
+ </TooltipTrigger>
+ <TooltipContent>
+ <Trans>
+ Optimized for fast previews — downloads always serve the original
+ uploaded file
+ </Trans>
+ </TooltipContent>
+ </Tooltip>
+ );
+}
diff --git a/apps/erp/app/components/index.ts b/apps/erp/app/components/index.ts
index 2fad30b19b..5bc9573f1f 100644
--- a/apps/erp/app/components/index.ts
+++ b/apps/erp/app/components/index.ts
@@ -32,6 +32,7 @@ import { ItemLifecycleBadge } from "./ItemLifecycleBadge";
import ItemThumbnail from "./ItemThumbnail";
import Location from "./Location";
import MetricCard from "./MetricCard";
+import { ModelOptimizedIndicator } from "./ModelOptimizedIndicator";
import New from "./New";
import PeriodSelector from "./PeriodSelector";
import RealtimeDataProvider from "./RealtimeDataProvider";
@@ -69,6 +70,7 @@ export {
MethodIcon,
MethodItemTypeIcon,
MetricCard,
+ ModelOptimizedIndicator,
ModuleIcon,
New,
OperationStatusIcon,
diff --git a/apps/erp/app/modules/items/ui/Item/ItemDocuments.tsx b/apps/erp/app/modules/items/ui/Item/ItemDocuments.tsx
index f70994e560..a47ddca76c 100644
--- a/apps/erp/app/modules/items/ui/Item/ItemDocuments.tsx
+++ b/apps/erp/app/modules/items/ui/Item/ItemDocuments.tsx
@@ -21,18 +21,19 @@ import {
Tr,
toast
} from "@carbon/react";
-import {
- convertKbToString,
- isModelRawDownloadable,
- MODEL_RAW_KEEP_MAX_BYTES
-} from "@carbon/utils";
+import { convertKbToString, MODEL_RAW_KEEP_MAX_BYTES } from "@carbon/utils";
import { Trans, useLingui } from "@lingui/react/macro";
import type { FileObject } from "@supabase/storage-js";
import type { ChangeEvent } from "react";
import { useCallback } from "react";
import { LuAxis3D, LuEllipsisVertical, LuUpload } from "react-icons/lu";
import { Link, useFetchers, useRevalidator, useSubmit } from "react-router";
-import { DocumentPreview, FileDropzone, Hyperlink } from "~/components";
+import {
+ DocumentPreview,
+ FileDropzone,
+ Hyperlink,
+ ModelOptimizedIndicator
+} from "~/components";
import DocumentIcon from "~/components/DocumentIcon";
import { useDateFormatter, usePermissions, useUser } from "~/hooks";
import type { ItemType, OptimisticFileObject } from "~/modules/shared";
@@ -146,6 +147,9 @@ const ItemDocuments = ({
<Hyperlink target="_blank" to={getModelPath(modelUpload)}>
{modelUpload.modelName}
</Hyperlink>
+ <ModelOptimizedIndicator
+ modelPath={modelUpload.modelPath}
+ />
</HStack>
</Td>
<Td className="text-xs font-mono">
@@ -172,13 +176,11 @@ const ItemDocuments = ({
<Trans>View</Trans>
</Link>
</DropdownMenuItem>
- {isModelRawDownloadable(modelUpload.modelPath) && (
- <DropdownMenuItem
- onClick={() => downloadModel(modelUpload)}
- >
- Download
- </DropdownMenuItem>
- )}
+ <DropdownMenuItem
+ onClick={() => downloadModel(modelUpload)}
+ >
+ Download
+ </DropdownMenuItem>
<DropdownMenuItem
destructive
disabled={isReadOnly || !canDelete}
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobDocuments.tsx b/apps/erp/app/modules/production/ui/Jobs/JobDocuments.tsx
index 47d5f7baca..6c95e3e6bb 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobDocuments.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobDocuments.tsx
@@ -27,18 +27,19 @@ import {
toast,
VStack
} from "@carbon/react";
-import {
- convertKbToString,
- isModelRawDownloadable,
- MODEL_RAW_KEEP_MAX_BYTES
-} from "@carbon/utils";
+import { convertKbToString, MODEL_RAW_KEEP_MAX_BYTES } from "@carbon/utils";
import { Trans, useLingui } from "@lingui/react/macro";
import type { FileObject } from "@supabase/storage-js";
import type { ChangeEvent } from "react";
import { useCallback } from "react";
import { LuEllipsisVertical, LuUpload } from "react-icons/lu";
import { Link, useFetchers, useRevalidator, useSubmit } from "react-router";
-import { DocumentPreview, FileDropzone, Hyperlink } from "~/components";
+import {
+ DocumentPreview,
+ FileDropzone,
+ Hyperlink,
+ ModelOptimizedIndicator
+} from "~/components";
import DocumentIcon from "~/components/DocumentIcon";
import { Enumerable } from "~/components/Enumerable";
import { useDateFormatter, usePermissions, useUser } from "~/hooks";
@@ -410,6 +411,9 @@ const JobDocuments = ({
{modelUpload.modelName}
</Hyperlink>
</VStack>
+ <ModelOptimizedIndicator
+ modelPath={modelUpload.modelPath}
+ />
</HStack>
</Td>
<Td>
@@ -439,13 +443,11 @@ const JobDocuments = ({
<Trans>View</Trans>
</Link>
</DropdownMenuItem>
- {isModelRawDownloadable(modelUpload.modelPath) && (
- <DropdownMenuItem
- onClick={() => downloadModel(modelUpload)}
- >
- Download
- </DropdownMenuItem>
- )}
+ <DropdownMenuItem
+ onClick={() => downloadModel(modelUpload)}
+ >
+ Download
+ </DropdownMenuItem>
<DropdownMenuItem
destructive
disabled={!canDelete || isReadOnly}
diff --git a/apps/erp/app/modules/sales/ui/Opportunity/OpportunityLineDocuments.tsx b/apps/erp/app/modules/sales/ui/Opportunity/OpportunityLineDocuments.tsx
index 1ab16eb1d0..7dbd390845 100644
--- a/apps/erp/app/modules/sales/ui/Opportunity/OpportunityLineDocuments.tsx
+++ b/apps/erp/app/modules/sales/ui/Opportunity/OpportunityLineDocuments.tsx
@@ -27,18 +27,19 @@ import {
toast,
VStack
} from "@carbon/react";
-import {
- convertKbToString,
- isModelRawDownloadable,
- MODEL_RAW_KEEP_MAX_BYTES
-} from "@carbon/utils";
+import { convertKbToString, MODEL_RAW_KEEP_MAX_BYTES } from "@carbon/utils";
import { Trans, useLingui } from "@lingui/react/macro";
import type { FileObject } from "@supabase/storage-js";
import type { ChangeEvent } from "react";
import { useCallback } from "react";
import { LuEllipsisVertical, LuUpload } from "react-icons/lu";
import { Link, useFetchers, useRevalidator, useSubmit } from "react-router";
-import { DocumentPreview, FileDropzone, Hyperlink } from "~/components";
+import {
+ DocumentPreview,
+ FileDropzone,
+ Hyperlink,
+ ModelOptimizedIndicator
+} from "~/components";
import DocumentIcon from "~/components/DocumentIcon";
import { Enumerable } from "~/components/Enumerable";
import { useDateFormatter, usePermissions, useUser } from "~/hooks";
@@ -480,6 +481,9 @@ const OpportunityLineDocuments = ({
{modelUpload.modelName}
</Hyperlink>
</VStack>
+ <ModelOptimizedIndicator
+ modelPath={modelUpload.modelPath}
+ />
</HStack>
</Td>
<Td>
@@ -509,13 +513,11 @@ const OpportunityLineDocuments = ({
<Trans>View</Trans>
</Link>
</DropdownMenuItem>
- {isModelRawDownloadable(modelUpload.modelPath) && (
- <DropdownMenuItem
- onClick={() => downloadModel(modelUpload)}
- >
- <Trans>Download</Trans>
- </DropdownMenuItem>
- )}
+ <DropdownMenuItem
+ onClick={() => downloadModel(modelUpload)}
+ >
+ <Trans>Download</Trans>
+ </DropdownMenuItem>
<DropdownMenuItem
destructive
disabled={!canDelete}
diff --git a/packages/database/supabase/migrations/20260728151514_model-size-original-backfill.sql b/packages/database/supabase/migrations/20260728151514_model-size-original-backfill.sql
new file mode 100644
index 0000000000..90fd4c397d
--- /dev/null
+++ b/packages/database/supabase/migrations/20260728151514_model-size-original-backfill.sql
@@ -0,0 +1,9 @@
+-- "size" must always be the customer's AS-UPLOADED bytes: it feeds every
+-- "modelSize" view/RPC and the file lists, which display the customer's file.
+-- Compaction used to rewrite it to the internal ".xbf.zst"/".zst" artifact's
+-- size (the compact job no longer does); restore the frozen original bytes on
+-- rows that were rewritten.
+UPDATE "modelUpload"
+SET "size" = "originalSize"
+WHERE "originalSize" IS NOT NULL
+ AND "size" IS DISTINCT FROM "originalSize";
diff --git a/packages/jobs/src/inngest/functions/tasks/model-compact.ts b/packages/jobs/src/inngest/functions/tasks/model-compact.ts
index b9440187d3..5afa9de512 100644
--- a/packages/jobs/src/inngest/functions/tasks/model-compact.ts
+++ b/packages/jobs/src/inngest/functions/tasks/model-compact.ts
@@ -216,7 +216,9 @@ export const modelCompactFunction = inngest.createFunction(
if (fits) {
// Relocate the compacted raw to durable storage and repoint `modelPath`
// at it. xbf: also retain the original; zstd: drop the fat original
- // (the `.zst` IS the original, compressed).
+ // (the `.zst` IS the original, compressed). `size` stays the
+ // AS-UPLOADED bytes — it feeds every "modelSize" view/RPC and the file
+ // lists, which must show the customer's file, not an internal artifact.
const err = await moveRawToDurable(client, compactPath);
if (err) throw new Error(`relocate compacted raw to durable: ${err}`);
if (isXbf) await retainOriginal();
@@ -225,8 +227,7 @@ export const modelCompactFunction = inngest.createFunction(
.update({
modelPath: compactPath,
originalPath: isXbf ? model.modelPath : null,
- ...originalSizeUpdate,
- size: compactedSize
+ ...originalSizeUpdate
})
.eq("id", modelUploadId);
if (!isXbf) {
@@ -265,8 +266,7 @@ export const modelCompactFunction = inngest.createFunction(
.update({
modelPath: compactPath,
originalPath: isXbf ? model.modelPath : null,
- ...originalSizeUpdate,
- ...(compactedSize != null ? { size: compactedSize } : {})
+ ...originalSizeUpdate
})
.eq("id", modelUploadId);
if (!isXbf) {