@@ -1030,7 +1030,7 @@ async function initRepository() {
1030
1030
if ( $dropzone . length === 1 ) {
1031
1031
$dropzone . data ( 'saved' , false ) ;
1032
1032
1033
- const filenameDict = { } ;
1033
+ const fileUuidDict = { } ;
1034
1034
dz = await createDropzone ( $dropzone [ 0 ] , {
1035
1035
url : $dropzone . data ( 'upload-url' ) ,
1036
1036
headers : { 'X-Csrf-Token' : csrf } ,
@@ -1048,28 +1048,24 @@ async function initRepository() {
1048
1048
thumbnailHeight : 480 ,
1049
1049
init ( ) {
1050
1050
this . on ( 'success' , ( file , data ) => {
1051
- filenameDict [ file . name ] = {
1052
- uuid : data . uuid ,
1051
+ fileUuidDict [ file . uuid ] = {
1053
1052
submitted : false
1054
1053
} ;
1055
1054
const input = $ ( `<input id="${ data . uuid } " name="files" type="hidden">` ) . val ( data . uuid ) ;
1056
1055
$dropzone . find ( '.files' ) . append ( input ) ;
1057
1056
} ) ;
1058
1057
this . on ( 'removedfile' , ( file ) => {
1059
- if ( ! ( file . name in filenameDict ) ) {
1060
- return ;
1061
- }
1062
- $ ( `#${ filenameDict [ file . name ] . uuid } ` ) . remove ( ) ;
1063
- if ( $dropzone . data ( 'remove-url' ) && ! filenameDict [ file . name ] . submitted ) {
1058
+ $ ( `#${ file . uuid } ` ) . remove ( ) ;
1059
+ if ( $dropzone . data ( 'remove-url' ) && ! fileUuidDict [ file . uuid ] . submitted ) {
1064
1060
$ . post ( $dropzone . data ( 'remove-url' ) , {
1065
- file : filenameDict [ file . name ] . uuid ,
1061
+ file : file . uuid ,
1066
1062
_csrf : csrf ,
1067
1063
} ) ;
1068
1064
}
1069
1065
} ) ;
1070
1066
this . on ( 'submit' , ( ) => {
1071
- $ . each ( filenameDict , ( name ) => {
1072
- filenameDict [ name ] . submitted = true ;
1067
+ $ . each ( fileUuidDict , ( fileUuid ) => {
1068
+ fileUuidDict [ fileUuid ] . submitted = true ;
1073
1069
} ) ;
1074
1070
} ) ;
1075
1071
this . on ( 'reload' , ( ) => {
@@ -1082,9 +1078,8 @@ async function initRepository() {
1082
1078
dz . emit ( 'thumbnail' , this , imgSrc ) ;
1083
1079
dz . emit ( 'complete' , this ) ;
1084
1080
dz . files . push ( this ) ;
1085
- filenameDict [ this . name ] = {
1081
+ fileUuidDict [ this . uuid ] = {
1086
1082
submitted : true ,
1087
- uuid : this . uuid
1088
1083
} ;
1089
1084
$dropzone . find ( `img[src='${ imgSrc } ']` ) . css ( 'max-width' , '100%' ) ;
1090
1085
const input = $ ( `<input id="${ this . uuid } " name="files" type="hidden">` ) . val ( this . uuid ) ;
@@ -2674,7 +2669,6 @@ $(document).ready(async () => {
2674
2669
2675
2670
// Dropzone
2676
2671
for ( const el of document . querySelectorAll ( '.dropzone' ) ) {
2677
- const filenameDict = { } ;
2678
2672
const $dropzone = $ ( el ) ;
2679
2673
await createDropzone ( el , {
2680
2674
url : $dropzone . data ( 'upload-url' ) ,
@@ -2692,18 +2686,15 @@ $(document).ready(async () => {
2692
2686
thumbnailWidth : 480 ,
2693
2687
thumbnailHeight : 480 ,
2694
2688
init ( ) {
2695
- this . on ( 'success' , ( file , data ) => {
2696
- filenameDict [ file . name ] = data . uuid ;
2689
+ this . on ( 'success' , ( _file , data ) => {
2697
2690
const input = $ ( `<input id="${ data . uuid } " name="files" type="hidden">` ) . val ( data . uuid ) ;
2698
2691
$dropzone . find ( '.files' ) . append ( input ) ;
2699
2692
} ) ;
2700
2693
this . on ( 'removedfile' , ( file ) => {
2701
- if ( file . name in filenameDict ) {
2702
- $ ( `#${ filenameDict [ file . name ] } ` ) . remove ( ) ;
2703
- }
2694
+ $ ( `#${ file . uuid } ` ) . remove ( ) ;
2704
2695
if ( $dropzone . data ( 'remove-url' ) ) {
2705
2696
$ . post ( $dropzone . data ( 'remove-url' ) , {
2706
- file : filenameDict [ file . name ] ,
2697
+ file : file . uuid ,
2707
2698
_csrf : csrf
2708
2699
} ) ;
2709
2700
}
0 commit comments