Fix limit when fetching entries, allow moment timestamps

This commit is contained in:
Bryan Ashby 2018-01-11 21:17:26 -07:00
parent 4e4ee6b8ce
commit fa1bffeaf8
1 changed files with 14 additions and 7 deletions

View File

@ -13,6 +13,7 @@ const paths = require('path');
const fse = require('fs-extra');
const { unlink, readFile } = require('graceful-fs');
const crypto = require('crypto');
const moment = require('moment');
const FILE_TABLE_MEMBERS = [
'file_id', 'area_tag', 'file_sha256', 'file_name', 'storage_tag',
@ -425,6 +426,10 @@ module.exports = class FileEntry {
let sqlOrderBy;
const sqlOrderDir = 'ascending' === filter.order ? 'ASC' : 'DESC';
if(moment.isMoment(filter.newerThanTimestamp)) {
filter.newerThanTimestamp = getISOTimestampString(filter.newerThanTimestamp);
}
function getOrderByWithCast(ob) {
if( [ 'dl_count', 'est_release_year', 'byte_size' ].indexOf(filter.sort) > -1 ) {
return `ORDER BY CAST(${ob} AS INTEGER)`;
@ -552,12 +557,14 @@ module.exports = class FileEntry {
appendWhereClause(`f.file_id > ${filter.newerThanFileId}`);
}
sql += `${sqlWhere} ${sqlOrderBy};`;
sql += `${sqlWhere} ${sqlOrderBy}`;
if(_.isNumber(filter.limit)) {
sql += `LIMIT ${filter.limit}`;
sql += ` LIMIT ${filter.limit}`;
}
sql += ';';
const matchingFileIds = [];
fileDb.each(sql, (err, fileId) => {
if(fileId) {