Eslint errors

This commit is contained in:
Daniel García Aubert 2019-12-26 18:01:38 +01:00
parent 014158c968
commit fddc76b542
5 changed files with 26 additions and 28 deletions

View File

@ -1,12 +1,13 @@
'use strict';
var fs = require('fs');
const path = require('path');
var formats = {};
function formatFilesWithPath (dir) {
var formatDir = __dirname + '/' + dir;
var formatDir = path.join(__dirname, dir);
return fs.readdirSync(formatDir).map(function (formatFile) {
return formatDir + '/' + formatFile;
return path.join(formatDir, formatFile);
});
}

View File

@ -25,7 +25,7 @@ OgrFormat.prototype = {
},
transform: function (/* result, options, callback */) {
throw 'should not be called for file formats';
throw new Error('should not be called for file formats');
},
getContentType: function () { return this._contentType; },
@ -50,11 +50,11 @@ OgrFormat.prototype = {
};
// Internal function usable by all OGR-driven outputs
OgrFormat.prototype.toOGR = function (options, out_format, out_filename, callback) {
OgrFormat.prototype.toOGR = function (options, outFormat, outFilename, callback) {
// var gcol = options.gn;
var sql = options.sql;
var skipfields = options.skipfields;
var out_layername = options.filename;
var outLayername = options.filename;
var dbopts = options.dbopts;
@ -113,7 +113,7 @@ OgrFormat.prototype.toOGR = function (options, out_format, out_filename, callbac
return field;
})
// apply quotes to columns
.map(field => out_format === 'CSV' ? pg.quoteIdentifier(field.name) + '::text' : pg.quoteIdentifier(field.name));
.map(field => outFormat === 'CSV' ? pg.quoteIdentifier(field.name) + '::text' : pg.quoteIdentifier(field.name));
if (!needSRS || !geocol) {
return null;
@ -148,11 +148,11 @@ OgrFormat.prototype.toOGR = function (options, out_format, out_filename, callbac
var ogrsql = 'SELECT ' + columns.join(',') + ' FROM (' + sql + ') as _cartodbsqlapi';
var ogrargs = [
'-f', out_format,
'-f', outFormat,
'-lco', 'RESIZE=YES',
'-lco', 'ENCODING=UTF-8',
'-lco', 'LINEFORMAT=CRLF',
out_filename,
outFilename,
'PG:host=' + dbhost + ' port=' + dbport + ' user=' + dbuser + ' dbname=' + dbname + ' password=' + dbpass,
'-sql', ogrsql
];
@ -169,7 +169,7 @@ OgrFormat.prototype.toOGR = function (options, out_format, out_filename, callbac
ogrargs = ogrargs.concat(options.cmd_params);
}
ogrargs.push('-nln', out_layername);
ogrargs.push('-nln', outLayername);
// TODO: research if `exec` could fit better than `spawn`
var child = spawn(ogr2ogr, ogrargs);
@ -214,14 +214,14 @@ OgrFormat.prototype.toOGR = function (options, out_format, out_filename, callbac
});
},
function finish (err) {
callback(err, out_filename);
callback(err, outFilename);
}
);
};
OgrFormat.prototype.toOGR_SingleFile = function (options, fmt, callback) {
var dbname = options.dbopts.dbname;
var user_id = options.dbopts.user;
var userId = options.dbopts.user;
var gcol = options.gcol;
var sql = options.sql;
var skipfields = options.skipfields;
@ -232,7 +232,7 @@ OgrFormat.prototype.toOGR_SingleFile = function (options, fmt, callback) {
var reqKey = [
fmt,
dbname,
user_id,
userId,
gcol,
this.generateMD5(layername),
this.generateMD5(sql)
@ -293,8 +293,6 @@ OgrFormat.prototype.sendResponse = function (opts, callback) {
}
};
// TODO: put in an ExportRequest.js ----- {
function ExportRequest (ostream, callback, beforeSink) {
this.cb = callback;
this.beforeSink = beforeSink;
@ -305,7 +303,6 @@ function ExportRequest (ostream, callback, beforeSink) {
var that = this;
this.ostream.on('close', function () {
// console.log("Request close event, qElem.stream is " + qElem.stream);
that.canceled = true;
if (that.istream) {
that.istream.destroy();
@ -314,9 +311,12 @@ function ExportRequest (ostream, callback, beforeSink) {
}
ExportRequest.prototype.sendFile = function (err, filename, callback) {
if (err) {
return callback(err);
}
var that = this;
if (!this.canceled) {
// console.log("Creating readable stream out of dumpfile");
this.istream = fs.createReadStream(filename)
.on('open', function (/* fd */) {
if (that.beforeSink) {
@ -331,12 +331,9 @@ ExportRequest.prototype.sendFile = function (err, filename, callback) {
callback();
});
} else {
// console.log("Response was canceled, not streaming the file");
callback();
}
this.cb();
};
// ------ }
module.exports = OgrFormat;

View File

@ -27,7 +27,7 @@ ShpFormat.prototype.generate = function (options, callback) {
ShpFormat.prototype.toSHP = function (options, callback) {
var dbname = options.database;
var user_id = options.user_id;
var userId = options.user_id;
var gcol = options.gn;
var sql = options.sql;
var skipfields = options.skipfields;
@ -37,7 +37,7 @@ ShpFormat.prototype.toSHP = function (options, callback) {
var zip = global.settings.zipCommand || 'zip';
var zipOptions = '-qrj';
var tmpdir = global.settings.tmpDir || '/tmp';
var reqKey = ['shp', dbname, user_id, gcol, this.generateMD5(sql)].concat(skipfields).join(':');
var reqKey = ['shp', dbname, userId, gcol, this.generateMD5(sql)].concat(skipfields).join(':');
var outdirpath = tmpdir + '/sqlapi-' + process.pid + '-' + reqKey;
var zipfile = outdirpath + '.zip';
var shapefile = outdirpath + '/' + filename + '.shp';

View File

@ -20,12 +20,12 @@ BinaryFormat.prototype._extractTypeFromName = function (name) {
};
BinaryFormat.prototype.transform = function (result, options, callback) {
var total_rows = result.rowCount;
var totalRows = result.rowCount;
var rows = result.rows;
// get headers
if (!total_rows) {
callback(null, new Buffer(0));
if (!totalRows) {
callback(null, Buffer.alloc(0));
return;
}
@ -64,7 +64,7 @@ BinaryFormat.prototype.transform = function (result, options, callback) {
for (i = 0; i < headersNames.length; ++i) {
var d = [];
n = headersNames[i];
for (r = 0; r < total_rows; ++r) {
for (r = 0; r < totalRows; ++r) {
var row = rows[r][n];
if (headerTypes[i] > ArrayBufferSer.BUFFER) {
row = new ArrayBufferSer(headerTypes[i] - ArrayBufferSer.BUFFER, row);

View File

@ -71,7 +71,7 @@ JsonFormat.prototype.handleQueryRow = function (row, result) {
this.lastKnownResult = result;
this.buffer += (this.total_rows++ ? ',' : '') + JSON.stringify(row, function (key, value) {
if (value !== value) {
if (value !== value) { // eslint-disable-line no-self-compare
return 'NaN';
}
@ -123,11 +123,11 @@ JsonFormat.prototype.handleQueryEnd = function (result) {
result.fields = newfields;
}
var total_time = (Date.now() - this.start_time) / 1000;
var totalTime = (Date.now() - this.start_time) / 1000;
var out = [
'],', // end of "rows" array
'"time":', JSON.stringify(total_time),
'"time":', JSON.stringify(totalTime),
',"fields":', JSON.stringify(this.formatResultFields(result.fields)),
',"total_rows":', JSON.stringify(result.rowCount || this.total_rows)
];