* 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
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
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");
|
|
});
|
|
});
|