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 } }))
|
if (await prisma.watchEvent.findUnique({ where: { sessionId } }))
|
||||||
continue;
|
continue;
|
||||||
const percentComplete = item.percent_complete || 0;
|
const percentComplete = item.percent_complete || 0;
|
||||||
const watchDurationMinutes = Math.floor(
|
const watchDurationSeconds =
|
||||||
(item.stopped - item.started) / 60,
|
item.duration ||
|
||||||
);
|
(item.stopped && item.started ? item.stopped - item.started : 0);
|
||||||
|
const watchDurationMinutes = Math.floor(watchDurationSeconds / 60);
|
||||||
if (
|
if (
|
||||||
percentComplete < minWatchPercent ||
|
percentComplete < minWatchPercent ||
|
||||||
watchDurationMinutes < minWatchMinutes
|
watchDurationMinutes < minWatchMinutes ||
|
||||||
|
watchDurationMinutes > 600
|
||||||
)
|
)
|
||||||
continue;
|
continue;
|
||||||
const creditsEarned = watchDurationMinutes * creditsPerMinute;
|
const creditsEarned = watchDurationMinutes * creditsPerMinute;
|
||||||
|
|||||||
Reference in New Issue
Block a user