2026-03-23 01:46:05 +08:00
|
|
|
import { Download } from "lucide-react";
|
2026-03-25 09:27:12 +08:00
|
|
|
import { useState } from "react";
|
|
|
|
|
import { ProgressCard } from "@/components/common/progress-card";
|
|
|
|
|
import { useToolProcessor } from "@/hooks/use-tool-processor";
|
|
|
|
|
import { useFileStore } from "@/stores/file-store";
|
2026-03-22 04:31:49 +08:00
|
|
|
|
|
|
|
|
export function BlurFacesSettings() {
|
|
|
|
|
const { files } = useFileStore();
|
2026-03-23 01:46:05 +08:00
|
|
|
const { processFiles, processing, error, downloadUrl, originalSize, processedSize, progress } =
|
2026-03-22 04:31:49 +08:00
|
|
|
useToolProcessor("blur-faces");
|
|
|
|
|
|
|
|
|
|
const [blurRadius, setBlurRadius] = useState(30);
|
|
|
|
|
const [sensitivity, setSensitivity] = useState(50);
|
|
|
|
|
|
|
|
|
|
const handleProcess = () => {
|
|
|
|
|
processFiles(files, {
|
|
|
|
|
blurRadius,
|
|
|
|
|
sensitivity: sensitivity / 100,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const hasFile = files.length > 0;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
{/* Blur radius */}
|
|
|
|
|
<div>
|
|
|
|
|
<div className="flex justify-between items-center">
|
2026-03-26 01:10:13 +08:00
|
|
|
<label htmlFor="blur-faces-blur-radius" className="text-xs text-muted-foreground">
|
|
|
|
|
Blur Radius
|
|
|
|
|
</label>
|
2026-03-22 04:31:49 +08:00
|
|
|
<span className="text-xs font-mono text-foreground">{blurRadius}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<input
|
2026-03-26 01:10:13 +08:00
|
|
|
id="blur-faces-blur-radius"
|
2026-03-22 04:31:49 +08:00
|
|
|
type="range"
|
|
|
|
|
min={5}
|
|
|
|
|
max={80}
|
|
|
|
|
value={blurRadius}
|
|
|
|
|
onChange={(e) => setBlurRadius(Number(e.target.value))}
|
|
|
|
|
className="w-full mt-1"
|
|
|
|
|
/>
|
|
|
|
|
<div className="flex justify-between text-[10px] text-muted-foreground mt-0.5">
|
|
|
|
|
<span>Light</span>
|
|
|
|
|
<span>Heavy</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Sensitivity */}
|
|
|
|
|
<div>
|
|
|
|
|
<div className="flex justify-between items-center">
|
2026-03-26 01:10:13 +08:00
|
|
|
<label htmlFor="blur-faces-sensitivity" className="text-xs text-muted-foreground">
|
|
|
|
|
Detection Sensitivity
|
|
|
|
|
</label>
|
2026-03-22 04:31:49 +08:00
|
|
|
<span className="text-xs font-mono text-foreground">{sensitivity}%</span>
|
|
|
|
|
</div>
|
|
|
|
|
<input
|
2026-03-26 01:10:13 +08:00
|
|
|
id="blur-faces-sensitivity"
|
2026-03-22 04:31:49 +08:00
|
|
|
type="range"
|
|
|
|
|
min={10}
|
|
|
|
|
max={90}
|
|
|
|
|
value={sensitivity}
|
|
|
|
|
onChange={(e) => setSensitivity(Number(e.target.value))}
|
|
|
|
|
className="w-full mt-1"
|
|
|
|
|
/>
|
|
|
|
|
<div className="flex justify-between text-[10px] text-muted-foreground mt-0.5">
|
|
|
|
|
<span>More faces</span>
|
|
|
|
|
<span>Fewer false positives</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Error */}
|
|
|
|
|
{error && <p className="text-xs text-red-500">{error}</p>}
|
|
|
|
|
|
|
|
|
|
{/* Size info */}
|
|
|
|
|
{originalSize != null && processedSize != null && (
|
|
|
|
|
<div className="text-xs text-muted-foreground space-y-0.5">
|
|
|
|
|
<p>Original: {(originalSize / 1024).toFixed(1)} KB</p>
|
|
|
|
|
<p>Processed: {(processedSize / 1024).toFixed(1)} KB</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* Process button */}
|
2026-03-23 01:46:05 +08:00
|
|
|
{processing ? (
|
|
|
|
|
<ProgressCard
|
|
|
|
|
active={processing}
|
|
|
|
|
phase={progress.phase === "idle" ? "uploading" : progress.phase}
|
|
|
|
|
label="Blurring faces"
|
|
|
|
|
percent={progress.percent}
|
|
|
|
|
elapsed={progress.elapsed}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<button
|
2026-03-26 01:10:13 +08:00
|
|
|
type="button"
|
2026-03-28 11:19:09 +08:00
|
|
|
data-testid="blur-faces-submit"
|
2026-03-23 01:46:05 +08:00
|
|
|
onClick={handleProcess}
|
|
|
|
|
disabled={!hasFile || processing}
|
|
|
|
|
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
|
|
|
|
|
>
|
|
|
|
|
Blur Faces
|
|
|
|
|
</button>
|
2026-03-22 19:28:57 +08:00
|
|
|
)}
|
|
|
|
|
|
2026-03-22 04:31:49 +08:00
|
|
|
{/* Download */}
|
|
|
|
|
{downloadUrl && (
|
|
|
|
|
<a
|
|
|
|
|
href={downloadUrl}
|
|
|
|
|
download
|
2026-03-28 11:19:09 +08:00
|
|
|
data-testid="blur-faces-download"
|
2026-03-22 04:31:49 +08:00
|
|
|
className="w-full py-2.5 rounded-lg border border-primary text-primary font-medium flex items-center justify-center gap-2 hover:bg-primary/5"
|
|
|
|
|
>
|
|
|
|
|
<Download className="h-4 w-4" />
|
|
|
|
|
Download
|
|
|
|
|
</a>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|