filemanager: ask user for confirmation on rename conflict

This commit is contained in:
Johannes Zellner
2024-01-04 15:47:26 +01:00
parent 4f57bed03a
commit c577d3d91f
2 changed files with 20 additions and 4 deletions

View File

@@ -90,9 +90,9 @@ export function createDirectoryModel(origin, accessToken, api) {
await superagent.del(`${origin}/api/v1/${api}/files/${filePath}`)
.query({ access_token: accessToken });
},
async rename(fromFilePath, toFilePath) {
async rename(fromFilePath, toFilePath, overwrite = false) {
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 });
},
async copy(fromFilePath, toFilePath) {

View File

@@ -378,8 +378,24 @@ export default {
},
async renameHandler(file, newName) {
await this.directoryModel.rename(this.directoryModel.buildFilePath(this.cwd, file.name), sanitize(this.cwd + '/' + newName));
await this.loadCwd();
try {
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) {
if (!files) return;