Fix desktop file uploads with extensions (#1741)

* fix(attachments): allow Markdown file uploads on desktop

Desktop file upload copied picked files through managed storage with bare picker extensions like md. Normalize those extensions at the command boundary and pass dot-prefixed extensions from the picker path.

* fix(attachments): stop enumerating generic file types

Generic file uploads should not depend on a hand-maintained non-image MIME table. Keep raster image inference for image handling and use octet-stream for other path-only uploads.

* test(attachments): cover picker extension format
This commit is contained in:
Mohamed Boudra
2026-06-26 14:45:45 +08:00
committed by GitHub
parent 862154541a
commit 28c5e55bd9
5 changed files with 82 additions and 48 deletions

View File

@@ -0,0 +1,65 @@
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { copyAttachmentFileToManagedStorage } from "./attachments";
const originalPaseoHome = process.env.PASEO_HOME;
let testHome: string | null = null;
async function useTempPaseoHome(): Promise<string> {
testHome = await mkdtemp(path.join(os.tmpdir(), "paseo-desktop-attachments-"));
process.env.PASEO_HOME = testHome;
return testHome;
}
describe("desktop attachment files", () => {
afterEach(async () => {
if (originalPaseoHome === undefined) {
delete process.env.PASEO_HOME;
} else {
process.env.PASEO_HOME = originalPaseoHome;
}
if (testHome) {
await rm(testHome, { recursive: true, force: true });
testHome = null;
}
});
it("accepts dot-prefixed picker extensions for managed copies", async () => {
const paseoHome = await useTempPaseoHome();
const sourcePath = path.join(paseoHome, "report.md");
await writeFile(sourcePath, "# Report\n");
const result = await copyAttachmentFileToManagedStorage({
attachmentId: "att_markdown",
sourcePath,
extension: ".md",
});
expect(result).toEqual({
path: path.join(paseoHome, "desktop-attachments", "att_markdown.md"),
byteSize: 9,
});
await expect(readFile(result.path, "utf8")).resolves.toBe("# Report\n");
});
it("normalizes legacy bare extensions for managed copies", async () => {
const paseoHome = await useTempPaseoHome();
const sourcePath = path.join(paseoHome, "report.md");
await writeFile(sourcePath, "# Report\n");
const result = await copyAttachmentFileToManagedStorage({
attachmentId: "att_markdown_legacy",
sourcePath,
extension: "md",
});
expect(result).toEqual({
path: path.join(paseoHome, "desktop-attachments", "att_markdown_legacy.md"),
byteSize: 9,
});
await expect(readFile(result.path, "utf8")).resolves.toBe("# Report\n");
});
});

View File

@@ -40,10 +40,11 @@ function normalizeExtension(value: unknown): string {
throw new Error("Attachment extension must be a string.");
}
const normalized = value.trim().toLowerCase();
if (!EXTENSION_PATTERN.test(normalized)) {
const extension = normalized.startsWith(".") ? normalized : `.${normalized}`;
if (!EXTENSION_PATTERN.test(extension)) {
throw new Error(`Invalid attachment extension: ${value}`);
}
return normalized;
return extension;
}
async function buildManagedAttachmentPath(input: {