//
// SPDX-License-Identifier: AGPL-3.0
-import { CommonResourceService } from "../../common/api/common-resource-service";
-import { CollectionResource } from "../../models/collection";
+import { CommonResourceService } from "~/common/api/common-resource-service";
+import { CollectionResource } from "~/models/collection";
import { AxiosInstance } from "axios";
-import { CollectionFile, CollectionDirectory } from "../../models/collection-file";
-import { WebDAV } from "../../common/webdav";
+import { CollectionFile, CollectionDirectory } from "~/models/collection-file";
+import { WebDAV } from "~/common/webdav";
import { AuthService } from "../auth-service/auth-service";
-import { mapTreeValues } from "../../models/tree";
+import { mapTreeValues } from "~/models/tree";
import { parseFilesResponse } from "./collection-service-files-response";
-import { fileToArrayBuffer } from "../../common/file";
+import { fileToArrayBuffer } from "~/common/file";
export type UploadProgress = (fileId: number, loaded: number, total: number, currentTime: number) => void;
return Promise.reject();
}
- async deleteFile(collectionUuid: string, filePath: string) {
- return this.webdavClient.delete(`/c=${collectionUuid}${filePath}`);
+ async deleteFiles(collectionUuid: string, filePaths: string[]) {
+ for (const path of filePaths) {
+ await this.webdavClient.delete(`/c=${collectionUuid}${path}`);
+ }
}
async uploadFiles(collectionUuid: string, files: File[], onProgress?: UploadProgress) {
+ // files have to be uploaded sequentially
for (let idx = 0; idx < files.length; idx++) {
await this.uploadFile(collectionUuid, files[idx], idx, onProgress);
}
}
+ moveFile(collectionUuid: string, oldPath: string, newPath: string) {
+ return this.webdavClient.move(
+ `/c=${collectionUuid}${oldPath}`,
+ `/c=${collectionUuid}${encodeURI(newPath)}`
+ );
+ }
+
private extendFileURL = (file: CollectionDirectory | CollectionFile) => ({
...file,
url: this.webdavClient.defaults.baseURL + file.url + '?api_token=' + this.authService.getApiToken()