add image upload from clipboard
This commit is contained in:
parent
d3aba5c519
commit
1d4a2673b0
1 changed files with 15 additions and 4 deletions
|
@ -129,19 +129,30 @@ elements.imageUploadBtn.addEventListener('click', () => {
|
||||||
imgUploadInput.click();
|
imgUploadInput.click();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.addEventListener('paste', (e) => {
|
||||||
|
if (e.clipboardData?.files.length === 0) return;
|
||||||
|
let file = e.clipboardData!.files[0];
|
||||||
|
if (!file.type.startsWith('image/')) return;
|
||||||
|
if (!window.confirm(`Upload ${file.name} (${Math.round(file.size / 1000)}KB)?`)) return;
|
||||||
|
uploadFile(file);
|
||||||
|
});
|
||||||
|
|
||||||
imgUploadInput.addEventListener('change', async () => {
|
imgUploadInput.addEventListener('change', async () => {
|
||||||
if (!imgUploadInput.files || imgUploadInput.files.length === 0) return;
|
if (!imgUploadInput.files || imgUploadInput.files.length === 0) return;
|
||||||
let file = imgUploadInput.files[0];
|
uploadFile(imgUploadInput.files[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
function uploadFile(file: File) {
|
||||||
let reader = new FileReader();
|
let reader = new FileReader();
|
||||||
reader.onload = async () => {
|
reader.onload = async () => {
|
||||||
let buffer = reader.result as ArrayBuffer;
|
let buffer = reader.result as ArrayBuffer;
|
||||||
await Room?.sendImage(buffer, file.type);
|
await Room?.sendImage(buffer, file.type);
|
||||||
};
|
};
|
||||||
reader.readAsArrayBuffer(file);
|
reader.readAsArrayBuffer(file);
|
||||||
});
|
}
|
||||||
|
|
||||||
let w = window as any;
|
let w = window as any;
|
||||||
|
|
||||||
w.agentchat = {
|
w.agentchat = {
|
||||||
getRoom: () => Room,
|
getRoom: () => Room
|
||||||
}
|
};
|
||||||
|
|
Loading…
Reference in a new issue