From 23a3b2a9e84829dcfd34171e502570c14c0c5d95 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Thu, 5 Jun 2025 15:39:10 +0200 Subject: [PATCH] adding document when creating process takes a fileBlob type --- src/pages/account/key-value-section.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/pages/account/key-value-section.ts b/src/pages/account/key-value-section.ts index 66f8b21..a43bfad 100644 --- a/src/pages/account/key-value-section.ts +++ b/src/pages/account/key-value-section.ts @@ -32,11 +32,15 @@ export function createKeyValueSection(title: string, id: string, isRoleSection = storagesInput: HTMLInputElement; validationRules: ValidationRule[]; }[] = []; + type fileBlob = { + type: string, + data: Uint8Array + }; const nonRoleRowStates: { keyInput: HTMLInputElement, valueInput: HTMLInputElement, fileInput: HTMLInputElement, - fileBlob: number[] | null + fileBlob: fileBlob | null }[] = []; const inputStyle = 'flex: 1; height: 2.5rem; padding: 0.5rem; border: 1px solid #ccc; border-radius: 0.375rem;'; @@ -92,8 +96,14 @@ export function createKeyValueSection(title: string, id: string, isRoleSection = fileInput.onchange = async () => { const file = fileInput.files?.[0]; if (!file) return; + const buffer = await file.arrayBuffer(); - rowState.fileBlob = Array.from(new Uint8Array(buffer)); + const uint8 = new Uint8Array(buffer); + + rowState.fileBlob = { + type: file.type, + data: uint8, + }; valueInput.value = `📄 ${file.name}`; valueInput.disabled = true; @@ -105,7 +115,6 @@ export function createKeyValueSection(title: string, id: string, isRoleSection = attachBtn.style.cssText = 'padding: 0.3rem 0.75rem; border: 1px solid #ccc; border-radius: 0.375rem; background: #f0f0f0; cursor: pointer;'; attachBtn.onclick = () => fileInput.click(); - const keyInput = document.createElement('input'); const valueInput = document.createElement('input'); @@ -113,7 +122,7 @@ export function createKeyValueSection(title: string, id: string, isRoleSection = keyInput, valueInput, fileInput, - fileBlob: null as File | null + fileBlob: null as fileBlob | null }; nonRoleRowStates.push(rowState); @@ -170,7 +179,7 @@ export function createKeyValueSection(title: string, id: string, isRoleSection = } return data; } else { - const data: Record = {}; + const data: Record = {}; for (const row of nonRoleRowStates) { const key = row.keyInput.value.trim(); if (!key) continue;