download/upload implementation for the web

This commit is contained in:
Eugene Pankov
2021-06-12 13:05:09 +02:00
parent a397884d3c
commit 9e17ce157d
5 changed files with 81 additions and 32 deletions

View File

@@ -10,7 +10,7 @@ export { Theme } from './theme'
export { TabContextMenuItemProvider } from './tabContextMenuProvider'
export { SelectorOption } from './selector'
export { CLIHandler, CLIEvent } from './cli'
export { PlatformService, ClipboardContent, MessageBoxResult, MessageBoxOptions, FileDownload, FileUpload, FileTransfer, FileUploadOptions } from './platform'
export { PlatformService, ClipboardContent, MessageBoxResult, MessageBoxOptions, FileDownload, FileUpload, FileTransfer, HTMLFileUpload, FileUploadOptions } from './platform'
export { MenuItemOptions } from './menu'
export { BootstrapData, BOOTSTRAP_DATA } from './mainProcess'
export { HostWindowService } from './hostWindow'

View File

@@ -88,7 +88,7 @@ export abstract class PlatformService {
abstract startDownload (name: string, size: number): Promise<FileDownload|null>
abstract startUpload (options?: FileUploadOptions): Promise<FileUpload[]>
startUploadFromDragEvent (event: DragEvent): FileUpload[] {
startUploadFromDragEvent (event: DragEvent, multiple = false): FileUpload[] {
const result: FileUpload[] = []
if (!event.dataTransfer) {
return []
@@ -96,9 +96,12 @@ export abstract class PlatformService {
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < event.dataTransfer.files.length; i++) {
const file = event.dataTransfer.files[i]
const transfer = new DropUpload(file)
const transfer = new HTMLFileUpload(file)
this.fileTransferStarted.next(transfer)
result.push(transfer)
if (!multiple) {
break
}
}
return result
}
@@ -160,8 +163,7 @@ export abstract class PlatformService {
abstract quit (): void
}
class DropUpload extends FileUpload {
export class HTMLFileUpload extends FileUpload {
private stream: ReadableStream
private reader: ReadableStreamDefaultReader