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(static/video): add mimetypes from filename for safari playback (#4071)
Seamusdb28ae272980
diff --git a/js/app/packages/core/util/create.ts b/js/app/packages/core/util/create.tsindex d891d62251..3865e1979c 100644--- a/js/app/packages/core/util/create.ts+++ b/js/app/packages/core/util/create.ts@@ -26,6 +26,7 @@ import {isCodeEditorExtensionSupported,isCodeEditorLanguageSupported,} from './languageQuery';+import { resolveUploadContentType } from './uploadContentType';type CreateMarkdownFileArgs = {title?: string;@@ -313,9 +314,10 @@ export async function createChat(args?: CreateChatRequest) {/** Uploads a file to the static file service and returns the id */export async function createStaticFile(file: File): Promise<string> {+ const contentType = resolveUploadContentType(file);const result = await staticFileClient.makePresignedUrl({file_name: file.name,- content_type: file.type,+ content_type: contentType,});invalidateUserQuota();if (result.isErr()) throw new Error('Failed to upload file');@@ -324,6 +326,7 @@ export async function createStaticFile(file: File): Promise<string> {const uploadResult = await staticFileClient.uploadToPresignedUrl({url: upload_url,blob: file,+ contentType,});if (!uploadResult.success) {throw new Error('Failed to upload file');diff --git a/js/app/packages/core/util/uploadContentType.test.ts b/js/app/packages/core/util/uploadContentType.test.tsnew file mode 100644index 0000000000..799fc5799d--- /dev/null+++ b/js/app/packages/core/util/uploadContentType.test.ts@@ -0,0 +1,31 @@+import { describe, expect, it } from 'vitest';+import { resolveUploadContentType } from './uploadContentType';++describe('resolveUploadContentType', () => {+ it('keeps a specific explicit mime type', () => {+ expect(+ resolveUploadContentType({+ name: 'clip.mov',+ mimeType: 'video/quicktime',+ })+ ).toBe('video/quicktime');+ });++ it('infers a video mime type from the filename when none is provided', () => {+ expect(+ resolveUploadContentType({+ name: 'clip.mov',+ mimeType: '',+ })+ ).toBe('video/quicktime');+ });++ it('replaces generic octet-stream with a known extension mime type', () => {+ expect(+ resolveUploadContentType({+ name: 'clip.mp4',+ mimeType: 'application/octet-stream',+ })+ ).toBe('video/mp4');+ });+});diff --git a/js/app/packages/core/util/uploadContentType.ts b/js/app/packages/core/util/uploadContentType.tsnew file mode 100644index 0000000000..1700c344f1--- /dev/null+++ b/js/app/packages/core/util/uploadContentType.ts@@ -0,0 +1,28 @@+import { FileTypeMap } from '@service-storage/fileTypeMap';++function fileExtension(filename: string): string | undefined {+ const lastDotIndex = filename.lastIndexOf('.');+ return lastDotIndex === -1+ ? undefined+ : filename.substring(lastDotIndex + 1).toLowerCase();+}++export function resolveUploadContentType(file: {+ name: string;+ mimeType?: string;+ type?: string;+}): string | undefined {+ const explicitType = file.mimeType || file.type;+ if (explicitType && explicitType !== 'application/octet-stream') {+ return explicitType;+ }++ const ext = fileExtension(file.name);+ if (!ext) return explicitType || undefined;++ return (+ FileTypeMap[ext as keyof typeof FileTypeMap]?.mime ||+ explicitType ||+ undefined+ );+}diff --git a/js/app/packages/core/util/uploadFile.ts b/js/app/packages/core/util/uploadFile.tsindex fbd40de4e1..092a6b6ca3 100644--- a/js/app/packages/core/util/uploadFile.ts+++ b/js/app/packages/core/util/uploadFile.ts@@ -6,6 +6,7 @@ import {import { invalidateUserQuota } from '@queries/auth';import { staticFileClient } from '@service-static-files/client';import { contentHash } from './hash';+import { resolveUploadContentType } from './uploadContentType';/*** App-level upload file model.@@ -64,9 +65,10 @@ export function isNativeStagedUpload(export async function createStaticUploadFile(file: UploadFile): Promise<string> {+ const contentType = resolveUploadContentType(file);const result = await staticFileClient.makePresignedUrl({file_name: file.name,- content_type: file.mimeType,+ content_type: contentType,});invalidateUserQuota();if (result.isErr()) throw new Error('Failed to upload file');@@ -80,6 +82,7 @@ export async function createStaticUploadFile(const uploadResult = await staticFileClient.uploadToPresignedUrl({url: upload_url,blob: file.file,+ contentType,});if (!uploadResult.success) {throw new Error('Failed to upload file');diff --git a/js/app/packages/service-clients/service-static-files/client.ts b/js/app/packages/service-clients/service-static-files/client.tsindex 14223e3ae6..9e98b8369a 100644--- a/js/app/packages/service-clients/service-static-files/client.ts+++ b/js/app/packages/service-clients/service-static-files/client.ts@@ -59,10 +59,15 @@ export const staticFileClient = {return await staticFetch(`/file/${args.file_id}`, { method: 'GET' });},- async uploadToPresignedUrl(args: { url: string; blob: Blob | File }) {+ async uploadToPresignedUrl(args: {+ url: string;+ blob: Blob | File;+ contentType?: string;+ }) {const result = await platformFetch(args.url, {method: 'PUT',body: args.blob,+ headers: args.contentType ? { 'Content-Type': args.contentType } : {},});return { success: result.ok };},diff --git a/js/bun.lock b/js/bun.lockindex ce05b8b420..107f7a5775 100644--- a/js/bun.lock+++ b/js/bun.lock@@ -846,7 +846,7 @@"@img/sharp-win32-x64": ["@img/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-+29YMsqY2/9eFEiW93eqWnuLcWcufowXewwSNIT6UwZdUUCrM3oFjMWH/Z6/TMmb4hlFenmfAVbpWeup2jryCw=="],- "@inkibra/tauri-plugins": ["@inkibra/tauri-plugins@github:macro-inc/tauri-plugins#26537c8", { "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" } }, "macro-inc-tauri-plugins-26537c8", "sha512-6p5xQAkS6Uw6J8Uh0vlj6MjKZXWps5E1Gu0hciBFq1E2BfPBZAgdeeafKnR3diNb4SXWK0JML49nAr+o5PhwKw=="],+ "@inkibra/tauri-plugins": ["@inkibra/tauri-plugins@github:macro-inc/tauri-plugins#26537c8", { "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" } }, "macro-inc-tauri-plugins-26537c8"],"@inquirer/external-editor": ["@inquirer/[email protected]", "", { "dependencies": { "chardet": "^2.1.1", "iconv-lite": "^0.7.0" }, "peerDependencies": { "@types/node": ">=18" }, "optionalPeers": ["@types/node"] }, "sha512-RWbSrDiYmO4LbejWY7ttpxczuwQyZLBUyygsA9Nsv95hpzUWwnNTVQmAq3xuh7vNwCp07UTmE5i11XAEExx4RA=="],@@ -2576,7 +2576,7 @@"pathval": ["[email protected]", "", {}, "sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ=="],- "pdfjs-dist": ["pdfjs-dist@github:macro-inc/pdf.js#f9b2ce6", { "dependencies": { "dommatrix": "^1.0.3", "web-streams-polyfill": "^3.2.1" }, "peerDependencies": { "worker-loader": "^3.0.8" }, "optionalPeers": ["worker-loader"] }, "macro-inc-pdf.js-f9b2ce6", "sha512-HDFaPbCxLG2GHpf1smUG97nku5aPGBGaCcIbK05dGdp07TBLUlDcXsM4WcE82mO5W4RBPIBVYobX5N/6M6NFrA=="],+ "pdfjs-dist": ["pdfjs-dist@github:macro-inc/pdf.js#f9b2ce6", { "dependencies": { "dommatrix": "^1.0.3", "web-streams-polyfill": "^3.2.1" }, "peerDependencies": { "worker-loader": "^3.0.8" }, "optionalPeers": ["worker-loader"] }, "macro-inc-pdf.js-f9b2ce6"],"performance-now": ["[email protected]", "", {}, "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow=="],