From 50deee7f2ab5d30442a67ac90bb5d7db453b97e1 Mon Sep 17 00:00:00 2001 From: tigeren Date: Mon, 25 Aug 2025 16:54:17 +0000 Subject: [PATCH] fix: update Tailwind CSS version to v3 in project documentation and ensure compliance with v3 standards --- CLAUDE.md | 1 + GEMINI.md | 1 + PRD.md | 2 +- src/app/api/stream/[id]/route.ts | 63 +++++++++ src/app/videos/page.tsx | 53 +++++--- src/components/video-player.tsx | 218 +++++++++++++++++++++++++++++++ 6 files changed, 320 insertions(+), 18 deletions(-) create mode 100644 src/app/api/stream/[id]/route.ts create mode 100644 src/components/video-player.tsx diff --git a/CLAUDE.md b/CLAUDE.md index 052d373..5b41813 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,5 +1,6 @@ Project Description: This is a nextjs project, basically a youtube like video sites. +the tailwindcss is v3 version. must ensure all the css related tailwind sytling code should comply with the v3 standard Feature requirement: 1. Has a youtube like UI diff --git a/GEMINI.md b/GEMINI.md index 052d373..5b41813 100644 --- a/GEMINI.md +++ b/GEMINI.md @@ -1,5 +1,6 @@ Project Description: This is a nextjs project, basically a youtube like video sites. +the tailwindcss is v3 version. must ensure all the css related tailwind sytling code should comply with the v3 standard Feature requirement: 1. Has a youtube like UI diff --git a/PRD.md b/PRD.md index 5eecc6f..5b41813 100644 --- a/PRD.md +++ b/PRD.md @@ -1,6 +1,6 @@ Project Description: This is a nextjs project, basically a youtube like video sites. -the tailwindcss is v4 version. must ensure all the css related tailwind sytling code should comply with the v4 standard +the tailwindcss is v3 version. must ensure all the css related tailwind sytling code should comply with the v3 standard Feature requirement: 1. Has a youtube like UI diff --git a/src/app/api/stream/[id]/route.ts b/src/app/api/stream/[id]/route.ts new file mode 100644 index 0000000..7174e7d --- /dev/null +++ b/src/app/api/stream/[id]/route.ts @@ -0,0 +1,63 @@ +import { NextRequest, NextResponse } from "next/server"; +import db from "@/db"; +import fs from "fs"; +import path from "path"; + +export async function GET( + request: NextRequest, + { params }: { params: Promise<{ id: string }> } +) { + const { id } = await params; + try { + const videoId = parseInt(id); + + const video = db.prepare("SELECT * FROM media WHERE id = ? AND type = 'video'").get(videoId) as { path: string } | undefined; + + if (!video) { + return NextResponse.json({ error: "Video not found" }, { status: 404 }); + } + + const videoPath = video.path; + + if (!fs.existsSync(videoPath)) { + return NextResponse.json({ error: "Video file not found" }, { status: 404 }); + } + + const stat = fs.statSync(videoPath); + const fileSize = stat.size; + const range = request.headers.get("range"); + + if (range) { + const parts = range.replace(/bytes=/, "").split("-"); + const start = parseInt(parts[0], 10); + const end = parts[1] ? parseInt(parts[1], 10) : fileSize - 1; + const chunksize = end - start + 1; + const file = fs.createReadStream(videoPath, { start, end }); + const headers = new Headers({ + "Content-Range": `bytes ${start}-${end}/${fileSize}`, + "Accept-Ranges": "bytes", + "Content-Length": chunksize.toString(), + "Content-Type": "video/mp4", + }); + + return new Response(file as any, { + status: 206, + headers, + }); + } else { + const headers = new Headers({ + "Content-Length": fileSize.toString(), + "Content-Type": "video/mp4", + }); + const file = fs.createReadStream(videoPath); + + return new Response(file as any, { + status: 200, + headers, + }); + } + } catch (error) { + console.error("Error streaming video:", error); + return NextResponse.json({ error: "Internal server error" }, { status: 500 }); + } +} \ No newline at end of file diff --git a/src/app/videos/page.tsx b/src/app/videos/page.tsx index 4f0969e..13c9e4f 100644 --- a/src/app/videos/page.tsx +++ b/src/app/videos/page.tsx @@ -1,4 +1,3 @@ - "use client"; import { useState, useEffect } from "react"; @@ -7,6 +6,7 @@ import { Film, Play, Clock, HardDrive, Search, Filter } from "lucide-react"; import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; +import VideoPlayer from "@/components/video-player"; interface Video { id: number; @@ -20,6 +20,8 @@ const VideosPage = () => { const [videos, setVideos] = useState([]); const [loading, setLoading] = useState(true); const [searchTerm, setSearchTerm] = useState(""); + const [selectedVideo, setSelectedVideo] = useState