@ -41,12 +41,9 @@
import type { FileAction , Node } from '@nextcloud/files'
import type { FileAction , Node } from '@nextcloud/files'
import type { PropType } from 'vue'
import type { PropType } from 'vue'
import axios , { isAxiosError } from '@nextcloud/axios'
import { showError , showSuccess } from '@nextcloud/dialogs'
import { showError , showSuccess } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { FileType , NodeStatus } from '@nextcloud/files'
import { FileType , NodeStatus } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import { translate as t } from '@nextcloud/l10n'
import { dirname } from '@nextcloud/paths'
import { defineComponent , inject } from 'vue'
import { defineComponent , inject } from 'vue'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
@ -245,66 +242,23 @@ export default defineComponent({
}
}
const oldName = this . source . basename
const oldName = this . source . basename
const oldEncodedSource = this . source . encodedSource
if ( oldName === newName ) {
this . stopRenaming ( )
return
}
/ / S e t l o a d i n g s t a t e
this . $set ( this . source , 'status' , NodeStatus . LOADING )
/ / U p d a t e n o d e
this . source . rename ( newName )
logger . debug ( 'Moving file to' , { destination : this . source . encodedSource , oldEncodedSource } )
try {
try {
await axios ( {
const status = await this . renamingStore . rename ( )
method : 'MOVE' ,
if ( status ) {
url : oldEncodedSource ,
headers : {
Destination : this . source . encodedSource ,
Overwrite : 'F' ,
} ,
} )
/ / S u c c e s s 🎉
emit ( 'files:node:updated' , this . source )
emit ( 'files:node:renamed' , this . source )
emit ( 'files:node:moved' , {
node : this . source ,
oldSource : ` ${ dirname ( this . source . source ) } / ${ oldName } ` ,
} )
showSuccess ( t ( 'files' , 'Renamed "{oldName}" to "{newName}"' , { oldName , newName } ) )
showSuccess ( t ( 'files' , 'Renamed "{oldName}" to "{newName}"' , { oldName , newName } ) )
/ / R e s e t t h e r e n a m i n g s t o r e
this . stopRenaming ( )
this . $nextTick ( ( ) => {
this . $nextTick ( ( ) => {
const nameContainter = this . $refs . basename as HTMLElement | undefined
const nameContainter = this . $refs . basename as HTMLElement | undefined
nameContainter ? . focus ( )
nameContainter ? . focus ( )
} )
} )
} else {
/ / W a s c a n c e l l e d - m e a n i n g t h e r e n a m i n g s t a t e i s j u s t r e s e t
}
} catch ( error ) {
} catch ( error ) {
logger . error ( 'Error while renaming file' , { error } )
logger . error ( error as Error )
/ / R e n a m e b a c k a s i t f a i l e d
showError ( ( error as Error ) . message )
this . source . rename ( oldName )
/ / A n d e n s u r e w e r e s e t t o t h e r e n a m i n g s t a t e
/ / A n d e n s u r e w e r e s e t t o t h e r e n a m i n g s t a t e
this . startRenaming ( )
this . startRenaming ( )
if ( isAxiosError ( error ) ) {
/ / T O D O : 4 0 9 m e a n s c u r r e n t f o l d e r d o e s n o t e x i s t , r e d i r e c t ?
if ( error ? . response ? . status === 404 ) {
showError ( t ( 'files' , 'Could not rename "{oldName}", it does not exist any more' , { oldName } ) )
return
} else if ( error ? . response ? . status === 412 ) {
showError ( t ( 'files' , 'The name "{newName}" is already used in the folder "{dir}". Please choose a different name.' , { newName , dir : this . directory } ) )
return
}
}
/ / U n k n o w n e r r o r
showError ( t ( 'files' , 'Could not rename "{oldName}"' , { oldName } ) )
} finally {
this . $set ( this . source , 'status' , undefined )
}
}
} ,
} ,