fix: use duration field, guard null started/stopped, cap 10h
This commit is contained in:
@@ -54,12 +54,14 @@ export async function backfillUserHistory(user: {
|
||||
if (await prisma.watchEvent.findUnique({ where: { sessionId } }))
|
||||
continue;
|
||||
const percentComplete = item.percent_complete || 0;
|
||||
const watchDurationMinutes = Math.floor(
|
||||
(item.stopped - item.started) / 60,
|
||||
);
|
||||
const watchDurationSeconds =
|
||||
item.duration ||
|
||||
(item.stopped && item.started ? item.stopped - item.started : 0);
|
||||
const watchDurationMinutes = Math.floor(watchDurationSeconds / 60);
|
||||
if (
|
||||
percentComplete < minWatchPercent ||
|
||||
watchDurationMinutes < minWatchMinutes
|
||||
watchDurationMinutes < minWatchMinutes ||
|
||||
watchDurationMinutes > 600
|
||||
)
|
||||
continue;
|
||||
const creditsEarned = watchDurationMinutes * creditsPerMinute;
|
||||
|
||||
Reference in New Issue
Block a user