This commit is contained in:
Marcelo
2026-03-20 04:54:08 +00:00
parent 62b3cfe467
commit 02afbd7cfb
12 changed files with 1491 additions and 299 deletions

View File

@@ -14,7 +14,7 @@ export default function VideoUpload({ lessonId, currentVideoUrl, onUploadComplet
const [uploading, setUploading] = useState(false);
const [progress, setProgress] = useState(0);
const handleUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
const handleVideoUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (!file) return;
@@ -26,28 +26,46 @@ export default function VideoUpload({ lessonId, currentVideoUrl, onUploadComplet
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!
);
// Create a unique file path: lesson_id/timestamp_filename
// 1. Verify session
const { data: { user }, error: authError } = await supabase.auth.getUser();
if (authError || !user) {
toast.error("Authentication error: Please log in again.");
setUploading(false);
return;
}
console.log("Authenticated User ID:", user.id);
// 2. Create a unique file path: lesson_id/timestamp_filename
const filePath = `${lessonId}/${Date.now()}_${file.name}`;
// 3. Upload to Supabase Storage
const { error } = await supabase.storage
.from("courses") // Make sure this bucket exists!
.from("courses")
.upload(filePath, file, {
upsert: true,
});
if (error) {
toast.error("Upload failed: " + error.message);
console.error("Storage upload error:", error);
// Hint for common RLS issue
if (error.message.includes("row-level security policy")) {
toast.error("Upload failed: RLS Policy error. Make sure 'courses' bucket allows uploads for authenticated teachers.");
} else {
toast.error("Upload failed: " + error.message);
}
setUploading(false);
return;
}
// Get Public URL
// 4. Get Public URL
const { data: { publicUrl } } = supabase.storage
.from("courses")
.getPublicUrl(filePath);
onUploadComplete(publicUrl);
setUploading(false);
toast.success("Video subido con éxito");
};
return (
@@ -73,7 +91,7 @@ export default function VideoUpload({ lessonId, currentVideoUrl, onUploadComplet
<input
type="file"
accept="video/*"
onChange={handleUpload}
onChange={handleVideoUpload}
disabled={uploading}
className="block w-full text-sm text-slate-500
file:mr-4 file:py-2 file:px-4