@@ -603,10 +603,6 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
603603 app . use ( function ( req , res , next ) {
604604 var contentType = req . headers [ 'content-type' ] ;
605605 if ( req . method . toLowerCase ( ) === 'post' && contentType && contentType . indexOf ( 'multipart/form-data' ) >= 0 ) {
606- if ( ! req . session ?. uid || Date . now ( ) > req . session ?. expires ) {
607- res . status ( 401 ) . send ( 'Unauthorized' ) ;
608- return ;
609- }
610606 var form = new formidable . IncomingForm ( ) ;
611607 form . uploadDir = __dirname + '/uploads' ;
612608 form . parse ( req , function ( err , fields , files ) {
@@ -661,7 +657,7 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
661657 favicon : "images/favicon.png" ,
662658 documentationLink : convertLink ( versionInfo . documentationLink , "https://support.count.ly/hc/en-us/categories/360002373332-Knowledge-Base" ) ,
663659 helpCenterLink : convertLink ( versionInfo . helpCenterLink , "https://support.count.ly/hc/en-us" ) ,
664- featureRequestLink : convertLink ( versionInfo . featureRequestLink , "https://discord.com/channels/1088398296789299280/1088721958218248243 " ) ,
660+ featureRequestLink : convertLink ( versionInfo . featureRequestLink , "https://support.count.ly/hc/en-us/community/topics/360001464272-Feature-Requests " ) ,
665661 feedbackLink : convertLink ( versionInfo . feedbackLink , "https://count.ly/legal/privacy-policy" ) ,
666662 } ;
667663 plugins . loadConfigs ( countlyDb , function ( ) {
@@ -1610,7 +1606,7 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
16101606 req . body . app_id = req . body . app_image_id ;
16111607 }
16121608 var params = paramsGenerator ( { req, res} ) ;
1613- validateCreate ( params , 'global_upload' , function ( ) {
1609+ validateCreate ( params , 'global_upload' , async function ( ) {
16141610 if ( ! req . session . uid && ! req . body . app_image_id ) {
16151611 res . end ( ) ;
16161612 return false ;
@@ -1634,25 +1630,18 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
16341630 }
16351631 plugins . callMethod ( "iconUpload" , { req : req , res : res , next : next , data : req . body } ) ;
16361632 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
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 ( ) { } ) ;
16511638 } ) ;
16521639 }
16531640 catch ( e ) {
1654- console . log ( e . stack ) ;
1641+ console . log ( "Problem uploading app icon" , e ) ;
1642+ res . status ( 400 ) . send ( false ) ;
16551643 }
1644+ fs . unlink ( tmp_path , function ( ) { } ) ;
16561645 } ) ;
16571646 } ) ;
16581647
@@ -1694,23 +1683,19 @@ Promise.all([plugins.dbConnection(countlyConfig), plugins.dbConnection("countly_
16941683 }
16951684 plugins . callMethod ( "iconUpload" , { req : req , res : res , next : next , data : req . body } ) ;
16961685 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
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+ } ) ;
17091692 } ) ;
17101693 }
17111694 catch ( e ) {
1712- console . log ( e . stack ) ;
1695+ console . log ( "Problem uploading member icon" , e ) ;
1696+ res . status ( 400 ) . send ( false ) ;
17131697 }
1698+ fs . unlink ( tmp_path , function ( ) { } ) ;
17141699 } ) ;
17151700 } ) ;
17161701
0 commit comments