57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
|
import { ModalOptions } from "@ionic/angular";
|
||
|
import { StoragehubService } from "src/app/storagehub.service";
|
||
|
import { WsViewerComponent } from "src/app/ws-viewer/ws-viewer.component";
|
||
|
import { WSItem } from "../ws-item";
|
||
|
import { Filesystem } from "@capacitor/filesystem";
|
||
|
import { UploaderInfoService } from "src/app/uploader-info.service";
|
||
|
|
||
|
export class UploadFile {
|
||
|
|
||
|
|
||
|
|
||
|
getModalOptions(storagehub: StoragehubService, uploaderInfo: UploaderInfoService, data: any, reload: Function, notify: Function): ModalOptions {
|
||
|
return {
|
||
|
component: WsViewerComponent,
|
||
|
componentProps: {
|
||
|
finishLabel: "Upload here",
|
||
|
title: "Select destination folder",
|
||
|
notClickableIds: [],
|
||
|
notSelectableIds: [],
|
||
|
onSelected: (destinationItem: WSItem) => {
|
||
|
const itemId = destinationItem.item.id;
|
||
|
uploaderInfo.uploadStarted(itemId, data.title);
|
||
|
this.actionHandler(destinationItem, data, storagehub).then( obs => obs.subscribe({
|
||
|
next: () => {},
|
||
|
error: err => uploaderInfo.uploadFinished(itemId, data.title),
|
||
|
complete: () => {
|
||
|
notify(`uploaded file ${data.title}`);
|
||
|
uploaderInfo.uploadFinished(itemId, data.title),
|
||
|
reload(itemId);
|
||
|
},
|
||
|
|
||
|
}
|
||
|
));
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
|
||
|
async actionHandler(destinationItem: WSItem, result: any, storagehub: StoragehubService) {
|
||
|
const pathDecodedWebPath = decodeURIComponent(result.webPath);
|
||
|
|
||
|
const file = await fetch(pathDecodedWebPath)
|
||
|
.then(res => res.blob()) // Gets the response and returns it as a blob
|
||
|
.then(blob => { return new File([blob], result.title)});
|
||
|
|
||
|
console.log("before uploading file ");
|
||
|
return storagehub.uploadFile(destinationItem.item.id, result.title, file);
|
||
|
}
|
||
|
|
||
|
getName(): string {
|
||
|
return "UploadFile";
|
||
|
}
|
||
|
getActionType(): string | undefined {
|
||
|
return undefined;
|
||
|
}
|
||
|
}
|