@@ -2285,35 +2285,33 @@ <h2>' + (nodeResolveString(node.label||'', node.metrics) || node._id) + ' ' + re
22852285 $ ( "#changeNodeIcon_OK" ) . click ( "tap" , function ( event ) {
22862286 if ( $ ( "#nodeIconUpload" ) . val ( ) ) {
22872287 event . preventDefault ( ) ;
2288- var file_data = $ ( '#nodeIconUpload' ) . prop ( 'files' ) [ 0 ] ;
2289- var form_data = new FormData ( ) ;
2290- form_data . append ( 'file' , file_data ) ;
2291- $ . ajax ( {
2292- type : "POST" ,
2293- url : "upload.php" ,
2294- enctype : 'multipart/form-data' ,
2295- dataType : 'json' ,
2296- cache : false ,
2297- contentType : false ,
2298- processData : false ,
2299- data : form_data ,
2300- success : function ( data , textStatus , jqXHR ) {
2301- data [ 'status' ] ;
2302- if ( data [ 'status' ] == 'success' )
2288+
2289+ var file = $ ( '#nodeIconUpload' ) . prop ( 'files' ) [ 0 ] ;
2290+
2291+ var types = [ 'image/jpeg' , 'image/png' , 'image/gif' ] ;
2292+ if ( ! types . includes ( file . type ) ) {
2293+ alert ( 'Invalid file type; only JPG/JPEG/PNG/GIF are allowed' ) ;
2294+ return ;
2295+ }
2296+
2297+ if ( ( file . size || 0 ) > 500000 ) {
2298+ alert ( 'File too large (>500K)' ) ;
2299+ return ;
2300+ }
2301+
2302+ socket . emit ( 'UPLOADIMAGE' , file . name , file , function ( filePath , err ) {
2303+ if ( err ) {
2304+ alert ( 'Upload failed: ' + err . message ) ;
2305+ }
2306+ else {
2307+ if ( filePath )
23032308 {
2304- if ( data [ 'filePath' ] )
2305- {
2306- $ ( '#nodeDetailImage' ) . attr ( 'src' , 'images/' + data [ 'filePath' ] ) ;
2307- nodes [ selectedNodeId ] . icon = data [ 'filePath' ] ;
2308- socket . emit ( 'REFRESHICONS' ) ;
2309- $ . mobile . navigate ( '#nodedetails' ) ;
2310- }
2311- else alert ( 'Expected filePath back, got nothing' ) ;
2309+ $ ( '#nodeDetailImage' ) . attr ( 'src' , 'images/' + filePath ) ;
2310+ nodes [ selectedNodeId ] . icon = filePath ;
2311+ socket . emit ( 'REFRESHICONS' ) ;
2312+ $ . mobile . navigate ( '#nodedetails' ) ;
23122313 }
2313- else alert ( data [ 'message' ] || 'Upload failed' ) ;
2314- } ,
2315- error : function ( data , textStatus , msg ) {
2316- alert ( msg || 'Upload failed' ) ;
2314+ else alert ( 'Expected filePath back, got nothing' ) ;
23172315 }
23182316 } ) ;
23192317 }
0 commit comments