feat: working frontend AI transcribe
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -583,3 +583,20 @@ def api_post_audit(post_id: int):
|
|||||||
return jsonify({"logs": list_audit_logs(post_id=post_id, page=page, limit=limit)})
|
return jsonify({"logs": list_audit_logs(post_id=post_id, page=page, limit=limit)})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return _error(str(e), 500)
|
return _error(str(e), 500)
|
||||||
|
|
||||||
|
@api.get("/posts/<int:post_id>/audio")
|
||||||
|
def api_get_audio_url(post_id: int):
|
||||||
|
"""
|
||||||
|
Get a signed URL for the original audio file.
|
||||||
|
"""
|
||||||
|
expires_in = request.args.get("expires_in", default=3600, type=int)
|
||||||
|
|
||||||
|
try:
|
||||||
|
audio_data = get_original_audio_url(post_id, expires_in=expires_in)
|
||||||
|
return jsonify(audio_data)
|
||||||
|
except ValueError as e:
|
||||||
|
return _error(str(e), 404)
|
||||||
|
except RuntimeError as e:
|
||||||
|
return _error(str(e), 500)
|
||||||
|
except Exception as e:
|
||||||
|
return _error(f"Failed to get audio URL: {e}", 500)
|
||||||
|
|||||||
BIN
backend/uploads/15e03d49-14bd-42dd-bb7f-2e28e930c361_data.m4a
Normal file
BIN
backend/uploads/15e03d49-14bd-42dd-bb7f-2e28e930c361_data.m4a
Normal file
Binary file not shown.
BIN
backend/uploads/21dc3b26-0b05-4669-a86a-053f0b441f59_data.m4a
Normal file
BIN
backend/uploads/21dc3b26-0b05-4669-a86a-053f0b441f59_data.m4a
Normal file
Binary file not shown.
BIN
backend/uploads/2bbc9bd6-7895-4cd1-8040-c2e886f4e901_data.m4a
Normal file
BIN
backend/uploads/2bbc9bd6-7895-4cd1-8040-c2e886f4e901_data.m4a
Normal file
Binary file not shown.
BIN
backend/uploads/dd79bca3-9b6d-4fc5-ab24-cbf09b4930a6_data.m4a
Normal file
BIN
backend/uploads/dd79bca3-9b6d-4fc5-ab24-cbf09b4930a6_data.m4a
Normal file
Binary file not shown.
@@ -3,7 +3,7 @@
|
|||||||
* Handles all communication with Flask API
|
* Handles all communication with Flask API
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const API_BASE_URL = 'http://127.0.0.1:5000/api';
|
const API_BASE_URL = 'http://localhost:5000/api';
|
||||||
|
|
||||||
class ApiClient {
|
class ApiClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -107,7 +107,8 @@ class ApiClient {
|
|||||||
if (params.page) queryParams.append('page', params.page);
|
if (params.page) queryParams.append('page', params.page);
|
||||||
if (params.limit) queryParams.append('limit', params.limit);
|
if (params.limit) queryParams.append('limit', params.limit);
|
||||||
if (params.visibility) queryParams.append('visibility', params.visibility);
|
if (params.visibility) queryParams.append('visibility', params.visibility);
|
||||||
if (params.user_id) queryParams.append('user_id', params.user_id);
|
// Pass current_user_id for privacy checks (not filtering by author)
|
||||||
|
if (params.current_user_id) queryParams.append('current_user_id', params.current_user_id);
|
||||||
|
|
||||||
return this.request(`/posts?${queryParams.toString()}`);
|
return this.request(`/posts?${queryParams.toString()}`);
|
||||||
}
|
}
|
||||||
@@ -132,6 +133,10 @@ class ApiClient {
|
|||||||
return this.updatePost(postId, { status: 'deleted' });
|
return this.updatePost(postId, { status: 'deleted' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getPostMetadata(postId) {
|
||||||
|
return this.request(`/posts/${postId}/metadata`);
|
||||||
|
}
|
||||||
|
|
||||||
// ==================== Post Files ====================
|
// ==================== Post Files ====================
|
||||||
|
|
||||||
async getPostFiles(postId) {
|
async getPostFiles(postId) {
|
||||||
|
|||||||
@@ -1,6 +1,17 @@
|
|||||||
import { Play, Volume2, MoreVertical, Clock } from 'lucide-react'
|
import { Play, Pause, Volume2, MoreVertical, Clock, ChevronDown, ChevronUp } from 'lucide-react'
|
||||||
|
import { useState, useRef, useEffect } from 'react'
|
||||||
|
import { api } from '../api'
|
||||||
|
|
||||||
|
export default function AudioPostCard({ post }) {
|
||||||
|
const [isPlaying, setIsPlaying] = useState(false)
|
||||||
|
const [currentTime, setCurrentTime] = useState(0)
|
||||||
|
const [duration, setDuration] = useState(0)
|
||||||
|
const [volume, setVolume] = useState(1)
|
||||||
|
const [transcript, setTranscript] = useState(null)
|
||||||
|
const [loadingTranscript, setLoadingTranscript] = useState(false)
|
||||||
|
const [transcriptExpanded, setTranscriptExpanded] = useState(false)
|
||||||
|
const audioRef = useRef(null)
|
||||||
|
|
||||||
export default function AudioPostCard({ post, onPlay }) {
|
|
||||||
const formatDate = (dateString) => {
|
const formatDate = (dateString) => {
|
||||||
const date = new Date(dateString)
|
const date = new Date(dateString)
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
@@ -12,6 +23,92 @@ export default function AudioPostCard({ post, onPlay }) {
|
|||||||
return `${Math.floor(diffMins / 1440)}d ago`
|
return `${Math.floor(diffMins / 1440)}d ago`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formatTime = (seconds) => {
|
||||||
|
if (!seconds || isNaN(seconds)) return '0:00'
|
||||||
|
const mins = Math.floor(seconds / 60)
|
||||||
|
const secs = Math.floor(seconds % 60)
|
||||||
|
return `${mins}:${secs.toString().padStart(2, '0')}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load transcript on mount if post is ready
|
||||||
|
useEffect(() => {
|
||||||
|
if (post.status === 'ready' && !transcript && !loadingTranscript) {
|
||||||
|
loadTranscript()
|
||||||
|
}
|
||||||
|
}, [post.post_id, post.status])
|
||||||
|
|
||||||
|
const loadTranscript = async () => {
|
||||||
|
setLoadingTranscript(true)
|
||||||
|
try {
|
||||||
|
const metadata = await api.getPostMetadata(post.post_id)
|
||||||
|
if (metadata && metadata.metadata) {
|
||||||
|
const metadataObj = JSON.parse(metadata.metadata)
|
||||||
|
const promptText = metadataObj.prompt || ''
|
||||||
|
const transcriptMatch = promptText.match(/Transcript:\n([\s\S]*?)\n\nAnswer user questions/)
|
||||||
|
if (transcriptMatch) {
|
||||||
|
setTranscript(transcriptMatch[1].trim())
|
||||||
|
} else {
|
||||||
|
setTranscript('Transcript not available')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to load transcript:', err)
|
||||||
|
setTranscript('Failed to load transcript')
|
||||||
|
} finally {
|
||||||
|
setLoadingTranscript(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const togglePlay = () => {
|
||||||
|
if (!audioRef.current) return
|
||||||
|
|
||||||
|
if (isPlaying) {
|
||||||
|
audioRef.current.pause()
|
||||||
|
} else {
|
||||||
|
audioRef.current.play()
|
||||||
|
}
|
||||||
|
setIsPlaying(!isPlaying)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleTimeUpdate = () => {
|
||||||
|
if (audioRef.current) {
|
||||||
|
setCurrentTime(audioRef.current.currentTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleLoadedMetadata = () => {
|
||||||
|
if (audioRef.current) {
|
||||||
|
setDuration(audioRef.current.duration)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSeek = (e) => {
|
||||||
|
const rect = e.currentTarget.getBoundingClientRect()
|
||||||
|
const x = e.clientX - rect.left
|
||||||
|
const percentage = x / rect.width
|
||||||
|
const newTime = percentage * duration
|
||||||
|
|
||||||
|
if (audioRef.current) {
|
||||||
|
audioRef.current.currentTime = newTime
|
||||||
|
setCurrentTime(newTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleVolumeChange = (e) => {
|
||||||
|
const newVolume = parseFloat(e.target.value)
|
||||||
|
setVolume(newVolume)
|
||||||
|
if (audioRef.current) {
|
||||||
|
audioRef.current.volume = newVolume
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleEnded = () => {
|
||||||
|
setIsPlaying(false)
|
||||||
|
setCurrentTime(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
const progress = duration > 0 ? (currentTime / duration) * 100 : 0
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<article className="bg-white rounded-lg border border-gray-200 overflow-hidden shadow-sm hover:shadow-md transition-shadow">
|
<article className="bg-white rounded-lg border border-gray-200 overflow-hidden shadow-sm hover:shadow-md transition-shadow">
|
||||||
{/* Post Header */}
|
{/* Post Header */}
|
||||||
@@ -53,30 +150,101 @@ export default function AudioPostCard({ post, onPlay }) {
|
|||||||
|
|
||||||
{/* Audio Player - Only show if ready */}
|
{/* Audio Player - Only show if ready */}
|
||||||
{post.status === 'ready' && (
|
{post.status === 'ready' && (
|
||||||
|
<>
|
||||||
<div className="bg-gray-50 rounded-lg p-4 border border-gray-200">
|
<div className="bg-gray-50 rounded-lg p-4 border border-gray-200">
|
||||||
|
{/* Hidden audio element */}
|
||||||
|
<audio
|
||||||
|
ref={audioRef}
|
||||||
|
src={post.audio_path}
|
||||||
|
onTimeUpdate={handleTimeUpdate}
|
||||||
|
onLoadedMetadata={handleLoadedMetadata}
|
||||||
|
onEnded={handleEnded}
|
||||||
|
preload="metadata"
|
||||||
|
/>
|
||||||
|
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
<button
|
<button
|
||||||
onClick={() => onPlay?.(post)}
|
onClick={togglePlay}
|
||||||
className="w-10 h-10 bg-[#f4b840] hover:bg-[#e5a930] rounded-full flex items-center justify-center text-[#1a1a1a] transition-colors"
|
className="w-10 h-10 bg-[#f4b840] hover:bg-[#e5a930] rounded-full flex items-center justify-center text-[#1a1a1a] transition-colors"
|
||||||
>
|
>
|
||||||
|
{isPlaying ? (
|
||||||
|
<Pause size={16} fill="currentColor" />
|
||||||
|
) : (
|
||||||
<Play size={16} fill="currentColor" />
|
<Play size={16} fill="currentColor" />
|
||||||
|
)}
|
||||||
</button>
|
</button>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
<div className="h-1.5 bg-gray-300 rounded-full overflow-hidden mb-2">
|
<div
|
||||||
<div className="h-full w-0 bg-[#f4b840] rounded-full"></div>
|
className="h-1.5 bg-gray-300 rounded-full overflow-hidden mb-2 cursor-pointer"
|
||||||
|
onClick={handleSeek}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="h-full bg-[#f4b840] rounded-full transition-all"
|
||||||
|
style={{ width: `${progress}%` }}
|
||||||
|
></div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between text-xs text-gray-600">
|
<div className="flex justify-between text-xs text-gray-600">
|
||||||
<span>0:00</span>
|
<span>{formatTime(currentTime)}</span>
|
||||||
<span>--:--</span>
|
<span>{formatTime(duration)}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button className="text-gray-600 hover:text-gray-900">
|
<div className="flex items-center gap-2">
|
||||||
<Volume2 size={18} />
|
<Volume2 size={18} className="text-gray-600" />
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min="0"
|
||||||
|
max="1"
|
||||||
|
step="0.01"
|
||||||
|
value={volume}
|
||||||
|
onChange={handleVolumeChange}
|
||||||
|
className="w-16 h-1.5 bg-gray-300 rounded-full appearance-none cursor-pointer"
|
||||||
|
style={{
|
||||||
|
background: `linear-gradient(to right, #f4b840 0%, #f4b840 ${volume * 100}%, #d1d5db ${volume * 100}%, #d1d5db 100%)`
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Transcript Section - Always shown */}
|
||||||
|
<div className="mt-4 border border-gray-200 rounded-lg overflow-hidden">
|
||||||
|
<button
|
||||||
|
onClick={() => setTranscriptExpanded(!transcriptExpanded)}
|
||||||
|
className="w-full flex items-center justify-between p-3 bg-gray-50 hover:bg-gray-100 transition-colors"
|
||||||
|
>
|
||||||
|
<span className="text-sm font-medium text-gray-900">Transcript</span>
|
||||||
|
{loadingTranscript ? (
|
||||||
|
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-gray-600"></div>
|
||||||
|
) : (
|
||||||
|
transcriptExpanded ? <ChevronUp size={18} /> : <ChevronDown size={18} />
|
||||||
|
)}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
{transcript && (
|
||||||
|
<div className={`bg-white transition-all ${transcriptExpanded ? 'max-h-96' : 'max-h-24'} overflow-y-auto`}>
|
||||||
|
<div className="p-4">
|
||||||
|
<p className="text-sm text-gray-700 leading-relaxed whitespace-pre-wrap">
|
||||||
|
{transcript}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{!transcript && !loadingTranscript && (
|
||||||
|
<div className="p-4 bg-white">
|
||||||
|
<p className="text-sm text-gray-500 italic">No transcript available</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loadingTranscript && (
|
||||||
|
<div className="p-4 bg-white text-center">
|
||||||
|
<p className="text-sm text-gray-500">Loading transcript...</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Processing Status */}
|
{/* Processing Status */}
|
||||||
{post.status === 'processing' && (
|
{post.status === 'processing' && (
|
||||||
<div className="bg-yellow-50 rounded-lg p-4 border border-yellow-200 text-center">
|
<div className="bg-yellow-50 rounded-lg p-4 border border-yellow-200 text-center">
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Search, User, Volume2 } from 'lucide-react'
|
import { Search, LogOut } from 'lucide-react'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
|
||||||
export default function Header({ user, onSearch, onLogout }) {
|
export default function Header({ onSearch, onLogout }) {
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
|
|
||||||
const handleSearch = (e) => {
|
const handleSearch = (e) => {
|
||||||
@@ -16,7 +16,9 @@ export default function Header({ user, onSearch, onLogout }) {
|
|||||||
{/* Left: Logo */}
|
{/* Left: Logo */}
|
||||||
<div className="flex items-center gap-3 flex-shrink-0">
|
<div className="flex items-center gap-3 flex-shrink-0">
|
||||||
<div className="w-8 h-8 bg-[#f4b840] rounded-lg flex items-center justify-center">
|
<div className="w-8 h-8 bg-[#f4b840] rounded-lg flex items-center justify-center">
|
||||||
<Volume2 size={18} className="text-white" />
|
<svg className="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4m-4-8a3 3 0 01-3-3V5a3 3 0 116 0v6a3 3 0 01-3 3z" />
|
||||||
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
<h1 className="text-lg font-bold text-gray-900">VoiceVault</h1>
|
<h1 className="text-lg font-bold text-gray-900">VoiceVault</h1>
|
||||||
</div>
|
</div>
|
||||||
@@ -35,25 +37,16 @@ export default function Header({ user, onSearch, onLogout }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right: User Info / Login */}
|
{/* Right: Logout */}
|
||||||
<div className="flex items-center gap-3 flex-shrink-0">
|
<div className="flex items-center gap-3 flex-shrink-0">
|
||||||
{user ? (
|
|
||||||
<div className="flex items-center gap-3">
|
|
||||||
<span className="text-sm text-gray-700">{user.display_name || user.email}</span>
|
|
||||||
<button
|
<button
|
||||||
onClick={onLogout}
|
onClick={onLogout}
|
||||||
className="text-sm text-gray-600 hover:text-gray-900"
|
className="flex items-center gap-2 text-sm text-gray-600 hover:text-gray-900 px-3 py-2 rounded hover:bg-gray-100 transition-colors"
|
||||||
>
|
>
|
||||||
Logout
|
<LogOut size={16} />
|
||||||
|
<span>Logout</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
|
||||||
<button className="bg-[#f4b840] hover:bg-[#e5a930] text-[#1a1a1a] px-4 py-2 rounded text-sm font-medium flex items-center gap-2">
|
|
||||||
<User size={16} />
|
|
||||||
Log In
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Plus, Home, History, Settings } from 'lucide-react'
|
import { Plus, Home, History, Settings } from 'lucide-react'
|
||||||
|
|
||||||
export default function Sidebar({ activeTab, onTabChange }) {
|
export default function Sidebar({ user, activeTab, onTabChange }) {
|
||||||
const navItems = [
|
const navItems = [
|
||||||
{ id: 'create', label: 'Make an Archive Post', icon: Plus },
|
{ id: 'create', label: 'Make an Archive Post', icon: Plus },
|
||||||
{ id: 'feed', label: 'My Feed', icon: Home },
|
{ id: 'feed', label: 'My Feed', icon: Home },
|
||||||
@@ -8,9 +8,42 @@ export default function Sidebar({ activeTab, onTabChange }) {
|
|||||||
{ id: 'settings', label: 'Settings', icon: Settings }
|
{ id: 'settings', label: 'Settings', icon: Settings }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
// Get user initials
|
||||||
|
const getInitials = () => {
|
||||||
|
if (user?.display_name) {
|
||||||
|
return user.display_name
|
||||||
|
.split(' ')
|
||||||
|
.map(n => n[0])
|
||||||
|
.join('')
|
||||||
|
.toUpperCase()
|
||||||
|
.slice(0, 2)
|
||||||
|
}
|
||||||
|
if (user?.email) {
|
||||||
|
return user.email.slice(0, 2).toUpperCase()
|
||||||
|
}
|
||||||
|
return 'U'
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside className="w-64 bg-white border-r border-gray-200 p-6 hidden md:block flex-shrink-0 overflow-y-auto">
|
<aside className="w-64 bg-white border-r border-gray-200 p-6 hidden md:block flex-shrink-0 overflow-y-auto">
|
||||||
<div className="sticky top-6">
|
<div className="sticky top-6">
|
||||||
|
{/* User Profile */}
|
||||||
|
{user && (
|
||||||
|
<div className="mb-6 text-center">
|
||||||
|
<div className="w-20 h-20 bg-gradient-to-br from-[#f4b840] to-[#e5a930] rounded-full flex items-center justify-center text-[#1a1a1a] font-bold text-2xl mx-auto mb-3">
|
||||||
|
{getInitials()}
|
||||||
|
</div>
|
||||||
|
<h2 className="text-base font-semibold text-gray-900 truncate">
|
||||||
|
{user.display_name || user.email}
|
||||||
|
</h2>
|
||||||
|
{user.bio && (
|
||||||
|
<p className="text-xs text-gray-600 mt-1 line-clamp-2">
|
||||||
|
{user.bio}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Navigation */}
|
{/* Navigation */}
|
||||||
<nav className="space-y-2">
|
<nav className="space-y-2">
|
||||||
{navItems.map((item) => {
|
{navItems.map((item) => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { Upload, X } from 'lucide-react'
|
import { Upload, X, FileText } from 'lucide-react'
|
||||||
import { api } from '../api'
|
import { api } from '../api'
|
||||||
|
|
||||||
export default function CreatePost({ user, onPostCreated }) {
|
export default function CreatePost({ user, onPostCreated }) {
|
||||||
@@ -8,14 +8,15 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
const [visibility, setVisibility] = useState('private')
|
const [visibility, setVisibility] = useState('private')
|
||||||
const [language, setLanguage] = useState('en')
|
const [language, setLanguage] = useState('en')
|
||||||
const [audioFile, setAudioFile] = useState(null)
|
const [audioFile, setAudioFile] = useState(null)
|
||||||
const [uploading, setUploading] = useState(false)
|
const [transcribing, setTranscribing] = useState(false)
|
||||||
|
const [transcript, setTranscript] = useState(null)
|
||||||
|
const [postData, setPostData] = useState(null)
|
||||||
const [error, setError] = useState(null)
|
const [error, setError] = useState(null)
|
||||||
const [success, setSuccess] = useState(false)
|
const [success, setSuccess] = useState(false)
|
||||||
|
|
||||||
const handleFileSelect = (e) => {
|
const handleFileSelect = (e) => {
|
||||||
const file = e.target.files[0]
|
const file = e.target.files[0]
|
||||||
if (file) {
|
if (file) {
|
||||||
// Check file type
|
|
||||||
const validTypes = ['audio/mpeg', 'audio/wav', 'audio/ogg', 'audio/flac', 'audio/mp4', 'video/mp4']
|
const validTypes = ['audio/mpeg', 'audio/wav', 'audio/ogg', 'audio/flac', 'audio/mp4', 'video/mp4']
|
||||||
if (!validTypes.includes(file.type) && !file.name.match(/\.(mp3|wav|ogg|flac|m4a|mp4|mov|mkv|webm)$/i)) {
|
if (!validTypes.includes(file.type) && !file.name.match(/\.(mp3|wav|ogg|flac|m4a|mp4|mov|mkv|webm)$/i)) {
|
||||||
setError('Invalid file type. Please upload an audio or video file.')
|
setError('Invalid file type. Please upload an audio or video file.')
|
||||||
@@ -23,31 +24,30 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setAudioFile(file)
|
setAudioFile(file)
|
||||||
|
setTranscript(null)
|
||||||
|
setPostData(null)
|
||||||
setError(null)
|
setError(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleSubmit = async (e) => {
|
const handleTranscribe = async () => {
|
||||||
e.preventDefault()
|
|
||||||
|
|
||||||
if (!audioFile) {
|
if (!audioFile) {
|
||||||
setError('Please select an audio file')
|
setError('Please select an audio file first')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!title.trim()) {
|
if (!title.trim()) {
|
||||||
setError('Please enter a title')
|
setError('Please enter a title first')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user?.user_id) {
|
if (!user?.user_id) {
|
||||||
setError('You must be logged in to create a post')
|
setError('You must be logged in')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setUploading(true)
|
setTranscribing(true)
|
||||||
setError(null)
|
setError(null)
|
||||||
setSuccess(false)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
@@ -60,26 +60,36 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
|
|
||||||
const response = await api.uploadPost(formData)
|
const response = await api.uploadPost(formData)
|
||||||
|
|
||||||
console.log('Upload response:', response)
|
if (response.transcript_text) {
|
||||||
|
setTranscript(response.transcript_text)
|
||||||
|
setPostData(response)
|
||||||
setSuccess(true)
|
setSuccess(true)
|
||||||
|
setTimeout(() => setSuccess(false), 3000)
|
||||||
|
} else {
|
||||||
|
setError('Transcription completed but no transcript returned')
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
setError(err.message || 'Failed to transcribe audio')
|
||||||
|
} finally {
|
||||||
|
setTranscribing(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reset form
|
const handleReset = () => {
|
||||||
setTitle('')
|
setTitle('')
|
||||||
setDescription('')
|
setDescription('')
|
||||||
setVisibility('private')
|
setVisibility('private')
|
||||||
setLanguage('en')
|
setLanguage('en')
|
||||||
setAudioFile(null)
|
setAudioFile(null)
|
||||||
|
setTranscript(null)
|
||||||
// Notify parent component
|
setPostData(null)
|
||||||
onPostCreated?.(response)
|
setError(null)
|
||||||
|
setSuccess(false)
|
||||||
// Show success message
|
|
||||||
setTimeout(() => setSuccess(false), 5000)
|
|
||||||
} catch (err) {
|
|
||||||
setError(err.message || 'Failed to upload post')
|
|
||||||
} finally {
|
|
||||||
setUploading(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleCreateAnother = () => {
|
||||||
|
handleReset()
|
||||||
|
onPostCreated?.()
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -95,14 +105,15 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
|
|
||||||
{success && (
|
{success && (
|
||||||
<div className="mb-4 p-4 bg-green-50 border border-green-200 rounded-lg">
|
<div className="mb-4 p-4 bg-green-50 border border-green-200 rounded-lg">
|
||||||
<p className="text-sm text-green-800">
|
<p className="text-sm text-green-800 font-medium">
|
||||||
Post uploaded successfully! Transcript is being generated...
|
✓ Archive created and transcribed successfully!
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<form onSubmit={handleSubmit} className="space-y-6">
|
{!transcript ? (
|
||||||
{/* Title Input */}
|
// STEP 1: Upload and Configure
|
||||||
|
<div className="space-y-6">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-900 mb-2">
|
<label className="block text-sm font-medium text-gray-900 mb-2">
|
||||||
Title *
|
Title *
|
||||||
@@ -114,11 +125,10 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
placeholder="Give your archive a descriptive title..."
|
placeholder="Give your archive a descriptive title..."
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#f4b840] focus:border-transparent"
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#f4b840] focus:border-transparent"
|
||||||
required
|
required
|
||||||
disabled={uploading}
|
disabled={transcribing}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Description Input */}
|
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-900 mb-2">
|
<label className="block text-sm font-medium text-gray-900 mb-2">
|
||||||
Description (optional)
|
Description (optional)
|
||||||
@@ -129,11 +139,10 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
placeholder="Add a description or context for this recording..."
|
placeholder="Add a description or context for this recording..."
|
||||||
rows={3}
|
rows={3}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#f4b840] focus:border-transparent resize-none"
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#f4b840] focus:border-transparent resize-none"
|
||||||
disabled={uploading}
|
disabled={transcribing}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Audio File Upload */}
|
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-900 mb-2">
|
<label className="block text-sm font-medium text-gray-900 mb-2">
|
||||||
Audio/Video File *
|
Audio/Video File *
|
||||||
@@ -155,7 +164,7 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
accept="audio/*,video/mp4,video/quicktime,video/x-matroska,video/webm"
|
accept="audio/*,video/mp4,video/quicktime,video/x-matroska,video/webm"
|
||||||
onChange={handleFileSelect}
|
onChange={handleFileSelect}
|
||||||
className="hidden"
|
className="hidden"
|
||||||
disabled={uploading}
|
disabled={transcribing}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
) : (
|
) : (
|
||||||
@@ -177,7 +186,7 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={() => setAudioFile(null)}
|
onClick={() => setAudioFile(null)}
|
||||||
className="text-gray-500 hover:text-gray-700 ml-2"
|
className="text-gray-500 hover:text-gray-700 ml-2"
|
||||||
disabled={uploading}
|
disabled={transcribing}
|
||||||
>
|
>
|
||||||
<X size={20} />
|
<X size={20} />
|
||||||
</button>
|
</button>
|
||||||
@@ -185,7 +194,6 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Language Selection */}
|
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-900 mb-2">
|
<label className="block text-sm font-medium text-gray-900 mb-2">
|
||||||
Language
|
Language
|
||||||
@@ -194,7 +202,7 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
value={language}
|
value={language}
|
||||||
onChange={(e) => setLanguage(e.target.value)}
|
onChange={(e) => setLanguage(e.target.value)}
|
||||||
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#f4b840] focus:border-transparent"
|
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#f4b840] focus:border-transparent"
|
||||||
disabled={uploading}
|
disabled={transcribing}
|
||||||
>
|
>
|
||||||
<option value="en">English</option>
|
<option value="en">English</option>
|
||||||
<option value="es">Spanish</option>
|
<option value="es">Spanish</option>
|
||||||
@@ -209,7 +217,6 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Visibility Toggle */}
|
|
||||||
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg border border-gray-200">
|
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg border border-gray-200">
|
||||||
<div>
|
<div>
|
||||||
<p className="font-medium text-gray-900">Visibility</p>
|
<p className="font-medium text-gray-900">Visibility</p>
|
||||||
@@ -226,7 +233,7 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
? 'bg-[#f4b840] text-[#1a1a1a]'
|
? 'bg-[#f4b840] text-[#1a1a1a]'
|
||||||
: 'bg-gray-200 text-gray-700 hover:bg-gray-300'
|
: 'bg-gray-200 text-gray-700 hover:bg-gray-300'
|
||||||
}`}
|
}`}
|
||||||
disabled={uploading}
|
disabled={transcribing}
|
||||||
>
|
>
|
||||||
Private
|
Private
|
||||||
</button>
|
</button>
|
||||||
@@ -238,44 +245,100 @@ export default function CreatePost({ user, onPostCreated }) {
|
|||||||
? 'bg-[#f4b840] text-[#1a1a1a]'
|
? 'bg-[#f4b840] text-[#1a1a1a]'
|
||||||
: 'bg-gray-200 text-gray-700 hover:bg-gray-300'
|
: 'bg-gray-200 text-gray-700 hover:bg-gray-300'
|
||||||
}`}
|
}`}
|
||||||
disabled={uploading}
|
disabled={transcribing}
|
||||||
>
|
>
|
||||||
Public
|
Public
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Submit Buttons */}
|
|
||||||
<div className="flex gap-3">
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={handleTranscribe}
|
||||||
setTitle('')
|
disabled={transcribing || !audioFile || !title.trim()}
|
||||||
setDescription('')
|
className="w-full px-4 py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-lg font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
|
||||||
setAudioFile(null)
|
|
||||||
setError(null)
|
|
||||||
}}
|
|
||||||
className="flex-1 px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition-colors"
|
|
||||||
disabled={uploading}
|
|
||||||
>
|
>
|
||||||
Cancel
|
{transcribing ? (
|
||||||
</button>
|
<>
|
||||||
<button
|
<div className="animate-spin rounded-full h-5 w-5 border-b-2 border-white"></div>
|
||||||
type="submit"
|
Transcribing & Creating Archive...
|
||||||
disabled={uploading || !audioFile || !title.trim()}
|
</>
|
||||||
className="flex-1 px-4 py-2 bg-[#f4b840] hover:bg-[#e5a930] text-[#1a1a1a] rounded-lg font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
|
|
||||||
>
|
|
||||||
{uploading ? (
|
|
||||||
<span className="flex items-center justify-center gap-2">
|
|
||||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-[#1a1a1a]"></div>
|
|
||||||
Uploading...
|
|
||||||
</span>
|
|
||||||
) : (
|
) : (
|
||||||
'Create Archive'
|
<>
|
||||||
|
<FileText size={18} />
|
||||||
|
Transcribe & Create Archive
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
|
<p className="text-xs text-gray-600 text-center">
|
||||||
|
This will upload your file and generate a transcript
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
) : (
|
||||||
|
// STEP 2: Show Results
|
||||||
|
<div className="space-y-6">
|
||||||
|
<div className="p-5 bg-green-50 border border-green-200 rounded-lg">
|
||||||
|
<div className="flex items-start gap-3 mb-3">
|
||||||
|
<div className="w-10 h-10 bg-green-600 rounded-full flex items-center justify-center flex-shrink-0">
|
||||||
|
<FileText size={20} className="text-white" />
|
||||||
|
</div>
|
||||||
|
<div className="flex-1">
|
||||||
|
<h3 className="text-lg font-semibold text-green-900 mb-1">
|
||||||
|
Archive Created Successfully!
|
||||||
|
</h3>
|
||||||
|
<p className="text-sm text-green-700">
|
||||||
|
Your audio has been transcribed and saved.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-4 p-4 bg-white rounded border border-green-200">
|
||||||
|
<p className="text-xs font-semibold text-gray-900 mb-2">TRANSCRIPT</p>
|
||||||
|
<p className="text-sm text-gray-700 max-h-48 overflow-y-auto">
|
||||||
|
{transcript}
|
||||||
|
</p>
|
||||||
|
<div className="mt-3 pt-3 border-t border-gray-200 flex items-center justify-between text-xs text-gray-600">
|
||||||
|
<span>{transcript.length} characters</span>
|
||||||
|
<span>{postData?.rag_chunk_count || 0} RAG chunks</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-4 p-4 bg-gray-50 rounded-lg">
|
||||||
|
<div>
|
||||||
|
<p className="text-xs text-gray-600 mb-1">Title</p>
|
||||||
|
<p className="text-sm font-medium text-gray-900">{title}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-xs text-gray-600 mb-1">Visibility</p>
|
||||||
|
<p className="text-sm font-medium text-gray-900 capitalize">{visibility}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-xs text-gray-600 mb-1">Language</p>
|
||||||
|
<p className="text-sm font-medium text-gray-900">{language.toUpperCase()}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-xs text-gray-600 mb-1">Status</p>
|
||||||
|
<p className="text-sm font-medium text-green-600">Ready</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex gap-3">
|
||||||
|
<button
|
||||||
|
onClick={() => onPostCreated?.()}
|
||||||
|
className="flex-1 px-4 py-2 bg-[#f4b840] hover:bg-[#e5a930] text-[#1a1a1a] rounded-lg font-medium transition-colors"
|
||||||
|
>
|
||||||
|
View in Feed
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={handleCreateAnother}
|
||||||
|
className="flex-1 px-4 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition-colors"
|
||||||
|
>
|
||||||
|
Create Another
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default function Feed({ user }) {
|
|||||||
const params = {
|
const params = {
|
||||||
page,
|
page,
|
||||||
limit: 20,
|
limit: 20,
|
||||||
user_id: user.user_id,
|
current_user_id: user.user_id, // For backend privacy checks
|
||||||
}
|
}
|
||||||
|
|
||||||
if (visibilityFilter !== 'all') {
|
if (visibilityFilter !== 'all') {
|
||||||
@@ -31,7 +31,14 @@ export default function Feed({ user }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const response = await api.getPosts(params)
|
const response = await api.getPosts(params)
|
||||||
setPosts(response.posts || [])
|
let filteredPosts = response.posts || []
|
||||||
|
|
||||||
|
// Frontend privacy filter: only show posts if they're public OR user is the author
|
||||||
|
filteredPosts = filteredPosts.filter(post => {
|
||||||
|
return post.visibility === 'public' || post.user_id === user.user_id
|
||||||
|
})
|
||||||
|
|
||||||
|
setPosts(filteredPosts)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err.message)
|
setError(err.message)
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user