filemanager: ask user for confirmation on rename conflict
This commit is contained in:
@@ -90,9 +90,9 @@ export function createDirectoryModel(origin, accessToken, api) {
|
|||||||
await superagent.del(`${origin}/api/v1/${api}/files/${filePath}`)
|
await superagent.del(`${origin}/api/v1/${api}/files/${filePath}`)
|
||||||
.query({ access_token: accessToken });
|
.query({ access_token: accessToken });
|
||||||
},
|
},
|
||||||
async rename(fromFilePath, toFilePath) {
|
async rename(fromFilePath, toFilePath, overwrite = false) {
|
||||||
await superagent.put(`${origin}/api/v1/${api}/files/${fromFilePath}`)
|
await superagent.put(`${origin}/api/v1/${api}/files/${fromFilePath}`)
|
||||||
.send({ action: 'rename', newFilePath: sanitize(toFilePath) })
|
.send({ action: 'rename', newFilePath: sanitize(toFilePath), overwrite })
|
||||||
.query({ access_token: accessToken });
|
.query({ access_token: accessToken });
|
||||||
},
|
},
|
||||||
async copy(fromFilePath, toFilePath) {
|
async copy(fromFilePath, toFilePath) {
|
||||||
|
|||||||
@@ -378,8 +378,24 @@ export default {
|
|||||||
|
|
||||||
},
|
},
|
||||||
async renameHandler(file, newName) {
|
async renameHandler(file, newName) {
|
||||||
await this.directoryModel.rename(this.directoryModel.buildFilePath(this.cwd, file.name), sanitize(this.cwd + '/' + newName));
|
try {
|
||||||
await this.loadCwd();
|
await this.directoryModel.rename(this.directoryModel.buildFilePath(this.cwd, file.name), sanitize(this.cwd + '/' + newName));
|
||||||
|
await this.loadCwd();
|
||||||
|
} catch (e) {
|
||||||
|
if (e.status === 409) {
|
||||||
|
this.$confirm.require({
|
||||||
|
message: this.$t('filemanager.renameDialog.reallyOverwrite'),
|
||||||
|
icon: '',
|
||||||
|
acceptClass: 'p-button-danger',
|
||||||
|
accept: async () => {
|
||||||
|
await this.directoryModel.rename(this.directoryModel.buildFilePath(this.cwd, file.name), sanitize(this.cwd + '/' + newName), true /* overwrite */);
|
||||||
|
await this.loadCwd();
|
||||||
|
this.$confirm.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else console.error(`Failed to rename ${file} to ${newName}`, e);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
async changeOwnerHandler(files, newOwnerUid) {
|
async changeOwnerHandler(files, newOwnerUid) {
|
||||||
if (!files) return;
|
if (!files) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user