Use local buildFilePath

This commit is contained in:
Johannes Zellner
2023-09-20 10:04:24 +02:00
parent 585bd04c42
commit 51d49ef60a
2 changed files with 18 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
import superagent from 'superagent';
import { buildFilePath, sanitize } from 'pankow/utils';
import { sanitize } from 'pankow/utils';
const BASE_URL = import.meta.env.BASE_URL || '/';
@@ -8,6 +8,13 @@ export function createDirectoryModel(origin, accessToken, api) {
return {
name: 'DirectoryModel',
buildFilePath(filePath, fileName) {
// remove leading and trailing slashes
while (filePath.startsWith('/')) filePath = filePath.slice(1);
while (filePath.endsWith('/')) filePath = filePath.slice(0, -1);
return encodeURIComponent(`${filePath}${filePath ? '/' : ''}${fileName}`);
},
async listFiles(path) {
let error, result;
try {
@@ -118,8 +125,8 @@ export function createDirectoryModel(origin, accessToken, api) {
let targetPath = targetDir + '/' + files[f].name;
while (!done) {
try {
if (action === 'cut') await this.rename(buildFilePath(files[f].folderPath, files[f].name), targetPath);
if (action === 'copy') await this.copy(buildFilePath(files[f].folderPath, files[f].name), targetPath);
if (action === 'cut') await this.rename(this.buildFilePath(files[f].folderPath, files[f].name), targetPath);
if (action === 'copy') await this.copy(this.buildFilePath(files[f].folderPath, files[f].name), targetPath);
done = true;
} catch (error) {
if (error.status === 409) {