diff --git a/src/models/DirectoryModel.js b/src/models/DirectoryModel.js index 30cd939b1..e1c084d30 100644 --- a/src/models/DirectoryModel.js +++ b/src/models/DirectoryModel.js @@ -1,6 +1,7 @@ import superagent from 'superagent'; import safe from 'safetydance'; +import { sanitize } from 'pankow/utils'; export function createDirectoryModel(origin, accessToken, appId) { return { @@ -21,8 +22,16 @@ export function createDirectoryModel(origin, accessToken, appId) { return result.body.entries; }, - async rename(oldPath, newPath) { - + async remove(filePath) { + const [error] = await safe(superagent.del(`${origin}/api/v1/apps/${appId}/files/${filePath}`) + .query({ access_token: accessToken })); + if (error) throw error; + }, + async rename(fromFilePath, toFilePath) { + const [error] = await safe(superagent.put(`${origin}/api/v1/apps/${appId}/files/${fromFilePath}`) + .send({ action: 'rename', newFilePath: sanitize(toFilePath) }) + .query({ access_token: accessToken })); + if (error) throw error; }, async getFile(path) { const [error, result] = await safe(fetch(`${origin}/api/v1/apps/${appId}/files/${path}?access_token=${accessToken}`)); diff --git a/src/views/Home.vue b/src/views/Home.vue index 29186602f..4655efe2d 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -150,14 +150,16 @@ export default { else this.$router.push(`/viewer/${this.activeApp.id}${sanitize(this.cwd + '/' + item.name)}`); }, async deleteHandler(files) { - console.log('now delete', files); + if (!files) return; + + for (let i in files) { + await this.directoryModel.remove(buildFilePath(this.cwd, files[i].name)) + } + await this.loadCwd(); }, async renameHandler(file, newName) { - const [error] = await safe(superagent.put(`${BASE_URL}/api/v1/apps/${this.selectedAppId}/files/${buildFilePath(this.cwd, file.name)}`) - .send({ action: 'rename', newFilePath: sanitize(this.cwd + '/' + newName) }) - .query({ access_token: localStorage.accessToken })); - if (error) throw error; + await this.directoryModel.rename(buildFilePath(this.cwd, file.name), sanitize(this.cwd + '/' + newName)) await this.loadCwd(); }, async loadCwd() {