Skip to content

Commit d8b69eb

Browse files
committed
fix: check if work update happened within 24h before publishing
1 parent 4fb0c4c commit d8b69eb

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/jobs/check-feeds.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '../enums/warnings';
1515
import NewWork from '../templates/new-work';
1616
import emojis from '../constants/emojis';
17+
import { is } from 'cheerio/dist/commonjs/api/traversing';
1718

1819
function mapSymbolsToEnums(warningsSymbols: string[]) {
1920
const mappedValues: { [key: string]: string | null } = {
@@ -162,12 +163,10 @@ export const checkFeeds: Job = {
162163

163164
const { tagName, works } = await parseFeed(feed);
164165

165-
// Get previous work snapshots from database
166166
const previousSnapshots = (await DataService.getWorkSnapshots(
167167
feed.id
168168
)) as Ao3WorkSnapshot[];
169169

170-
// Create maps for faster lookups
171170
const previousSnapshotsMap = new Map(
172171
previousSnapshots.map(snapshot => [
173172
snapshot.workId,
@@ -193,6 +192,17 @@ export const checkFeeds: Job = {
193192
parseIdFromUrl(work.link)
194193
);
195194

195+
if (work.lastUpdated) {
196+
const lastUpdatedDate = new Date(work.lastUpdated);
197+
if (!isNaN(+lastUpdatedDate)) {
198+
const diff =
199+
new Date().getTime() -
200+
lastUpdatedDate.getTime();
201+
const diffInHours = diff / (1000 * 60 * 60);
202+
if (diffInHours > 24) continue;
203+
}
204+
}
205+
196206
if (!previousSnapshot) {
197207
// Work ID not in snapshots - it's a new work
198208
console.log(`work not in ss: ${work.title}`);

0 commit comments

Comments
 (0)