@@ -1030,7 +1030,7 @@ async function initRepository() {
10301030 if ( $dropzone . length === 1 ) {
10311031 $dropzone . data ( 'saved' , false ) ;
10321032
1033- const filenameDict = { } ;
1033+ const fileUuidDict = { } ;
10341034 dz = await createDropzone ( $dropzone [ 0 ] , {
10351035 url : $dropzone . data ( 'upload-url' ) ,
10361036 headers : { 'X-Csrf-Token' : csrf } ,
@@ -1048,28 +1048,24 @@ async function initRepository() {
10481048 thumbnailHeight : 480 ,
10491049 init ( ) {
10501050 this . on ( 'success' , ( file , data ) => {
1051- filenameDict [ file . name ] = {
1052- uuid : data . uuid ,
1051+ fileUuidDict [ file . uuid ] = {
10531052 submitted : false
10541053 } ;
10551054 const input = $ ( `<input id="${ data . uuid } " name="files" type="hidden">` ) . val ( data . uuid ) ;
10561055 $dropzone . find ( '.files' ) . append ( input ) ;
10571056 } ) ;
10581057 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 ) {
10641060 $ . post ( $dropzone . data ( 'remove-url' ) , {
1065- file : filenameDict [ file . name ] . uuid ,
1061+ file : file . uuid ,
10661062 _csrf : csrf ,
10671063 } ) ;
10681064 }
10691065 } ) ;
10701066 this . on ( 'submit' , ( ) => {
1071- $ . each ( filenameDict , ( name ) => {
1072- filenameDict [ name ] . submitted = true ;
1067+ $ . each ( fileUuidDict , ( fileUuid ) => {
1068+ fileUuidDict [ fileUuid ] . submitted = true ;
10731069 } ) ;
10741070 } ) ;
10751071 this . on ( 'reload' , ( ) => {
@@ -1082,9 +1078,8 @@ async function initRepository() {
10821078 dz . emit ( 'thumbnail' , this , imgSrc ) ;
10831079 dz . emit ( 'complete' , this ) ;
10841080 dz . files . push ( this ) ;
1085- filenameDict [ this . name ] = {
1081+ fileUuidDict [ this . uuid ] = {
10861082 submitted : true ,
1087- uuid : this . uuid
10881083 } ;
10891084 $dropzone . find ( `img[src='${ imgSrc } ']` ) . css ( 'max-width' , '100%' ) ;
10901085 const input = $ ( `<input id="${ this . uuid } " name="files" type="hidden">` ) . val ( this . uuid ) ;
@@ -2695,7 +2690,6 @@ $(document).ready(async () => {
26952690
26962691 // Dropzone
26972692 for ( const el of document . querySelectorAll ( '.dropzone' ) ) {
2698- const filenameDict = { } ;
26992693 const $dropzone = $ ( el ) ;
27002694 await createDropzone ( el , {
27012695 url : $dropzone . data ( 'upload-url' ) ,
@@ -2713,18 +2707,15 @@ $(document).ready(async () => {
27132707 thumbnailWidth : 480 ,
27142708 thumbnailHeight : 480 ,
27152709 init ( ) {
2716- this . on ( 'success' , ( file , data ) => {
2717- filenameDict [ file . name ] = data . uuid ;
2710+ this . on ( 'success' , ( _file , data ) => {
27182711 const input = $ ( `<input id="${ data . uuid } " name="files" type="hidden">` ) . val ( data . uuid ) ;
27192712 $dropzone . find ( '.files' ) . append ( input ) ;
27202713 } ) ;
27212714 this . on ( 'removedfile' , ( file ) => {
2722- if ( file . name in filenameDict ) {
2723- $ ( `#${ filenameDict [ file . name ] } ` ) . remove ( ) ;
2724- }
2715+ $ ( `#${ file . uuid } ` ) . remove ( ) ;
27252716 if ( $dropzone . data ( 'remove-url' ) ) {
27262717 $ . post ( $dropzone . data ( 'remove-url' ) , {
2727- file : filenameDict [ file . name ] ,
2718+ file : file . uuid ,
27282719 _csrf : csrf
27292720 } ) ;
27302721 }
0 commit comments