Backend: Added auto entry refrech each 24h
This commit is contained in:
1 parent
17067a5516
commit
367c9899a0
2 files changed
+39
-1
No files matched your search
@@ -27,7 +27,7 @@ class EntryController {
|
|||||||
async getEntryById(req, res) {
|
async getEntryById(req, res) {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
|
||||||
let entry = await _entryService.getEntryById(id, true);
|
let entry = await _entryManager.getUpdatedEntry(id);
|
||||||
|
|
||||||
res.status(200).json(entry);
|
res.status(200).json(entry);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,6 +366,44 @@ class EntryManager {
|
|||||||
return refreshedEntry;
|
return refreshedEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an entry by its ID and refreshes it if needed.
|
||||||
|
*
|
||||||
|
* An entry is refreshed if:
|
||||||
|
* - It has never been fetched before (`last_fetch` is null or undefined), or
|
||||||
|
* - The last fetch was more than 24 hours ago.
|
||||||
|
*
|
||||||
|
* If a refresh is required, it logs the operation and calls `refrechEntryById`.
|
||||||
|
*
|
||||||
|
* @async
|
||||||
|
* @function getUpdatedEntry
|
||||||
|
* @param {number} id - The ID of the entry to retrieve.
|
||||||
|
* @returns {Promise<Object>} The entry object, either current or refreshed.
|
||||||
|
*/
|
||||||
|
async getUpdatedEntry(id) {
|
||||||
|
let entry = await _entryService.getEntryById(id, false);
|
||||||
|
|
||||||
|
let doRefrech = false;
|
||||||
|
if (!entry.last_fetch) {
|
||||||
|
doRefrech = true;
|
||||||
|
} else {
|
||||||
|
// check if the last fetch was more than 24 hours ago
|
||||||
|
const lastFetchDate = new Date(entry.last_fetch);
|
||||||
|
const currentDate = new Date();
|
||||||
|
const diffInHours = (currentDate - lastFetchDate) / (1000 * 60 * 60);
|
||||||
|
if (diffInHours > 24 && !(entry.is_tvseries && entry.status === 'Ended')) {
|
||||||
|
doRefrech = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doRefrech) {
|
||||||
|
logToFile(`Refrech Entry: ${entry.id} - ${entry.title}`);
|
||||||
|
entry = await this.refrechEntryById(id, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
/** This function will refresh data of series that have the status not 'ended/canceled' and have not been refreshed today
|
/** This function will refresh data of series that have the status not 'ended/canceled' and have not been refreshed today
|
||||||
*/
|
*/
|
||||||
async SyncSeriesData() {
|
async SyncSeriesData() {
|
||||||
|
|||||||
Reference in new issue
Block a user