mirror of https://gitee.com/bigwinds/arangodb
document export bugfix, added filters to doc export function
This commit is contained in:
parent
0f215c7f71
commit
7c035ad49a
|
@ -398,9 +398,81 @@ controller.get("/query/download/:user", function(req, res) {
|
|||
*/
|
||||
|
||||
controller.get("/query/result/download/:query", function(req, res) {
|
||||
var query = req.params("query");
|
||||
var query = req.params("query"),
|
||||
parsedQuery;
|
||||
|
||||
var result = db._query(query).toArray();
|
||||
var _utf8_decode = function (utftext) {
|
||||
var string = "";
|
||||
var i = 0;
|
||||
var c = c1 = c2 = 0;
|
||||
|
||||
while ( i < utftext.length ) {
|
||||
c = utftext.charCodeAt(i);
|
||||
|
||||
if (c < 128) {
|
||||
string += String.fromCharCode(c);
|
||||
i++;
|
||||
}
|
||||
else if((c > 191) && (c < 224)) {
|
||||
c2 = utftext.charCodeAt(i+1);
|
||||
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
||||
i += 2;
|
||||
}
|
||||
else {
|
||||
c2 = utftext.charCodeAt(i+1);
|
||||
c3 = utftext.charCodeAt(i+2);
|
||||
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
||||
i += 3;
|
||||
}
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
var decodeFunction = function (input) {
|
||||
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
var output = "";
|
||||
var chr1, chr2, chr3;
|
||||
var enc1, enc2, enc3, enc4;
|
||||
var i = 0;
|
||||
|
||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||
|
||||
while (i < input.length) {
|
||||
enc1 = keyStr.indexOf(input.charAt(i++));
|
||||
enc2 = keyStr.indexOf(input.charAt(i++));
|
||||
enc3 = keyStr.indexOf(input.charAt(i++));
|
||||
enc4 = keyStr.indexOf(input.charAt(i++));
|
||||
|
||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||
chr3 = ((enc3 & 3) << 6) | enc4;
|
||||
|
||||
output = output + String.fromCharCode(chr1);
|
||||
|
||||
if (enc3 != 64) {
|
||||
output = output + String.fromCharCode(chr2);
|
||||
}
|
||||
if (enc4 != 64) {
|
||||
output = output + String.fromCharCode(chr3);
|
||||
}
|
||||
}
|
||||
|
||||
output = _utf8_decode(output);
|
||||
|
||||
return output;
|
||||
|
||||
};
|
||||
|
||||
query = decodeFunction(query);
|
||||
|
||||
try {
|
||||
parsedQuery = JSON.parse(query);
|
||||
}
|
||||
catch (ignore) {
|
||||
}
|
||||
|
||||
var result = db._query(parsedQuery.query, parsedQuery.bindVars).toArray();
|
||||
res.set("Content-Type", "application/json");
|
||||
res.set("Content-Disposition", "attachment; filename=results.json");
|
||||
res.json(result);
|
||||
|
|
|
@ -236,7 +236,7 @@
|
|||
"@collection": this.collectionID
|
||||
};
|
||||
|
||||
query = "FOR x in " + this.collectionID;
|
||||
query = "FOR x in @@collection";
|
||||
query += this.setFiltersForQuery(bindVars);
|
||||
// Sort result, only useful for a small number of docs
|
||||
if (this.getTotal() < this.MAX_SORT) {
|
||||
|
@ -250,7 +250,7 @@
|
|||
bindVars: bindVars
|
||||
};
|
||||
|
||||
return query;
|
||||
return queryObj;
|
||||
},
|
||||
|
||||
updloadDocuments : function (file) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*jslint indent: 2, nomen: true, maxlen: 100, vars: true, white: true, plusplus: true */
|
||||
/*global require, arangoHelper, _, $, window, arangoHelper, templateEngine, Joi*/
|
||||
/*global require, arangoHelper, _, $, window, arangoHelper, templateEngine, Joi, btoa */
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
|
@ -172,7 +172,7 @@
|
|||
var query = this.collection.buildDownloadDocumentQuery();
|
||||
|
||||
if (query !== '' || query !== undefined || query !== null) {
|
||||
window.open(encodeURI("query/result/download/" + query));
|
||||
window.open(encodeURI("query/result/download/" + btoa(JSON.stringify(query))));
|
||||
}
|
||||
else {
|
||||
arangoHelper.arangoError("Document error", "could not download documents");
|
||||
|
|
Loading…
Reference in New Issue