@@ -1606,7 +1606,7 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
16061606 req . body . app_id = req . body . app_image_id ;
16071607 }
16081608 var params = paramsGenerator ( { req, res} ) ;
1609- validateCreate ( params , 'global_upload' , function ( ) {
1609+ validateCreate ( params , 'global_upload' , async function ( ) {
16101610 if ( ! req . session . uid && ! req . body . app_image_id ) {
16111611 res . end ( ) ;
16121612 return false ;
@@ -1630,25 +1630,18 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
16301630 }
16311631 plugins . callMethod ( "iconUpload" , { req : req , res : res , next : next , data : req . body } ) ;
16321632 try {
1633- jimp . read ( tmp_path , function ( err , icon ) {
1634- if ( err ) {
1635- console . log ( err , err . stack ) ;
1636- fs . unlink ( tmp_path , function ( ) { } ) ;
1637- res . status ( 400 ) . send ( false ) ;
1638- return true ;
1639- }
1640- icon . cover ( 72 , 72 ) . getBuffer ( jimp . MIME_PNG , function ( err2 , buffer ) {
1641- countlyFs . saveData ( "appimages" , target_path , buffer , { id : req . body . app_image_id + ".png" , writeMode : "overwrite" } , function ( ) {
1642- fs . unlink ( tmp_path , function ( ) { } ) ;
1643- res . send ( "appimages/" + req . body . app_image_id + ".png" ) ;
1644- countlyDb . collection ( 'apps' ) . updateOne ( { _id : countlyDb . ObjectID ( req . body . app_image_id ) } , { '$set' : { 'has_image' : true } } , function ( ) { } ) ;
1645- } ) ;
1646- } ) ; // save
1633+ const icon = await jimp . Jimp . read ( tmp_path ) ;
1634+ const buffer = await icon . cover ( { h : 72 , w : 72 } ) . getBuffer ( jimp . JimpMime . png ) ;
1635+ countlyFs . saveData ( "appimages" , target_path , buffer , { id : req . body . app_image_id + ".png" , writeMode : "overwrite" } , function ( ) {
1636+ res . send ( "appimages/" + req . body . app_image_id + ".png" ) ;
1637+ countlyDb . collection ( 'apps' ) . updateOne ( { _id : countlyDb . ObjectID ( req . body . app_image_id ) } , { '$set' : { 'has_image' : true } } , function ( ) { } ) ;
16471638 } ) ;
16481639 }
16491640 catch ( e ) {
1650- console . log ( e . stack ) ;
1641+ console . log ( "Problem uploading app icon" , e ) ;
1642+ res . status ( 400 ) . send ( false ) ;
16511643 }
1644+ fs . unlink ( tmp_path , function ( ) { } ) ;
16521645 } ) ;
16531646 } ) ;
16541647
@@ -1690,23 +1683,19 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
16901683 }
16911684 plugins . callMethod ( "iconUpload" , { req : req , res : res , next : next , data : req . body } ) ;
16921685 try {
1693- jimp . read ( tmp_path , function ( err , icon ) {
1694- if ( err ) {
1695- console . log ( err , err . stack ) ;
1696- }
1697- icon . cover ( 72 , 72 ) . getBuffer ( jimp . MIME_PNG , function ( err2 , buffer ) {
1698- countlyFs . saveData ( "memberimages" , target_path , buffer , { id : req . body . member_image_id + ".png" , writeMode : "overwrite" } , function ( ) {
1699- fs . unlink ( tmp_path , function ( ) { } ) ;
1700- countlyDb . collection ( 'members' ) . updateOne ( { _id : countlyDb . ObjectID ( req . body . member_image_id + "" ) } , { '$set' : { 'member_image' : "memberimages/" + req . body . member_image_id + ".png" } } , function ( ) {
1701- res . send ( "memberimages/" + req . body . member_image_id + ".png" ) ;
1702- } ) ;
1703- } ) ;
1704- } ) ; // save
1686+ const icon = await jimp . Jimp . read ( tmp_path ) ;
1687+ const buffer = await icon . cover ( { h : 72 , w : 72 } ) . getBuffer ( jimp . JimpMime . png ) ;
1688+ countlyFs . saveData ( "memberimages" , target_path , buffer , { id : req . body . member_image_id + ".png" , writeMode : "overwrite" } , function ( ) {
1689+ countlyDb . collection ( 'members' ) . updateOne ( { _id : countlyDb . ObjectID ( req . body . member_image_id + "" ) } , { '$set' : { 'member_image' : "memberimages/" + req . body . member_image_id + ".png" } } , function ( ) {
1690+ res . send ( "memberimages/" + req . body . member_image_id + ".png" ) ;
1691+ } ) ;
17051692 } ) ;
17061693 }
17071694 catch ( e ) {
1708- console . log ( e . stack ) ;
1695+ console . log ( "Problem uploading member icon" , e ) ;
1696+ res . status ( 400 ) . send ( false ) ;
17091697 }
1698+ fs . unlink ( tmp_path , function ( ) { } ) ;
17101699 } ) ;
17111700 } ) ;
17121701
0 commit comments