mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-17 05:47:52 +00:00
fix: corrige gravação de áudio na página de história
- Remove campos não utilizados (class_id e school_id) da tabela story_recordings - Simplifica o componente AudioRecorder para usar apenas campos necessários - Atualiza interface StoryRecording no types/database.ts - Corrige erro de constraint na inserção de gravações
This commit is contained in:
parent
9ecf46a9ac
commit
5573274ad4
@ -5,12 +5,10 @@ import { supabase } from '../../lib/supabase';
|
||||
interface AudioRecorderProps {
|
||||
storyId: string;
|
||||
studentId: string;
|
||||
classId: string;
|
||||
schoolId: string;
|
||||
onAudioUploaded: (audioUrl: string) => void;
|
||||
}
|
||||
|
||||
export function AudioRecorder({ storyId, studentId, classId, schoolId, onAudioUploaded }: AudioRecorderProps) {
|
||||
export function AudioRecorder({ storyId, studentId, onAudioUploaded }: AudioRecorderProps) {
|
||||
const [isRecording, setIsRecording] = useState(false);
|
||||
const [audioBlob, setAudioBlob] = useState<Blob | null>(null);
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
@ -56,15 +54,21 @@ export function AudioRecorder({ storyId, studentId, classId, schoolId, onAudioUp
|
||||
const uploadAudio = async () => {
|
||||
if (!audioBlob) return;
|
||||
|
||||
const { data: { session } } = await supabase.auth.getSession();
|
||||
if (!session?.user) {
|
||||
setError('Usuário não autenticado');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsUploading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
// Criar nome único para o arquivo usando uma estrutura de pastas organizada
|
||||
// Criar nome único para o arquivo
|
||||
const timestamp = new Date().getTime();
|
||||
const filePath = `${studentId}/${classId}/${storyId}/${timestamp}.webm`;
|
||||
const filePath = `${studentId}/${storyId}/${timestamp}.webm`;
|
||||
|
||||
// Upload do arquivo para o Supabase Storage
|
||||
// Upload do arquivo
|
||||
const { data, error: uploadError } = await supabase.storage
|
||||
.from('recordings')
|
||||
.upload(filePath, audioBlob, {
|
||||
@ -74,19 +78,17 @@ export function AudioRecorder({ storyId, studentId, classId, schoolId, onAudioUp
|
||||
|
||||
if (uploadError) throw uploadError;
|
||||
|
||||
// Obter URL pública do arquivo
|
||||
// Obter URL pública
|
||||
const { data: { publicUrl } } = supabase.storage
|
||||
.from('recordings')
|
||||
.getPublicUrl(filePath);
|
||||
|
||||
// Salvar referência no banco com todas as relações
|
||||
// Salvar referência no banco apenas com os campos necessários
|
||||
const { error: dbError } = await supabase
|
||||
.from('story_recordings')
|
||||
.insert({
|
||||
story_id: storyId,
|
||||
student_id: studentId,
|
||||
class_id: classId,
|
||||
school_id: schoolId,
|
||||
audio_url: publicUrl,
|
||||
status: 'pending_analysis'
|
||||
});
|
||||
|
||||
@ -129,8 +129,6 @@ export function StoryPage() {
|
||||
<AudioRecorder
|
||||
storyId={story.id}
|
||||
studentId={story.student_id}
|
||||
schoolId={story.school_id}
|
||||
classId={story.class_id}
|
||||
onAudioUploaded={(audioUrl) => {
|
||||
console.log('Áudio gravado:', audioUrl);
|
||||
}}
|
||||
|
||||
@ -130,3 +130,11 @@ export interface StudentWithStories extends Student {
|
||||
export interface ClassWithStudentsAndStories extends Class {
|
||||
students: StudentWithStories[];
|
||||
}
|
||||
|
||||
interface StoryRecording {
|
||||
id: string;
|
||||
student_id: string;
|
||||
story_id: string;
|
||||
audio_url: string;
|
||||
created_at: string;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user