[scraper] cleans up repository methods

This commit is contained in:
TheBeastLT
2020-04-25 14:13:19 +02:00
parent 5e72683ce4
commit 0be7dc4638

View File

@@ -77,11 +77,6 @@ const SkipTorrent = database.define('skip_torrent', {
infoHash: { type: Sequelize.STRING(64), primaryKey: true }, infoHash: { type: Sequelize.STRING(64), primaryKey: true },
}); });
const FailedImdbTorrent = database.define('failed_imdb_torrent', {
infoHash: { type: Sequelize.STRING(64), primaryKey: true },
title: { type: Sequelize.STRING(256), allowNull: false }
});
function connect() { function connect() {
if (process.env.ENABLE_SYNC) { if (process.env.ENABLE_SYNC) {
return database.sync({ alter: true }) return database.sync({ alter: true })
@@ -99,10 +94,6 @@ function getProvider(provider) {
.catch(() => provider); .catch(() => provider);
} }
function updateProvider(provider) {
return Provider.update(provider, { where: { name: { [Op.eq]: provider.name } } });
}
function getTorrent(torrent) { function getTorrent(torrent) {
return Torrent.findByPk(torrent.infoHash) return Torrent.findByPk(torrent.infoHash)
.then((result) => { .then((result) => {
@@ -135,10 +126,6 @@ function getUpdateSeedersTorrents() {
}); });
} }
function getTorrentsUpdatedBetween(provider, startDate, endDate) {
return Torrent.findAll({ where: { provider: provider, updatedAt: { [Op.gte]: startDate, [Op.lte]: endDate } } });
}
function createTorrent(torrent) { function createTorrent(torrent) {
return Torrent.upsert(torrent); return Torrent.upsert(torrent);
} }
@@ -163,7 +150,7 @@ function getSkipTorrent(torrent) {
return SkipTorrent.findByPk(torrent.infoHash) return SkipTorrent.findByPk(torrent.infoHash)
.then((result) => { .then((result) => {
if (!result) { if (!result) {
return getFailedImdbTorrent(torrent); throw new Error(`torrent not found: ${torrent.infoHash}`);
} }
return result.dataValues; return result.dataValues;
}) })
@@ -173,24 +160,9 @@ function createSkipTorrent(torrent) {
return SkipTorrent.upsert({ infoHash: torrent.infoHash }); return SkipTorrent.upsert({ infoHash: torrent.infoHash });
} }
function getFailedImdbTorrent(torrent) {
return FailedImdbTorrent.findByPk(torrent.infoHash)
.then((result) => {
if (!result) {
throw new Error(`torrent not found: ${torrent.infoHash}`);
}
return result.dataValues;
})
}
function createFailedImdbTorrent(torrent) {
return FailedImdbTorrent.upsert(torrent);
}
module.exports = { module.exports = {
connect, connect,
getProvider, getProvider,
updateProvider,
createTorrent, createTorrent,
getTorrent, getTorrent,
getTorrentsBasedOnTitle, getTorrentsBasedOnTitle,
@@ -201,7 +173,5 @@ module.exports = {
deleteFile, deleteFile,
getSkipTorrent, getSkipTorrent,
createSkipTorrent, createSkipTorrent,
createFailedImdbTorrent, getTorrentsWithoutSize
getTorrentsWithoutSize,
getTorrentsUpdatedBetween
}; };