mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-13 16:14:39 +02:00
Fix limit when fetching entries, allow moment timestamps
This commit is contained in:
parent
4e4ee6b8ce
commit
fa1bffeaf8
1 changed files with 14 additions and 7 deletions
|
@ -13,6 +13,7 @@ const paths = require('path');
|
||||||
const fse = require('fs-extra');
|
const fse = require('fs-extra');
|
||||||
const { unlink, readFile } = require('graceful-fs');
|
const { unlink, readFile } = require('graceful-fs');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
const FILE_TABLE_MEMBERS = [
|
const FILE_TABLE_MEMBERS = [
|
||||||
'file_id', 'area_tag', 'file_sha256', 'file_name', 'storage_tag',
|
'file_id', 'area_tag', 'file_sha256', 'file_name', 'storage_tag',
|
||||||
|
@ -425,6 +426,10 @@ module.exports = class FileEntry {
|
||||||
let sqlOrderBy;
|
let sqlOrderBy;
|
||||||
const sqlOrderDir = 'ascending' === filter.order ? 'ASC' : 'DESC';
|
const sqlOrderDir = 'ascending' === filter.order ? 'ASC' : 'DESC';
|
||||||
|
|
||||||
|
if(moment.isMoment(filter.newerThanTimestamp)) {
|
||||||
|
filter.newerThanTimestamp = getISOTimestampString(filter.newerThanTimestamp);
|
||||||
|
}
|
||||||
|
|
||||||
function getOrderByWithCast(ob) {
|
function getOrderByWithCast(ob) {
|
||||||
if( [ 'dl_count', 'est_release_year', 'byte_size' ].indexOf(filter.sort) > -1 ) {
|
if( [ 'dl_count', 'est_release_year', 'byte_size' ].indexOf(filter.sort) > -1 ) {
|
||||||
return `ORDER BY CAST(${ob} AS INTEGER)`;
|
return `ORDER BY CAST(${ob} AS INTEGER)`;
|
||||||
|
@ -552,12 +557,14 @@ module.exports = class FileEntry {
|
||||||
appendWhereClause(`f.file_id > ${filter.newerThanFileId}`);
|
appendWhereClause(`f.file_id > ${filter.newerThanFileId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
sql += `${sqlWhere} ${sqlOrderBy};`;
|
sql += `${sqlWhere} ${sqlOrderBy}`;
|
||||||
|
|
||||||
if(_.isNumber(filter.limit)) {
|
if(_.isNumber(filter.limit)) {
|
||||||
sql += `LIMIT ${filter.limit}`;
|
sql += ` LIMIT ${filter.limit}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sql += ';';
|
||||||
|
|
||||||
const matchingFileIds = [];
|
const matchingFileIds = [];
|
||||||
fileDb.each(sql, (err, fileId) => {
|
fileDb.each(sql, (err, fileId) => {
|
||||||
if(fileId) {
|
if(fileId) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue