@@ -1610,7 +1610,7 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
1610
1610
req . body . app_id = req . body . app_image_id ;
1611
1611
}
1612
1612
var params = paramsGenerator ( { req, res} ) ;
1613
- validateCreate ( params , 'global_upload' , function ( ) {
1613
+ validateCreate ( params , 'global_upload' , async function ( ) {
1614
1614
if ( ! req . session . uid && ! req . body . app_image_id ) {
1615
1615
res . end ( ) ;
1616
1616
return false ;
@@ -1634,25 +1634,18 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
1634
1634
}
1635
1635
plugins . callMethod ( "iconUpload" , { req : req , res : res , next : next , data : req . body } ) ;
1636
1636
try {
1637
- jimp . read ( tmp_path , function ( err , icon ) {
1638
- if ( err ) {
1639
- console . log ( err , err . stack ) ;
1640
- fs . unlink ( tmp_path , function ( ) { } ) ;
1641
- res . status ( 400 ) . send ( false ) ;
1642
- return true ;
1643
- }
1644
- icon . cover ( 72 , 72 ) . getBuffer ( jimp . MIME_PNG , function ( err2 , buffer ) {
1645
- countlyFs . saveData ( "appimages" , target_path , buffer , { id : req . body . app_image_id + ".png" , writeMode : "overwrite" } , function ( ) {
1646
- fs . unlink ( tmp_path , function ( ) { } ) ;
1647
- res . send ( "appimages/" + req . body . app_image_id + ".png" ) ;
1648
- countlyDb . collection ( 'apps' ) . updateOne ( { _id : countlyDb . ObjectID ( req . body . app_image_id ) } , { '$set' : { 'has_image' : true } } , function ( ) { } ) ;
1649
- } ) ;
1650
- } ) ; // save
1637
+ const icon = await jimp . Jimp . read ( tmp_path ) ;
1638
+ const buffer = await icon . cover ( { h : 72 , w : 72 } ) . getBuffer ( jimp . JimpMime . png ) ;
1639
+ countlyFs . saveData ( "appimages" , target_path , buffer , { id : req . body . app_image_id + ".png" , writeMode : "overwrite" } , function ( ) {
1640
+ res . send ( "appimages/" + req . body . app_image_id + ".png" ) ;
1641
+ countlyDb . collection ( 'apps' ) . updateOne ( { _id : countlyDb . ObjectID ( req . body . app_image_id ) } , { '$set' : { 'has_image' : true } } , function ( ) { } ) ;
1651
1642
} ) ;
1652
1643
}
1653
1644
catch ( e ) {
1654
- console . log ( e . stack ) ;
1645
+ console . log ( "Problem uploading app icon" , e ) ;
1646
+ res . status ( 400 ) . send ( false ) ;
1655
1647
}
1648
+ fs . unlink ( tmp_path , function ( ) { } ) ;
1656
1649
} ) ;
1657
1650
} ) ;
1658
1651
@@ -1694,23 +1687,19 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
1694
1687
}
1695
1688
plugins . callMethod ( "iconUpload" , { req : req , res : res , next : next , data : req . body } ) ;
1696
1689
try {
1697
- jimp . read ( tmp_path , function ( err , icon ) {
1698
- if ( err ) {
1699
- console . log ( err , err . stack ) ;
1700
- }
1701
- icon . cover ( 72 , 72 ) . getBuffer ( jimp . MIME_PNG , function ( err2 , buffer ) {
1702
- countlyFs . saveData ( "memberimages" , target_path , buffer , { id : req . body . member_image_id + ".png" , writeMode : "overwrite" } , function ( ) {
1703
- fs . unlink ( tmp_path , function ( ) { } ) ;
1704
- countlyDb . collection ( 'members' ) . updateOne ( { _id : countlyDb . ObjectID ( req . body . member_image_id + "" ) } , { '$set' : { 'member_image' : "memberimages/" + req . body . member_image_id + ".png" } } , function ( ) {
1705
- res . send ( "memberimages/" + req . body . member_image_id + ".png" ) ;
1706
- } ) ;
1707
- } ) ;
1708
- } ) ; // save
1690
+ const icon = await jimp . Jimp . read ( tmp_path ) ;
1691
+ const buffer = await icon . cover ( { h : 72 , w : 72 } ) . getBuffer ( jimp . JimpMime . png ) ;
1692
+ countlyFs . saveData ( "memberimages" , target_path , buffer , { id : req . body . member_image_id + ".png" , writeMode : "overwrite" } , function ( ) {
1693
+ countlyDb . collection ( 'members' ) . updateOne ( { _id : countlyDb . ObjectID ( req . body . member_image_id + "" ) } , { '$set' : { 'member_image' : "memberimages/" + req . body . member_image_id + ".png" } } , function ( ) {
1694
+ res . send ( "memberimages/" + req . body . member_image_id + ".png" ) ;
1695
+ } ) ;
1709
1696
} ) ;
1710
1697
}
1711
1698
catch ( e ) {
1712
- console . log ( e . stack ) ;
1699
+ console . log ( "Problem uploading member icon" , e ) ;
1700
+ res . status ( 400 ) . send ( false ) ;
1713
1701
}
1702
+ fs . unlink ( tmp_path , function ( ) { } ) ;
1714
1703
} ) ;
1715
1704
} ) ;
1716
1705
0 commit comments