diff --git a/src/lib/ChatScreens/DefaultChatScreen.svelte b/src/lib/ChatScreens/DefaultChatScreen.svelte index abe258a5..8a16e92b 100644 --- a/src/lib/ChatScreens/DefaultChatScreen.svelte +++ b/src/lib/ChatScreens/DefaultChatScreen.svelte @@ -28,6 +28,7 @@ import { getInlayAsset } from 'src/ts/process/files/inlays'; import PlaygroundMenu from '../Playground/PlaygroundMenu.svelte'; import { ConnectionOpenStore } from 'src/ts/sync/multiuser'; + import { preventDefault } from 'svelte/legacy'; let messageInput:string = $state('') let messageInputTranslate:string = $state('') @@ -462,6 +463,43 @@ e.preventDefault() } }} + onpaste={(e) => { + const items = e.clipboardData?.items + if(!items){ + return + } + let canceled = false + + for(const item of items){ + if(item.kind === 'file' && item.type.startsWith('image')){ + if(!canceled){ + e.preventDefault() + canceled = true + } + const file = item.getAsFile() + if(file){ + const reader = new FileReader() + reader.onload = async (e) => { + const buf = e.target?.result as ArrayBuffer + const uint8 = new Uint8Array(buf) + const res = await postChatFile({ + name: file.name, + data: uint8 + }) + if(res?.type === 'asset'){ + fileInput.push(res.data) + updateInputSizeAll() + } + if(res?.type === 'text'){ + messageInput += `{{file::${res.name}::${res.data}}}` + updateInputSizeAll() + } + } + reader.readAsArrayBuffer(file) + } + } + } + }} oninput={()=>{updateInputSizeAll();updateInputTransateMessage(false)}} style:height={inputHeight} > diff --git a/src/ts/process/files/multisend.ts b/src/ts/process/files/multisend.ts index e79d5033..be7f8c4c 100644 --- a/src/ts/process/files/multisend.ts +++ b/src/ts/process/files/multisend.ts @@ -194,8 +194,11 @@ type postFileResultText = { type: 'text', name: string } -export async function postChatFile(query:string):Promise{ - const file = await selectSingleFile([ +export async function postChatFile(query:string|{ + name:string, + data:Uint8Array +}):Promise{ + const file = typeof(query) === 'string' ? (await selectSingleFile([ //image format 'jpg', 'jpeg', @@ -220,12 +223,13 @@ export async function postChatFile(query:string):Promise{ 'po', // 'pdf', 'txt' - ]) + ])) : query if(!file){ return null } + const xquery = typeof(query) === 'string' ? query : '' const extention = file.name.split('.').at(-1) console.log(extention) @@ -233,7 +237,7 @@ export async function postChatFile(query:string):Promise{ case 'po':{ await sendPofile({ file: BufferToText(file.data), - query: query + query: xquery }) return { type: 'void' @@ -244,7 +248,7 @@ export async function postChatFile(query:string):Promise{ type: 'text', data: await sendPDFFile({ file: BufferToText(file.data), - query: query + query: xquery }), name: file.name } @@ -254,7 +258,7 @@ export async function postChatFile(query:string):Promise{ type: 'text', data: await sendXMLFile({ file: BufferToText(file.data), - query: query + query: xquery }), name: file.name } @@ -293,7 +297,7 @@ export async function postChatFile(query:string):Promise{ type: 'text', data: await sendTxtFile({ file: BufferToText(file.data), - query: query + query: xquery }), name: file.name }