2023-03-15 09:26:11 +01:00
|
|
|
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 {
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-15 17:16:06 +01:00
|
|
|
getModalOptions(storagehub: StoragehubService, uploaderInfo: UploaderInfoService, data: any, reload: Function, notify: Function, onSelectionFinished: Function): ModalOptions {
|
2023-03-15 09:26:11 +01:00
|
|
|
return {
|
|
|
|
component: WsViewerComponent,
|
|
|
|
componentProps: {
|
|
|
|
finishLabel: "Upload here",
|
|
|
|
title: "Select destination folder",
|
|
|
|
notClickableIds: [],
|
|
|
|
notSelectableIds: [],
|
|
|
|
onSelected: (destinationItem: WSItem) => {
|
|
|
|
const itemId = destinationItem.item.id;
|
2023-03-15 17:16:06 +01:00
|
|
|
|
2023-03-15 09:26:11 +01:00
|
|
|
uploaderInfo.uploadStarted(itemId, data.title);
|
|
|
|
this.actionHandler(destinationItem, data, storagehub).then( obs => obs.subscribe({
|
|
|
|
next: () => {},
|
2023-03-15 17:16:06 +01:00
|
|
|
error: err => {
|
|
|
|
uploaderInfo.uploadFinished(itemId, data.title);
|
|
|
|
notify(`error uploading file ${data.title} to workspace`);
|
|
|
|
},
|
2023-03-15 09:26:11 +01:00
|
|
|
complete: () => {
|
|
|
|
notify(`uploaded file ${data.title}`);
|
|
|
|
uploaderInfo.uploadFinished(itemId, data.title),
|
|
|
|
reload(itemId);
|
2023-03-15 17:16:06 +01:00
|
|
|
onSelectionFinished();
|
2023-03-15 09:26:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|