Handle browsers without DataTransfer in chat guard
This commit is contained in:
parent
c138e39586
commit
fc2047ca1e
@ -45,13 +45,12 @@
|
||||
const prepared=[];let saved=0;
|
||||
for(const f of raw){try{const p=await prepareAttachment(f);prepared.push(p.file);saved+=p.savedBytes;}catch(e){toast(e.message||String(e),'warn',6000);}}
|
||||
if(!prepared.length){input.value='';return;}
|
||||
if(typeof DataTransfer==='undefined')return;
|
||||
const dt=new DataTransfer();prepared.forEach(f=>dt.items.add(f));input.files=dt.files;
|
||||
guardedInputs.add(input);input.dispatchEvent(new Event('change',{bubbles:true}));guardedInputs.delete(input);
|
||||
if(saved>256*1024)toast(`Фото оптимизированы: сэкономлено ${(saved/1024/1024).toFixed(1)} МБ.`,'success',4200);
|
||||
}
|
||||
document.addEventListener('change',e=>{
|
||||
const input=e.target;if(!(input instanceof HTMLInputElement)||input.id!=='sunChatFilesV29'||guardedInputs.has(input))return;
|
||||
const input=e.target;if(!(input instanceof HTMLInputElement)||input.id!=='sunChatFilesV29'||guardedInputs.has(input)||typeof DataTransfer==='undefined')return;
|
||||
e.preventDefault();e.stopImmediatePropagation();guardChatFiles(input).catch(err=>{console.error('[Caterium photo compression]',err);guardedInputs.add(input);input.dispatchEvent(new Event('change',{bubbles:true}));guardedInputs.delete(input);});
|
||||
},true);
|
||||
window.SunAttachmentGuard={VERSION:'17.6.1',MAX_FILE,TARGET,MAX_SIDE,compressImage,prepareAttachment};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user