* fix(app): attach dropped files in composer Composer parents had to expose attachment callbacks, so New Workspace only wired image drops and JSON files never became file attachments. Centralize dropped-file ingestion in Composer so all composer surfaces share the same image and file path. * fix(app): handle desktop dropped attachment paths
29 lines
950 B
TypeScript
29 lines
950 B
TypeScript
import { getFileExtension } from "@/attachments/file-types";
|
|
import { copyDesktopAttachmentFile } from "@/desktop/attachments/desktop-file-commands";
|
|
import { readDesktopFileBase64 } from "@/desktop/attachments/desktop-preview-url";
|
|
|
|
export interface PickedFile {
|
|
fileName: string;
|
|
mimeType: string;
|
|
bytes: Uint8Array;
|
|
}
|
|
|
|
function base64ToUint8Array(base64: string): Uint8Array {
|
|
const binaryString = atob(base64);
|
|
const bytes = new Uint8Array(binaryString.length);
|
|
for (let i = 0; i < binaryString.length; i++) {
|
|
bytes[i] = binaryString.charCodeAt(i);
|
|
}
|
|
return bytes;
|
|
}
|
|
|
|
export async function readDesktopFileBytes(path: string): Promise<Uint8Array> {
|
|
const { path: managedPath } = await copyDesktopAttachmentFile({
|
|
attachmentId: crypto.randomUUID(),
|
|
sourcePath: path,
|
|
extension: getFileExtension(path) || null,
|
|
});
|
|
const base64 = await readDesktopFileBase64(managedPath);
|
|
return base64ToUint8Array(base64);
|
|
}
|