Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(image preview): ensure image upload and fetch include Content Typ… (#2560)
Aidan Holloway-Bidwellaa2a5a95ec48
diff --git a/js/app/packages/core/component/DocumentPreview.tsx b/js/app/packages/core/component/DocumentPreview.tsxindex 8412285f21..c5ccbb796e 100644--- a/js/app/packages/core/component/DocumentPreview.tsx+++ b/js/app/packages/core/component/DocumentPreview.tsx@@ -45,8 +45,20 @@ import { UserIcon as UserIconComponent } from '@core/component/UserIcon';import { createCallback } from '@solid-primitives/rootless';import { useNavigate } from '@solidjs/router';import { globalSplitManager } from 'app/signal/splitLayout';+import { fetchBinary } from '@service-storage/util/fetchBinary';+import { isErr } from '@core/util/maybeResult';import type { Component, JSX } from 'solid-js';-import { createMemo, For, Match, Show, Suspense, Switch } from 'solid-js';+import {+ createEffect,+ createMemo,+ createSignal,+ For,+ Match,+ onCleanup,+ Show,+ Suspense,+ Switch,+} from 'solid-js';import { Dynamic } from 'solid-js/web';import { useEntityProperties } from '@core/component/Properties/hooks';import { SYSTEM_PROPERTY_IDS } from '@core/component/Properties/constants';@@ -268,13 +280,49 @@ function UserInfo(props: { userId: string }) {/*** Popup preview component for document references*/-function ImageCoverStrip(props: { documentId: string; class?: string }) {+function ImageCoverStrip(props: {+ documentId: string;+ fileType?: string;+ class?: string;+}) {const query = useBinaryDocumentQuery(() => props.documentId);// Captured once at mount: true means the spinner was shown and we should fade in.// Reading .isLoading (not .data) avoids triggering Suspense here.const shouldFadeIn = query.isLoading;+ // SVGs served from presigned URLs may not carry the correct Content-Type header+ // (especially for older uploads), which causes <img> to show a broken image.+ // Fetching as a blob and creating an object URL with an explicit MIME type+ // bypasses this, matching the approach used by the full image viewer.+ const [svgObjectUrl, setSvgObjectUrl] = createSignal<string | undefined>();+ createEffect(() => {+ const presignedUrl = query.data;+ if (!presignedUrl || props.fileType !== 'svg') return;++ const controller = new AbortController();+ let objectUrl: string | undefined;+ fetchBinary(presignedUrl, 'blob', { signal: controller.signal }).then(+ (result) => {+ if (controller.signal.aborted || isErr(result)) return;+ const [, blob] = result;+ objectUrl = URL.createObjectURL(+ new Blob([blob], { type: 'image/svg+xml' })+ );+ setSvgObjectUrl(objectUrl);+ }+ );++ onCleanup(() => {+ controller.abort();+ if (objectUrl) URL.revokeObjectURL(objectUrl);+ setSvgObjectUrl(undefined);+ });+ });++ const displayUrl = () =>+ props.fileType === 'svg' ? svgObjectUrl() : query.data;+return (<divclass={`w-full overflow-hidden relative bg-edge-muted ${props.class ?? 'h-32'}`}@@ -286,7 +334,7 @@ function ImageCoverStrip(props: { documentId: string; class?: string }) {</div>}>- <Show when={query.data}>+ <Show when={displayUrl()}>{(url) => (<imgsrc={url()}@@ -704,6 +752,7 @@ export function PopupPreview(props: {<Show when={props.documentInfo.type === 'image'}><ImageCoverStripdocumentId={accessibleItem().id}+ fileType={accessibleItem().fileType}class="shrink-0 h-32"/></Show>diff --git a/js/app/packages/service-clients/service-storage/util/upload.ts b/js/app/packages/service-clients/service-storage/util/upload.tsindex d555bb6723..cc136dc8db 100644--- a/js/app/packages/service-clients/service-storage/util/upload.ts+++ b/js/app/packages/service-clients/service-storage/util/upload.ts@@ -11,6 +11,7 @@ import { filenameWithoutExtension } from '@service-storage/util/filename';import { uploadToPresignedUrl } from '@service-storage/util/uploadToPresignedUrl';import { storageWS } from '@service-storage/websocket';import { createUploadToast, toast } from 'core/component/Toast/Toast';+import { FileTypeMap } from '../fileTypeMap';import { uploadDocx } from './uploadDocx';const dismissToast = (toastId: number | null) => {@@ -207,12 +208,21 @@ export async function upload(},] = newfile;+ const fallbackMime = fileType+ ? (FileTypeMap[fileType as keyof typeof FileTypeMap]?.mime as+ | MimeType+ | undefined)+ : undefined;+ const resolvedContentType = (contentType ||+ fallbackMime ||+ 'application/octet-stream') as MimeType;+if (!(await uploadWithPresignedUrl({presignedUrl,buffer,sha,- type: contentType,+ type: resolvedContentType,}))) {console.error('failed to upload', documentId, 'removing...');