imports :)
This commit is contained in:
444
src/components/ImporterView.tsx
Normal file
444
src/components/ImporterView.tsx
Normal file
@@ -0,0 +1,444 @@
|
||||
import { useState, useRef, useEffect } from 'react';
|
||||
import { ArrowLeft, Download, Settings, RefreshCw, CheckCircle, XCircle, AlertCircle, Users, Film, Loader2 } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { importFromXBVR, XBVRConfig, ImportProgress } from '@/lib/xbvrImporter';
|
||||
import { importFromStashAPP, StashAPPConfig, updateActorsFromStashAPP } from '@/lib/stashappImporter';
|
||||
|
||||
export default function ImporterView({ onBack }: { onBack: () => void }) {
|
||||
const [xbvrConfig, setXbvrConfig] = useState<XBVRConfig>({ url: 'http://192.168.1.102:4080' });
|
||||
const [stashappConfig, setStashappConfig] = useState<StashAPPConfig>({ url: 'http://192.168.1.102:10001' });
|
||||
const [progress, setProgress] = useState<ImportProgress>({
|
||||
current: 0,
|
||||
total: 0,
|
||||
stage: 'idle',
|
||||
message: '',
|
||||
videosImported: 0,
|
||||
actorsImported: 0,
|
||||
errors: []
|
||||
});
|
||||
const [importLog, setImportLog] = useState<string[]>([]);
|
||||
const logContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// Auto-scroll to bottom when log updates
|
||||
useEffect(() => {
|
||||
if (logContainerRef.current) {
|
||||
logContainerRef.current.scrollTop = logContainerRef.current.scrollHeight;
|
||||
}
|
||||
}, [importLog]);
|
||||
|
||||
const addLog = (message: string) => {
|
||||
const timestamp = new Date().toLocaleTimeString();
|
||||
setImportLog(prev => [...prev, `[${timestamp}] ${message}`]);
|
||||
};
|
||||
|
||||
const handleXBVRImport = async () => {
|
||||
setProgress({
|
||||
current: 0,
|
||||
total: 0,
|
||||
stage: 'fetching',
|
||||
message: 'Connecting to DeoVR API...',
|
||||
videosImported: 0,
|
||||
actorsImported: 0,
|
||||
errors: []
|
||||
});
|
||||
setImportLog([]);
|
||||
|
||||
const result = await importFromXBVR(
|
||||
xbvrConfig,
|
||||
addLog,
|
||||
(progressUpdate) => {
|
||||
setProgress(prev => ({ ...prev, ...progressUpdate }));
|
||||
}
|
||||
);
|
||||
|
||||
setProgress(result);
|
||||
};
|
||||
|
||||
const handleStashAPPImport = async () => {
|
||||
setProgress({
|
||||
current: 0,
|
||||
total: 0,
|
||||
stage: 'fetching',
|
||||
message: 'Connecting to StashAPP...',
|
||||
videosImported: 0,
|
||||
actorsImported: 0,
|
||||
errors: []
|
||||
});
|
||||
setImportLog([]);
|
||||
|
||||
const result = await importFromStashAPP(
|
||||
stashappConfig,
|
||||
addLog,
|
||||
(progressUpdate) => {
|
||||
setProgress(prev => ({ ...prev, ...progressUpdate }));
|
||||
}
|
||||
);
|
||||
|
||||
setProgress(result);
|
||||
};
|
||||
|
||||
const handleStashAPPActorUpdate = async () => {
|
||||
setProgress({
|
||||
current: 0,
|
||||
total: 0,
|
||||
stage: 'fetching',
|
||||
message: 'Connecting to StashAPP...',
|
||||
videosImported: 0,
|
||||
actorsImported: 0,
|
||||
errors: []
|
||||
});
|
||||
setImportLog([]);
|
||||
|
||||
const result = await updateActorsFromStashAPP(
|
||||
stashappConfig,
|
||||
addLog,
|
||||
(progressUpdate) => {
|
||||
setProgress(prev => ({ ...prev, ...progressUpdate }));
|
||||
}
|
||||
);
|
||||
|
||||
setProgress(result);
|
||||
};
|
||||
|
||||
const resetImport = () => {
|
||||
setProgress({
|
||||
current: 0,
|
||||
total: 0,
|
||||
stage: 'idle',
|
||||
message: '',
|
||||
videosImported: 0,
|
||||
actorsImported: 0,
|
||||
errors: []
|
||||
});
|
||||
setImportLog([]);
|
||||
};
|
||||
|
||||
const getProgressPercentage = () => {
|
||||
if (progress.total === 0) return 0;
|
||||
return Math.round((progress.current / progress.total) * 100);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="pt-24 pb-12 px-6 max-w-[1600px] mx-auto">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between mb-8">
|
||||
<div className="flex items-center gap-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={onBack}
|
||||
className="text-zinc-600 hover:text-[#6d28d9]"
|
||||
>
|
||||
<ArrowLeft size={20} />
|
||||
</Button>
|
||||
<div>
|
||||
<h1 className="text-2xl font-black text-zinc-900">Media Importers</h1>
|
||||
<p className="text-sm text-zinc-500 font-medium">Import media from external platforms</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Importer Cards */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8">
|
||||
{/* XBVR Importer Card */}
|
||||
<div className="bg-white border border-zinc-200 rounded-xl p-6 hover:border-[#6d28d9]/50 transition-colors">
|
||||
<div className="flex items-start justify-between mb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-12 h-12 bg-purple-100 rounded-lg flex items-center justify-center">
|
||||
<Film className="text-purple-600" size={24} />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-bold text-zinc-900">XBVR</h3>
|
||||
<p className="text-xs text-zinc-500 font-medium">Adult Video Manager</p>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="h-8 w-8 border-zinc-200"
|
||||
onClick={() => {}}
|
||||
>
|
||||
<Settings size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-sm text-zinc-600 mb-4">
|
||||
Import adult videos and actors from your XBVR database.
|
||||
</p>
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<label className="text-xs font-bold text-zinc-500 mb-1 block">XBVR URL</label>
|
||||
<input
|
||||
type="text"
|
||||
value={xbvrConfig.url}
|
||||
onChange={(e) => setXbvrConfig({ ...xbvrConfig, url: e.target.value })}
|
||||
disabled={progress.stage !== 'idle'}
|
||||
className="w-full px-3 py-2 text-sm border border-zinc-200 rounded-lg focus:ring-2 focus:ring-[#6d28d9] focus:border-transparent outline-none disabled:bg-zinc-100 disabled:cursor-not-allowed"
|
||||
placeholder="http://192.168.1.102:10001"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleXBVRImport}
|
||||
disabled={progress.stage !== 'idle' || !xbvrConfig.url}
|
||||
className="w-full bg-[#6d28d9] hover:bg-[#5b21b6] text-white font-bold"
|
||||
>
|
||||
{progress.stage === 'fetching' || progress.stage === 'importing' ? (
|
||||
<>
|
||||
<Loader2 size={16} className="mr-2 animate-spin" />
|
||||
Importing...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download size={16} className="mr-2" />
|
||||
Import from XBVR
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* StashAPP Importer Card */}
|
||||
<div className="bg-white border border-zinc-200 rounded-xl p-6 hover:border-[#6d28d9]/50 transition-colors">
|
||||
<div className="flex items-start justify-between mb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center">
|
||||
<Film className="text-blue-600" size={24} />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-bold text-zinc-900">StashAPP</h3>
|
||||
<p className="text-xs text-zinc-500 font-medium">Adult Content Manager</p>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="h-8 w-8 border-zinc-200"
|
||||
onClick={() => {}}
|
||||
>
|
||||
<Settings size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-sm text-zinc-600 mb-4">
|
||||
Import adult videos and performers from your StashAPP database.
|
||||
</p>
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<label className="text-xs font-bold text-zinc-500 mb-1 block">StashAPP URL</label>
|
||||
<input
|
||||
type="text"
|
||||
value={stashappConfig.url}
|
||||
onChange={(e) => setStashappConfig({ ...stashappConfig, url: e.target.value })}
|
||||
disabled={progress.stage !== 'idle'}
|
||||
className="w-full px-3 py-2 text-sm border border-zinc-200 rounded-lg focus:ring-2 focus:ring-[#6d28d9] focus:border-transparent outline-none disabled:bg-zinc-100 disabled:cursor-not-allowed"
|
||||
placeholder="http://192.168.1.102:10001"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="text-xs font-bold text-zinc-500 mb-1 block">API Key (optional)</label>
|
||||
<input
|
||||
type="password"
|
||||
value={stashappConfig.apiKey || ''}
|
||||
onChange={(e) => setStashappConfig({ ...stashappConfig, apiKey: e.target.value })}
|
||||
disabled={progress.stage !== 'idle'}
|
||||
className="w-full px-3 py-2 text-sm border border-zinc-200 rounded-lg focus:ring-2 focus:ring-[#6d28d9] focus:border-transparent outline-none disabled:bg-zinc-100 disabled:cursor-not-allowed"
|
||||
placeholder="Enter API key if required"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleStashAPPImport}
|
||||
disabled={progress.stage !== 'idle' || !stashappConfig.url}
|
||||
className="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold"
|
||||
>
|
||||
{progress.stage === 'fetching' || progress.stage === 'importing' ? (
|
||||
<>
|
||||
<Loader2 size={16} className="mr-2 animate-spin" />
|
||||
Importing...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download size={16} className="mr-2" />
|
||||
Import from StashAPP
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* StashAPP Actor Updater Card */}
|
||||
<div className="bg-white border border-zinc-200 rounded-xl p-6 hover:border-[#6d28d9]/50 transition-colors">
|
||||
<div className="flex items-start justify-between mb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-12 h-12 bg-green-100 rounded-lg flex items-center justify-center">
|
||||
<Users className="text-green-600" size={24} />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="font-bold text-zinc-900">StashAPP Actor Updater</h3>
|
||||
<p className="text-xs text-zinc-500 font-medium">Update existing actors</p>
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="h-8 w-8 border-zinc-200"
|
||||
onClick={() => {}}
|
||||
>
|
||||
<Settings size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-sm text-zinc-600 mb-4">
|
||||
Update existing actors with fresh data from StashAPP and create missing ones.
|
||||
</p>
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<label className="text-xs font-bold text-zinc-500 mb-1 block">API Key (optional)</label>
|
||||
<input
|
||||
type="password"
|
||||
value={stashappConfig.apiKey || ''}
|
||||
onChange={(e) => setStashappConfig({ ...stashappConfig, apiKey: e.target.value })}
|
||||
disabled={progress.stage !== 'idle'}
|
||||
className="w-full px-3 py-2 text-sm border border-zinc-200 rounded-lg focus:ring-2 focus:ring-[#6d28d9] focus:border-transparent outline-none disabled:bg-zinc-100 disabled:cursor-not-allowed"
|
||||
placeholder="Enter API key if required"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleStashAPPActorUpdate}
|
||||
disabled={progress.stage !== 'idle' || !stashappConfig.url}
|
||||
className="w-full bg-green-600 hover:bg-green-700 text-white font-bold"
|
||||
>
|
||||
{progress.stage === 'fetching' || progress.stage === 'importing' ? (
|
||||
<>
|
||||
<Loader2 size={16} className="mr-2 animate-spin" />
|
||||
Updating...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<RefreshCw size={16} className="mr-2" />
|
||||
Update Actors
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Placeholder for future importers */}
|
||||
<div className="bg-zinc-50 border border-zinc-200 border-dashed rounded-xl p-6 flex flex-col items-center justify-center text-zinc-400">
|
||||
<Download size={32} className="mb-2" />
|
||||
<p className="text-sm font-medium">More importers coming soon</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Progress Section */}
|
||||
{progress.stage !== 'idle' && (
|
||||
<div className="bg-white border border-zinc-200 rounded-xl p-6">
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
{progress.stage === 'complete' ? (
|
||||
<div className="w-10 h-10 bg-green-100 rounded-full flex items-center justify-center">
|
||||
<CheckCircle className="text-green-600" size={20} />
|
||||
</div>
|
||||
) : progress.stage === 'error' ? (
|
||||
<div className="w-10 h-10 bg-red-100 rounded-full flex items-center justify-center">
|
||||
<XCircle className="text-red-600" size={20} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center">
|
||||
<Loader2 className="text-purple-600 animate-spin" size={20} />
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<h3 className="font-bold text-zinc-900">{progress.message}</h3>
|
||||
<p className="text-xs text-zinc-500 font-medium">
|
||||
{progress.stage === 'fetching' && 'Connecting to external service...'}
|
||||
{progress.stage === 'importing' && `Processing items... ${getProgressPercentage()}%`}
|
||||
{progress.stage === 'complete' && 'Import finished'}
|
||||
{progress.stage === 'error' && 'An error occurred'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
{progress.stage === 'complete' || progress.stage === 'error' ? (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={resetImport}
|
||||
className="gap-2 font-bold border-zinc-200"
|
||||
>
|
||||
<RefreshCw size={16} />
|
||||
Reset
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{/* Progress Bar */}
|
||||
{progress.stage === 'fetching' || progress.stage === 'importing' ? (
|
||||
<div className="mb-6">
|
||||
<div className="h-2 bg-zinc-100 rounded-full overflow-hidden">
|
||||
<div
|
||||
className={cn(
|
||||
"h-full transition-all duration-300 ease-out",
|
||||
progress.stage === 'error' ? "bg-red-500" : "bg-[#6d28d9]"
|
||||
)}
|
||||
style={{ width: `${getProgressPercentage()}%` }}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-between mt-2 text-xs text-zinc-500 font-medium">
|
||||
<span>{progress.current} / {progress.total} items</span>
|
||||
<span>{getProgressPercentage()}%</span>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Stats */}
|
||||
<div className="grid grid-cols-3 gap-4 mb-6">
|
||||
<div className="bg-zinc-50 rounded-lg p-4">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<Film size={16} className="text-zinc-400" />
|
||||
<span className="text-xs font-bold text-zinc-500">Videos</span>
|
||||
</div>
|
||||
<p className="text-2xl font-black text-zinc-900">{progress.videosImported}</p>
|
||||
</div>
|
||||
<div className="bg-zinc-50 rounded-lg p-4">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<Users size={16} className="text-zinc-400" />
|
||||
<span className="text-xs font-bold text-zinc-500">Actors</span>
|
||||
</div>
|
||||
<p className="text-2xl font-black text-zinc-900">{progress.actorsImported}</p>
|
||||
</div>
|
||||
<div className="bg-zinc-50 rounded-lg p-4">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<AlertCircle size={16} className="text-zinc-400" />
|
||||
<span className="text-xs font-bold text-zinc-500">Errors</span>
|
||||
</div>
|
||||
<p className="text-2xl font-black text-zinc-900">{progress.errors.length}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Log */}
|
||||
{importLog.length > 0 && (
|
||||
<div
|
||||
ref={logContainerRef}
|
||||
className="bg-zinc-900 rounded-lg p-4 max-h-64 overflow-y-auto"
|
||||
>
|
||||
<pre className="text-xs text-green-400 font-mono whitespace-pre-wrap">
|
||||
{importLog.join('\n')}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Errors */}
|
||||
{progress.errors.length > 0 && (
|
||||
<div className="mt-4">
|
||||
<h4 className="text-sm font-bold text-red-600 mb-2">Errors</h4>
|
||||
<div className="bg-red-50 border border-red-200 rounded-lg p-3 max-h-32 overflow-y-auto">
|
||||
{progress.errors.map((error, index) => (
|
||||
<p key={index} className="text-xs text-red-700 font-medium mb-1">
|
||||
• {error}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user