mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
feat: add video watch progress tracking with resume functionality
Implements a complete watch progress system that allows users to: - Save playback position automatically every 5 seconds while watching - Resume from last position when returning to a video - Save progress on page leave using sendBeacon for reliability Also includes: - Optimized slug generation in projects and workspaces APIs (single query vs loop) - Added isActive filter to version queries across all video endpoints - Added pagination support for video and comment queries - Enhanced database pool management with connection limits and graceful shutdown - New WatchProgress Prisma model with user-version relations
This commit is contained in:
@@ -105,14 +105,19 @@ export async function POST(request: NextRequest) {
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/-+/g, '-');
|
||||
|
||||
// Ensure uniqueness by appending random suffix if needed
|
||||
// Find all existing slugs with the same prefix in a single query
|
||||
const existingProjects = await db.project.findMany({
|
||||
where: { slug: { startsWith: baseSlug } },
|
||||
select: { slug: true },
|
||||
});
|
||||
|
||||
// Generate unique slug from the results
|
||||
const usedSlugs = new Set(existingProjects.map(p => p.slug));
|
||||
let slug = baseSlug;
|
||||
let attempts = 0;
|
||||
while (attempts < 10) {
|
||||
const existing = await db.project.findUnique({ where: { slug } });
|
||||
if (!existing) break;
|
||||
slug = `${baseSlug}-${Math.random().toString(36).substring(2, 6)}`;
|
||||
attempts++;
|
||||
let counter = 1;
|
||||
while (usedSlugs.has(slug)) {
|
||||
slug = `${baseSlug}-${counter}`;
|
||||
counter++;
|
||||
}
|
||||
|
||||
// Verify user has access to the workspace
|
||||
|
||||
Reference in New Issue
Block a user