cordis/client/webapp/elements/overlay-upload-datatransfer.ts
2021-11-21 20:47:29 -06:00

22 lines
971 B
TypeScript

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;
}