@@ -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 ) ;
@@ -2695,7 +2690,6 @@ $(document).ready(async () => {
2695
2690
2696
2691
// Dropzone
2697
2692
for ( const el of document . querySelectorAll ( '.dropzone' ) ) {
2698
- const filenameDict = { } ;
2699
2693
const $dropzone = $ ( el ) ;
2700
2694
await createDropzone ( el , {
2701
2695
url : $dropzone . data ( 'upload-url' ) ,
@@ -2713,18 +2707,15 @@ $(document).ready(async () => {
2713
2707
thumbnailWidth : 480 ,
2714
2708
thumbnailHeight : 480 ,
2715
2709
init ( ) {
2716
- this . on ( 'success' , ( file , data ) => {
2717
- filenameDict [ file . name ] = data . uuid ;
2710
+ this . on ( 'success' , ( _file , data ) => {
2718
2711
const input = $ ( `<input id="${ data . uuid } " name="files" type="hidden">` ) . val ( data . uuid ) ;
2719
2712
$dropzone . find ( '.files' ) . append ( input ) ;
2720
2713
} ) ;
2721
2714
this . on ( 'removedfile' , ( file ) => {
2722
- if ( file . name in filenameDict ) {
2723
- $ ( `#${ filenameDict [ file . name ] } ` ) . remove ( ) ;
2724
- }
2715
+ $ ( `#${ file . uuid } ` ) . remove ( ) ;
2725
2716
if ( $dropzone . data ( 'remove-url' ) ) {
2726
2717
$ . post ( $dropzone . data ( 'remove-url' ) , {
2727
- file : filenameDict [ file . name ] ,
2718
+ file : file . uuid ,
2728
2719
_csrf : csrf
2729
2720
} ) ;
2730
2721
}
0 commit comments