include top seeded entries only for non foreign provider by default

This commit is contained in:
TheBeastLT
2023-01-11 17:55:18 +02:00
parent 683776ab6d
commit 543bde2ca8
3 changed files with 24 additions and 14 deletions

View File

@@ -5,7 +5,7 @@ const DATABASE_URI = process.env.DATABASE_URI;
const database = new Sequelize(DATABASE_URI, { logging: false });
async function getIds(type, startDate, endDate) {
async function getIds(providers, type, startDate, endDate) {
const idName = type === Type.ANIME ? 'kitsuId' : 'imdbId';
const episodeCondition = type === Type.SERIES
? 'AND files."imdbSeason" IS NOT NULL AND files."imdbEpisode" IS NOT NULL'
@@ -13,9 +13,12 @@ async function getIds(type, startDate, endDate) {
const dateCondition = startDate && endDate
? `AND "uploadDate" BETWEEN '${startDate}' AND '${endDate}'`
: ''
const providersCondition = providers && providers.length
? `AND provider in (${providers.map(it => `'${it}'`).join(',')})`
: ''
const query = `SELECT files."${idName}"
FROM (SELECT torrents."infoHash", torrents.seeders FROM torrents
WHERE seeders > 0 AND type = '${type}' ${dateCondition}
WHERE seeders > 0 AND type = '${type}' ${providersCondition} ${dateCondition}
) as torrents
JOIN files ON torrents."infoHash" = files."infoHash"
WHERE files."${idName}" IS NOT NULL ${episodeCondition}