fix: link gain control, restore media export, and handle credentials in api requests
CD — Kai-Sa-Cam Deployment / deploy (push) Successful in 10s

This commit is contained in:
2026-10-25 13:54:39 +01:00
parent d55db7cd58
commit 5e0b802343
3 changed files with 87 additions and 51 deletions
+1
View File
@@ -104,6 +104,7 @@ export function App() {
recordingTime={recordingTime}
isTalking={isTalking}
gain={gain}
onGainChange={setGain}
onRecord={handleRecord}
onSnapshot={handleSnapshot}
onTalk={handleTalk}
+52 -47
View File
@@ -1,77 +1,82 @@
interface ControlsProps {
isRecording: boolean
recordingTime: number
isTalking: boolean
gain: number
onRecord: () => void
onSnapshot: () => void
onTalk: () => void
disabled?: boolean
isRecording: boolean;
recordingTime: number;
isTalking: boolean;
gain: number;
onGainChange: (gain: number) => void;
onRecord: () => void;
onSnapshot: () => void;
onTalk: () => void;
disabled?: boolean;
}
export function Controls({ isRecording, recordingTime, isTalking, gain, onRecord, onSnapshot, onTalk, disabled }: ControlsProps) {
export function Controls({
isRecording,
recordingTime,
isTalking,
gain,
onGainChange,
onRecord,
onSnapshot,
onTalk,
disabled,
}: ControlsProps) {
const formatTime = (seconds: number) => {
const m = Math.floor(seconds / 60).toString().padStart(2, '0')
const s = (seconds % 60).toString().padStart(2, '0')
return `${m}:${s}`
}
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${mins.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
};
return (
<div className="flex flex-col sm:flex-row items-center justify-center gap-4 p-4 bg-gray-800 rounded-lg border border-gray-700">
<div className="flex items-center gap-4">
<div className="glass-card p-4 rounded-2xl flex flex-col md:flex-row items-center justify-between gap-4">
<div className="flex items-center gap-3">
<button
onClick={onRecord}
disabled={disabled}
className={`w-16 h-16 rounded-full flex items-center justify-center font-bold text-xl transition-colors ${
className={`px-4 py-2 rounded-xl text-sm font-medium transition-all ${
isRecording
? 'bg-red-600 text-white animate-pulse ring-4 ring-red-500/30'
: 'bg-gray-700 text-white hover:bg-gray-600'
} ${disabled ? 'opacity-50 cursor-not-allowed' : ''}`}
aria-label={isRecording ? 'Arrêter enregistrement' : 'Démarrer enregistrement'}
? "bg-red-500/20 text-red-400 border border-red-500/30"
: "glass-button text-zinc-200"
}`}
>
{isRecording ? '■' : '●'}
{isRecording
? `Arrêter (${formatTime(recordingTime)})`
: "Enregistrer"}
</button>
{isRecording && <span className="font-mono text-lg text-red-300">{formatTime(recordingTime)}</span>}
</div>
<div className="flex items-center gap-4">
<button
onClick={onSnapshot}
disabled={disabled}
className={`w-16 h-16 rounded-full flex items-center justify-center font-bold text-xl transition-colors bg-gray-700 text-white hover:bg-gray-600 ${disabled ? 'opacity-50 cursor-not-allowed' : ''}`}
aria-label="Capture instantanée"
className="px-4 py-2 rounded-xl text-sm font-medium glass-button text-zinc-200 hover:text-white"
>
📷
Capture
</button>
</div>
<div className="flex items-center gap-4">
<button
onClick={onTalk}
disabled={disabled}
className={`w-16 h-16 rounded-full flex items-center justify-center font-bold text-xl transition-colors ${
isTalking
? 'bg-green-600 text-white ring-4 ring-green-500/30'
: 'bg-gray-700 text-white hover:bg-gray-600'
} ${disabled ? 'opacity-50 cursor-not-allowed' : ''}`}
aria-label={isTalking ? 'Couper micro' : 'Activer micro'}
>
{isTalking ? '🎤' : '🎤'}
</button>
<div className="w-32">
<label className="block text-xs text-gray-400 mb-1">Gain micro</label>
<div className="flex items-center gap-2">
<span className="text-xs text-zinc-400">Gain micro</span>
<input
type="range"
min="0.2"
max="5"
step="0.1"
value={gain}
onChange={(e) => {}}
className="w-full"
disabled={disabled}
onChange={(e) => onGainChange(Number(e.target.value))}
className="w-28 accent-blue-500"
/>
</div>
<button
onClick={onTalk}
disabled={disabled}
className={`px-4 py-2 rounded-xl text-sm font-medium transition-all ${
isTalking
? "bg-blue-500/20 text-blue-400 border border-blue-500/30"
: "glass-button text-zinc-200"
}`}
>
{isTalking ? "Parler (Actif)" : "Parler"}
</button>
</div>
</div>
)
}
);
}
@@ -17,11 +17,11 @@ export function MediaGallery() {
const fetchMedia = async () => {
try {
const res = await fetch("/api/media");
if (!res.ok) throw new Error("Erreur chargement médias");
if (!res.ok) throw new Error();
const data = await res.json();
setMedia(data);
} catch (e) {
setError("Impossible de charger les médias");
setError("Erreur chargement médias");
}
};
@@ -32,16 +32,46 @@ export function MediaGallery() {
const handleDelete = async (filename: string) => {
try {
const res = await fetch(`/api/media/${filename}`, { method: "DELETE" });
if (!res.ok) throw new Error("Suppression échouée");
if (!res.ok) throw new Error();
setMedia((prev) => prev.filter((m) => m.filename !== filename));
setItemToDelete(null);
} catch (e) {
setError("Erreur lors de la suppression");
setError("Erreur suppression");
}
};
const handleExportAll = async () => {
try {
const res = await fetch("/api/media/export", { method: "POST" });
if (!res.ok) throw new Error();
const blob = await res.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "kai-sa-cam-media.zip";
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
fetchMedia();
} catch (e) {
setError("Erreur export");
}
};
return (
<div className="flex-1 flex flex-col p-4 gap-4 overflow-y-auto">
<div className="flex justify-between items-center">
<span className="text-sm text-zinc-400">{media.length} fichiers</span>
{media.length > 0 && (
<button
onClick={handleExportAll}
className="px-4 py-2 text-xs glass-button rounded-xl text-zinc-200 hover:text-white"
>
Tout télécharger et vider
</button>
)}
</div>
{error && <div className="text-red-400 text-sm text-center">{error}</div>}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
{media.map((item) => (