91edba56d6
Course cards go back to the colour-block art that previously sat under the captured frame, so the UI is unchanged apart from losing the photo. - Drop thumb.php, generateThumbnails(), captureThumbnail() and ensureThumbnailColumns(), plus the first-video tracking the scanner only kept to pick a frame source. - Drop the ffprobe fallback in probeDuration(); the pure-PHP mvhd parse is now the only scan-time probe, with the player's report on first play as the remaining fallback. - Drop THUMBNAILS_DIR/THUMBNAIL_SEEK_PERCENT from config, the thumbnail_* columns from schema.sql, the thumbnail counters from scan output, .thumb img from the stylesheet, and the matching README parts. Existing databases keep two now-unused folders.thumbnail_* columns; they are inert and can be dropped by hand if wanted. Claude-Session: https://claude.ai/code/session_014oyi9DMdhALrGz989MNNZJ
66 lines
2.4 KiB
PHP
66 lines
2.4 KiB
PHP
<?php
|
|
// GET api/progress.php?video_id=N -> saved progress for this user/video
|
|
// POST api/progress.php -> save progress
|
|
// JSON body: {video_id, position, duration}
|
|
// (also accepts form-encoded fields; used by navigator.sendBeacon)
|
|
require_once __DIR__ . '/../includes/auth.php';
|
|
require_once __DIR__ . '/../includes/functions.php';
|
|
|
|
header('Content-Type: application/json');
|
|
$userId = requireLoginApi();
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
|
$videoId = (int)($_GET['video_id'] ?? 0);
|
|
$stmt = db()->prepare(
|
|
'SELECT position_seconds, duration_seconds, completed
|
|
FROM video_progress WHERE user_id = ? AND video_id = ?'
|
|
);
|
|
$stmt->execute([$userId, $videoId]);
|
|
echo json_encode($stmt->fetch() ?: ['position_seconds' => 0, 'duration_seconds' => null, 'completed' => 0]);
|
|
exit;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
http_response_code(405);
|
|
echo json_encode(['error' => 'Method not allowed']);
|
|
exit;
|
|
}
|
|
|
|
$raw = file_get_contents('php://input');
|
|
$data = json_decode($raw, true);
|
|
if (!is_array($data)) {
|
|
parse_str($raw, $data); // sendBeacon posts form-encoded
|
|
}
|
|
|
|
$videoId = (int)($data['video_id'] ?? 0);
|
|
$position = max(0, (float)($data['position'] ?? 0));
|
|
$duration = (float)($data['duration'] ?? 0);
|
|
|
|
if ($videoId <= 0 || !getVideo($videoId)) {
|
|
http_response_code(400);
|
|
echo json_encode(['error' => 'Unknown video']);
|
|
exit;
|
|
}
|
|
|
|
$completed = ($duration > 0 && $position / $duration >= COMPLETE_THRESHOLD) ? 1 : 0;
|
|
|
|
$db = db();
|
|
$stmt = $db->prepare(
|
|
'INSERT INTO video_progress (user_id, video_id, position_seconds, duration_seconds, completed)
|
|
VALUES (?, ?, ?, ?, ?)
|
|
ON DUPLICATE KEY UPDATE
|
|
position_seconds = VALUES(position_seconds),
|
|
duration_seconds = VALUES(duration_seconds),
|
|
completed = GREATEST(completed, VALUES(completed))' // once complete, stays complete
|
|
);
|
|
$stmt->execute([$userId, $videoId, $position, $duration > 0 ? $duration : null, $completed]);
|
|
|
|
// Cache the duration on the video row so listings can show it without waiting
|
|
// for someone to play the video (and for files the scanner couldn't parse).
|
|
if ($duration > 0) {
|
|
$db->prepare('UPDATE videos SET duration_seconds = ? WHERE id = ? AND duration_seconds IS NULL')
|
|
->execute([$duration, $videoId]);
|
|
}
|
|
|
|
echo json_encode(['ok' => true, 'completed' => (bool)$completed]);
|