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