portainer/app/agent/components/file-uploader/fileUploaderController.js

30 lines
605 B
JavaScript

export class FileUploaderController {
constructor($async) {
Object.assign(this, { $async });
this.state = {
uploadInProgress: false,
};
this.onFileSelected = this.onFileSelected.bind(this);
this.onFileSelectedAsync = this.onFileSelectedAsync.bind(this);
}
onFileSelected(file) {
return this.$async(this.onFileSelectedAsync, file);
}
async onFileSelectedAsync(file) {
if (!file) {
return;
}
this.state.uploadInProgress = true;
try {
await this.uploadFile(file);
} finally {
this.state.uploadInProgress = false;
}
}
}