filemanager: Implement clipboard handling

This commit is contained in:
Johannes Zellner
2023-04-25 22:45:22 +02:00
parent 9c5a7eb6bb
commit 8f25c91272
4 changed files with 48 additions and 21 deletions
+14 -1
View File
@@ -1,6 +1,6 @@
import superagent from 'superagent';
import { sanitize } from 'pankow/utils';
import { buildFilePath, sanitize } from 'pankow/utils';
const BASE_URL = import.meta.env.BASE_URL || '/';
@@ -17,6 +17,8 @@ export function createDirectoryModel(origin, accessToken, api) {
}
if (error || result.statusCode !== 200) {
if (error.status === 404) return [];
console.error('Failed to list files', error || result.statusCode);
return [];
}
@@ -69,6 +71,11 @@ export function createDirectoryModel(origin, accessToken, api) {
.send({ action: 'rename', newFilePath: sanitize(toFilePath) })
.query({ access_token: accessToken });
},
async copy(fromFilePath, toFilePath) {
await superagent.put(`${origin}/api/v1/${api}/files/${fromFilePath}`)
.send({ action: 'copy', newFilePath: sanitize(toFilePath) })
.query({ access_token: accessToken });
},
async chown(filePath, uid) {
await superagent.put(`${origin}/api/v1/${api}/files/${filePath}`)
.send({ action: 'chown', uid: uid, recursive: true })
@@ -93,6 +100,12 @@ export function createDirectoryModel(origin, accessToken, api) {
const text = await result.text();
return text;
},
async paste(targetDir, action, files) {
for (let f in files) {
if (action === 'cut') await this.rename(buildFilePath(files[f].folderPath, files[f].name), targetDir + '/' + files[f].name);
if (action === 'copy') await this.copy(buildFilePath(files[f].folderPath, files[f].name), targetDir + '/' + files[f].name);
}
},
getFileUrl(path) {
return `${origin}/api/v1/${api}/files/${path}?access_token=${accessToken}`;
}