22 lines
979 B
TypeScript
22 lines
979 B
TypeScript
import BaseElements from './require/base-elements.js';
|
|
|
|
import { Channel, ShouldNeverHappenError } from '../data-types';
|
|
import ClientController from '../client-controller.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, {
|
|
server: server, 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;
|
|
}
|