import BaseElements from './require/base-elements.js'; import { Channel, ShouldNeverHappenError } from '../data-types'; import CombinedGuild from '../guild-combined.js'; export default function createUploadOverlayFromDataTransferItem(document: Document, guild: CombinedGuild, channel: Channel, dataTransferItem: DataTransferItem): HTMLElement { let file = dataTransferItem.getAsFile(); if (file === null) throw new ShouldNeverHappenError('no file in the data transfer item'); let element = BaseElements.createUploadOverlay(document, { guild: guild, channel: channel, resourceName: file.name, resourceBuffFunc: async () => { if (file === null) throw new ShouldNeverHappenError('no file in the data transfer item'); return Buffer.from(await file.arrayBuffer()); }, resourceSizeFunc: () => { if (file === null) throw new ShouldNeverHappenError('no file in the data transfer item'); return file.size; } }); return element; }