@@ -1620,12 +1620,14 @@ const processRequest = (params) => {
1620
1620
else {
1621
1621
params . qstring . query . $and . push ( { "$or" : [ { "global" : { "$ne" : false } } , { "creator" : params . member . _id + "" } ] } ) ;
1622
1622
}
1623
- if ( params . qstring . app_id && params . qstring . app_id !== "" ) {
1624
- params . qstring . query . $and . push ( { "app_id" : params . qstring . app_id } ) ;
1625
- }
1626
- else if ( params . qstring . app_independent === true ) {
1627
- console . log ( params . qstring . app_independent ) ;
1628
- params . qstring . query . $and . push ( { "app_id" : "undefined" } ) ;
1623
+
1624
+ if ( params . qstring . data_source !== "all" && params . qstring . app_id ) {
1625
+ if ( params . qstring . data_source === "independent" ) {
1626
+ params . qstring . query . $and . push ( { "app_id" : "undefined" } ) ;
1627
+ }
1628
+ else {
1629
+ params . qstring . query . $and . push ( { "app_id" : params . qstring . app_id } ) ;
1630
+ }
1629
1631
}
1630
1632
1631
1633
if ( params . qstring . query . $or ) {
@@ -1938,6 +1940,7 @@ const processRequest = (params) => {
1938
1940
var type = filename . split ( "." ) ;
1939
1941
type = type [ type . length - 1 ] ;
1940
1942
var myfile = paths [ 4 ] ;
1943
+ var headers = { } ;
1941
1944
1942
1945
countlyFs . gridfs . getSize ( "task_results" , myfile , { id : paths [ 4 ] } , function ( err2 , size ) {
1943
1946
if ( err2 ) {
@@ -1947,30 +1950,16 @@ const processRequest = (params) => {
1947
1950
if ( data . type !== "dbviewer" ) {
1948
1951
common . returnMessage ( params , 400 , "Export size is 0" ) ;
1949
1952
}
1950
- //handling older aggregations aren't saved in countly_fs
1953
+ //handling older aggregations that aren't saved in countly_fs
1951
1954
else if ( ! data . gridfs && data . data ) {
1952
- console . log ( "here" ) ;
1953
1955
type = "json" ;
1954
1956
filename = data . name + "." + type ;
1955
- countlyFs . gridfs . saveData ( "task_results" , myfile , data . data , { id : myfile } , function ( err3 ) {
1956
- if ( err3 ) {
1957
- console . log ( err3 ) ;
1958
- }
1959
- else {
1960
- countlyFs . gridfs . getStream ( "task_results" , myfile , { id : myfile } , function ( err4 , stream ) {
1961
- if ( err4 ) {
1962
- common . returnMessage ( params , 400 , "Export stream does not exist" ) ;
1963
- }
1964
- else {
1965
- var headers = { } ;
1966
- headers [ "Content-Type" ] = countlyApi . data . exports . getType ( type ) ;
1967
- headers [ "Content-Disposition" ] = "attachment;filename=" + encodeURIComponent ( filename ) ;
1968
- params . res . writeHead ( 200 , headers ) ;
1969
- stream . pipe ( params . res ) ;
1970
- }
1971
- } ) ;
1972
- }
1973
- } ) ;
1957
+ headers = { } ;
1958
+ headers [ "Content-Type" ] = countlyApi . data . exports . getType ( type ) ;
1959
+ headers [ "Content-Disposition" ] = "attachment;filename=" + encodeURIComponent ( filename ) ;
1960
+ params . res . writeHead ( 200 , headers ) ;
1961
+ params . res . write ( data . data ) ;
1962
+ params . res . end ( ) ;
1974
1963
}
1975
1964
}
1976
1965
else {
@@ -1979,7 +1968,7 @@ const processRequest = (params) => {
1979
1968
common . returnMessage ( params , 400 , "Export stream does not exist" ) ;
1980
1969
}
1981
1970
else {
1982
- var headers = { } ;
1971
+ headers = { } ;
1983
1972
headers [ "Content-Type" ] = countlyApi . data . exports . getType ( type ) ;
1984
1973
headers [ "Content-Disposition" ] = "attachment;filename=" + encodeURIComponent ( filename ) ;
1985
1974
params . res . writeHead ( 200 , headers ) ;
0 commit comments