mirror of
https://github.com/Alvin-Zilverstand/Twitter-X-Media-Batch-Downloader.git
synced 2026-11-27 16:47:56 +01:00
v4.1
This commit is contained in:
1 parent
2d913d987f
commit
aa87cce538
25 files changed
+3835
-1574
No files matched your search
+1133
-50
File diff suppressed because it is too large.
Load diff
@@ -28,16 +28,22 @@ import {
|
||||
} from "@/components/ui/tooltip";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Trash2, Eye, FileInput, FileOutput, Pencil, Tag, Shuffle, X, Download, StopCircle, Globe, Lock, Bookmark, Heart, Image, Images, Video, Film, FileText, Filter, AlertCircle } from "lucide-react";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Trash2, FileInput, FileOutput, Pencil, Tag, Shuffle, X, Download, StopCircle, Globe, Lock, Bookmark, Heart, Image, Images, Video, Film, FileText, Filter, AlertCircle, MoreVertical, FileBraces, CloudBackup } from "lucide-react";
|
||||
import { toastWithSound as toast } from "@/lib/toast-with-sound";
|
||||
import { getSettings } from "@/lib/settings";
|
||||
import {
|
||||
GetAllAccountsFromDB,
|
||||
GetAccountFromDB,
|
||||
DeleteAccountFromDB,
|
||||
ClearAllAccountsFromDB,
|
||||
SaveAccountToDB,
|
||||
ExportAccountJSON,
|
||||
ExportAccountsTXT,
|
||||
UpdateAccountGroup,
|
||||
GetAllGroups,
|
||||
DownloadMediaWithMetadata,
|
||||
@@ -96,11 +102,12 @@ interface GroupInfo {
|
||||
interface DatabaseViewProps {
|
||||
onBack: () => void;
|
||||
onLoadAccount: (responseJSON: string, username: string) => void;
|
||||
onUpdateSelected?: (usernames: string[]) => void;
|
||||
}
|
||||
|
||||
const ITEMS_PER_PAGE = 10;
|
||||
|
||||
export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewProps) {
|
||||
const [accounts, setAccounts] = useState<AccountListItem[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [selectedIds, setSelectedIds] = useState<Set<number>>(new Set());
|
||||
@@ -230,25 +237,59 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
}
|
||||
|
||||
const settings = getSettings();
|
||||
// Check if it's bookmarks or likes by checking account_info.nick or username (for backward compatibility)
|
||||
const isBookmarks = data.account_info?.nick === "My Bookmarks" || username === "bookmarks";
|
||||
const isLikes = data.account_info?.nick === "My Likes" || username === "likes";
|
||||
let outputDir = settings.downloadPath;
|
||||
if (isBookmarks) {
|
||||
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
|
||||
outputDir = `${settings.downloadPath}${separator}My Bookmarks`;
|
||||
} else if (isLikes) {
|
||||
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
|
||||
outputDir = `${settings.downloadPath}${separator}My Likes`;
|
||||
}
|
||||
// Use actual username from account_info if available, otherwise use stored username
|
||||
const actualUsername = data.account_info?.name || username;
|
||||
|
||||
setIsDownloading(true);
|
||||
setDownloadingAccountId(id);
|
||||
setDownloadProgress({ current: 0, total: timeline.length, percent: 0 });
|
||||
|
||||
const request = new main.DownloadMediaWithMetadataRequest({
|
||||
items: timeline.map((item: { url: string; date: string; tweet_id: string; type: string }) => new main.MediaItemRequest({
|
||||
items: timeline.map((item: { url: string; date: string; tweet_id: string; type: string; original_filename?: string; author_username?: string }) => new main.MediaItemRequest({
|
||||
url: item.url,
|
||||
date: item.date,
|
||||
tweet_id: item.tweet_id,
|
||||
type: item.type,
|
||||
original_filename: item.original_filename || "",
|
||||
author_username: item.author_username || "",
|
||||
})),
|
||||
output_dir: settings.downloadPath,
|
||||
username: username,
|
||||
output_dir: outputDir,
|
||||
username: actualUsername,
|
||||
proxy: settings.proxy || "",
|
||||
});
|
||||
|
||||
const response = await DownloadMediaWithMetadata(request);
|
||||
|
||||
if (response.success) {
|
||||
toast.success(`Downloaded ${response.downloaded} files for @${username}`);
|
||||
const parts: string[] = [];
|
||||
if (response.downloaded > 0) {
|
||||
parts.push(`${response.downloaded} file${response.downloaded !== 1 ? 's' : ''} downloaded`);
|
||||
}
|
||||
if (response.skipped > 0) {
|
||||
parts.push(`${response.skipped} file${response.skipped !== 1 ? 's' : ''} already exist${response.skipped !== 1 ? '' : 's'}`);
|
||||
}
|
||||
if (response.failed > 0) {
|
||||
parts.push(`${response.failed} failed`);
|
||||
}
|
||||
const message = parts.length > 0 ? `${parts.join(', ')} for @${username}` : `Download completed for @${username}`;
|
||||
|
||||
// Use info toast if only skipped files (no downloaded, no failed)
|
||||
if (response.downloaded === 0 && response.failed === 0 && response.skipped > 0) {
|
||||
toast.info(message);
|
||||
} else {
|
||||
toast.success(message);
|
||||
}
|
||||
} else {
|
||||
toast.error(response.message || "Download failed");
|
||||
}
|
||||
@@ -287,6 +328,7 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
|
||||
const settings = getSettings();
|
||||
let totalDownloaded = 0;
|
||||
let totalSkipped = 0;
|
||||
let downloadedAccounts = 0;
|
||||
|
||||
for (let i = 0; i < idsToDownload.length; i++) {
|
||||
@@ -318,20 +360,38 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
|
||||
setDownloadProgress({ current: 0, total: timeline.length, percent: 0 });
|
||||
|
||||
// Check if it's bookmarks or likes by checking account_info.nick or username (for backward compatibility)
|
||||
const isBookmarks = data.account_info?.nick === "My Bookmarks" || account.username === "bookmarks";
|
||||
const isLikes = data.account_info?.nick === "My Likes" || account.username === "likes";
|
||||
let outputDir = settings.downloadPath;
|
||||
if (isBookmarks) {
|
||||
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
|
||||
outputDir = `${settings.downloadPath}${separator}My Bookmarks`;
|
||||
} else if (isLikes) {
|
||||
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
|
||||
outputDir = `${settings.downloadPath}${separator}My Likes`;
|
||||
}
|
||||
// Use actual username from account_info if available, otherwise use stored username
|
||||
const actualUsername = data.account_info?.name || account.username;
|
||||
|
||||
const request = new main.DownloadMediaWithMetadataRequest({
|
||||
items: timeline.map((item: { url: string; date: string; tweet_id: string; type: string }) => new main.MediaItemRequest({
|
||||
items: timeline.map((item: { url: string; date: string; tweet_id: string; type: string; author_username?: string; original_filename?: string }) => new main.MediaItemRequest({
|
||||
url: item.url,
|
||||
date: item.date,
|
||||
tweet_id: item.tweet_id,
|
||||
type: item.type,
|
||||
author_username: item.author_username || "",
|
||||
original_filename: item.original_filename || "",
|
||||
})),
|
||||
output_dir: settings.downloadPath,
|
||||
username: account.username,
|
||||
output_dir: outputDir,
|
||||
username: actualUsername,
|
||||
proxy: settings.proxy || "",
|
||||
});
|
||||
|
||||
const response = await DownloadMediaWithMetadata(request);
|
||||
if (response.success) {
|
||||
totalDownloaded += response.downloaded;
|
||||
totalSkipped += response.skipped || 0;
|
||||
downloadedAccounts++;
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -345,8 +405,22 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
setBulkDownloadCurrent(0);
|
||||
setBulkDownloadTotal(0);
|
||||
|
||||
if (totalDownloaded > 0 && !stopBulkDownloadRef.current) {
|
||||
toast.success(`Downloaded ${totalDownloaded} files from ${downloadedAccounts} accounts`);
|
||||
if ((totalDownloaded > 0 || totalSkipped > 0) && !stopBulkDownloadRef.current) {
|
||||
const parts: string[] = [];
|
||||
if (totalDownloaded > 0) {
|
||||
parts.push(`${totalDownloaded} file${totalDownloaded !== 1 ? 's' : ''} downloaded`);
|
||||
}
|
||||
if (totalSkipped > 0) {
|
||||
parts.push(`${totalSkipped} file${totalSkipped !== 1 ? 's' : ''} already exist${totalSkipped !== 1 ? '' : 's'}`);
|
||||
}
|
||||
const message = parts.length > 0 ? `${parts.join(', ')} from ${downloadedAccounts} account${downloadedAccounts !== 1 ? 's' : ''}` : `Download completed from ${downloadedAccounts} account${downloadedAccounts !== 1 ? 's' : ''}`;
|
||||
|
||||
// Use info toast if only skipped files (no downloaded)
|
||||
if (totalDownloaded === 0 && totalSkipped > 0) {
|
||||
toast.info(message);
|
||||
} else {
|
||||
toast.success(message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -375,7 +449,7 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const handleExport = async () => {
|
||||
const handleExportJSON = async () => {
|
||||
const idsToExport = selectedIds.size > 0 ? Array.from(selectedIds) : accounts.map((a) => a.id);
|
||||
|
||||
if (idsToExport.length === 0) {
|
||||
@@ -398,6 +472,34 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const handleExportTXT = async () => {
|
||||
const idsToExport = selectedIds.size > 0 ? Array.from(selectedIds) : accounts.map((a) => a.id);
|
||||
|
||||
if (idsToExport.length === 0) {
|
||||
toast.error("No accounts to export");
|
||||
return;
|
||||
}
|
||||
|
||||
const settings = getSettings();
|
||||
const outputDir = settings.downloadPath || "";
|
||||
|
||||
try {
|
||||
await ExportAccountsTXT(idsToExport, outputDir);
|
||||
toast.success(`Exported ${idsToExport.length} account(s) to ${outputDir}\\twitterxmediabatchdownloader_backups\\twitterxmediabatchdownloader_multiple.txt`);
|
||||
} catch (error) {
|
||||
toast.error("Failed to export");
|
||||
}
|
||||
};
|
||||
|
||||
// Check if any selected accounts are private (bookmarks/likes)
|
||||
const hasPrivateAccountSelected = () => {
|
||||
if (selectedIds.size === 0) return false;
|
||||
return Array.from(selectedIds).some((id) => {
|
||||
const account = accounts.find((a) => a.id === id);
|
||||
return account && isPrivateAccount(account.username);
|
||||
});
|
||||
};
|
||||
|
||||
const handleImport = () => {
|
||||
const input = document.createElement("input");
|
||||
input.type = "file";
|
||||
@@ -522,29 +624,29 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
<div className="flex items-center gap-3">
|
||||
<h2 className="text-2xl font-bold">Saved Accounts</h2>
|
||||
{/* Public/Private Toggle */}
|
||||
<div className="flex gap-1 p-1 bg-muted rounded-lg">
|
||||
<div className="flex gap-0.5 p-0.5 bg-muted rounded-lg">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setViewMode("public")}
|
||||
className={`flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium transition-all ${
|
||||
className={`flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all ${
|
||||
viewMode === "public"
|
||||
? "bg-background text-foreground shadow-sm"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
>
|
||||
<Globe className="h-4 w-4" />
|
||||
<Globe className="h-3 w-3" />
|
||||
Public ({publicAccounts.length})
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setViewMode("private")}
|
||||
className={`flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium transition-all ${
|
||||
className={`flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all ${
|
||||
viewMode === "private"
|
||||
? "bg-background text-foreground shadow-sm"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
}`}
|
||||
>
|
||||
<Lock className="h-4 w-4" />
|
||||
<Lock className="h-3 w-3" />
|
||||
Private ({privateAccounts.length})
|
||||
</button>
|
||||
</div>
|
||||
@@ -558,13 +660,62 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Import JSON</TooltipContent>
|
||||
</Tooltip>
|
||||
<DropdownMenu>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="icon" disabled={selectedIds.size === 0}>
|
||||
<FileOutput className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Export Selected ({selectedIds.size})</TooltipContent>
|
||||
</Tooltip>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={handleExportJSON}>
|
||||
<FileBraces className="h-4 w-4 mr-2" />
|
||||
Export JSON
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={handleExportTXT} disabled={hasPrivateAccountSelected()}>
|
||||
<FileText className="h-4 w-4 mr-2" />
|
||||
Export TXT
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button variant="outline" size="icon" onClick={handleExport} disabled={selectedIds.size === 0}>
|
||||
<FileOutput className="h-4 w-4" />
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => {
|
||||
const idsToUpdate = selectedIds.size > 0 ? Array.from(selectedIds) : accounts.map((a) => a.id);
|
||||
if (idsToUpdate.length === 0) {
|
||||
toast.error("No accounts selected");
|
||||
return;
|
||||
}
|
||||
const usernames = idsToUpdate
|
||||
.map((id) => {
|
||||
const account = accounts.find((a) => a.id === id);
|
||||
return account?.username;
|
||||
})
|
||||
.filter((username): username is string => !!username);
|
||||
|
||||
if (usernames.length === 0) {
|
||||
toast.error("No valid usernames found");
|
||||
return;
|
||||
}
|
||||
|
||||
if (onUpdateSelected) {
|
||||
onUpdateSelected(usernames);
|
||||
toast.success(`Added ${usernames.length} account(s) to multiple fetch`);
|
||||
}
|
||||
}}
|
||||
disabled={selectedIds.size === 0 || hasPrivateAccountSelected()}
|
||||
>
|
||||
<CloudBackup className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Export Selected</TooltipContent>
|
||||
<TooltipContent>Update Selected ({selectedIds.size})</TooltipContent>
|
||||
</Tooltip>
|
||||
{isBulkDownloading ? (
|
||||
<Tooltip>
|
||||
@@ -589,12 +740,12 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="destructive" size="icon" disabled={accounts.length === 0}>
|
||||
<Button variant="destructive" size="icon" disabled={baseAccounts.length === 0}>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Clear All</TooltipContent>
|
||||
<TooltipContent>Clear All {viewMode === "public" ? "Public" : "Private"}</TooltipContent>
|
||||
</Tooltip>
|
||||
<DialogContent className="[&>button]:hidden">
|
||||
<div className="absolute right-4 top-4">
|
||||
@@ -608,9 +759,9 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
</Button>
|
||||
</div>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Clear All Accounts?</DialogTitle>
|
||||
<DialogTitle>Clear All {viewMode === "public" ? "Public" : "Private"} Accounts?</DialogTitle>
|
||||
<DialogDescription>
|
||||
This will permanently delete all {formatNumberWithComma(accounts.length)} saved accounts. This action cannot be undone.
|
||||
This will permanently delete all {formatNumberWithComma(baseAccounts.length)} {viewMode === "public" ? "public" : "private"} saved accounts. This action cannot be undone.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
@@ -618,8 +769,12 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
variant="destructive"
|
||||
onClick={async () => {
|
||||
try {
|
||||
await ClearAllAccountsFromDB();
|
||||
toast.success("All accounts deleted");
|
||||
// Delete only accounts matching the current view mode
|
||||
const accountsToDelete = baseAccounts.map((acc) => acc.id);
|
||||
for (const id of accountsToDelete) {
|
||||
await DeleteAccountFromDB(id);
|
||||
}
|
||||
toast.success(`All ${viewMode === "public" ? "public" : "private"} accounts deleted`);
|
||||
setClearAllDialogOpen(false);
|
||||
loadAccounts();
|
||||
} catch (error) {
|
||||
@@ -627,7 +782,7 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
}
|
||||
}}
|
||||
>
|
||||
Delete All
|
||||
Delete All {viewMode === "public" ? "Public" : "Private"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
@@ -754,7 +909,10 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
{(currentPage - 1) * ITEMS_PER_PAGE + index + 1}
|
||||
</span>
|
||||
{isPrivateAccount(account.username) ? (
|
||||
<div className="w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center">
|
||||
<div
|
||||
className="w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center cursor-pointer hover:bg-primary/20 transition-colors"
|
||||
onClick={() => handleView(account.id, account.username)}
|
||||
>
|
||||
{account.username === "bookmarks" ? (
|
||||
<Bookmark className="h-6 w-6 text-primary" />
|
||||
) : (
|
||||
@@ -765,7 +923,8 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
<img
|
||||
src={account.profile_image}
|
||||
alt={account.name}
|
||||
className="w-12 h-12 rounded-full"
|
||||
className="w-12 h-12 rounded-full cursor-pointer hover:opacity-80 transition-opacity"
|
||||
onClick={() => handleView(account.id, account.username)}
|
||||
/>
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
@@ -809,57 +968,14 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground">@{account.username}</div>
|
||||
{!isPrivateAccount(account.username) && (
|
||||
<div className="text-sm text-muted-foreground">@{account.username}</div>
|
||||
)}
|
||||
<div className="text-sm text-muted-foreground">
|
||||
{account.last_fetched} {getRelativeTime(account.last_fetched)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => handleEditGroup(account)}
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Edit Group</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => handleView(account.id, account.username)}
|
||||
>
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>View</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={async () => {
|
||||
const settings = getSettings();
|
||||
const outputDir = settings.downloadPath || "";
|
||||
try {
|
||||
await ExportAccountJSON(account.id, outputDir);
|
||||
toast.success(`Exported @${account.username} to ${outputDir}\\twitterxmediabatchdownloader_backups`);
|
||||
} catch (error) {
|
||||
toast.error("Failed to export");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<FileOutput className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Export JSON</TooltipContent>
|
||||
</Tooltip>
|
||||
{downloadingAccountId === account.id ? (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
@@ -892,41 +1008,75 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
|
||||
<TooltipContent>Download All Media</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
<Dialog>
|
||||
<DropdownMenu>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="destructive" size="icon">
|
||||
<Trash2 className="h-4 w-4" />
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="icon">
|
||||
<MoreVertical className="h-4 w-4" />
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
</DropdownMenuTrigger>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Delete</TooltipContent>
|
||||
<TooltipContent>More Options</TooltipContent>
|
||||
</Tooltip>
|
||||
<DialogContent className="[&>button]:hidden">
|
||||
<div className="absolute right-4 top-4">
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={() => handleEditGroup(account)}>
|
||||
<Pencil className="h-4 w-4 mr-2" />
|
||||
Edit Group
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={async () => {
|
||||
const settings = getSettings();
|
||||
const outputDir = settings.downloadPath || "";
|
||||
try {
|
||||
await ExportAccountJSON(account.id, outputDir);
|
||||
toast.success(`Exported @${account.username} to ${outputDir}\\twitterxmediabatchdownloader_backups`);
|
||||
} catch (error) {
|
||||
toast.error("Failed to export");
|
||||
}
|
||||
}}
|
||||
>
|
||||
<FileOutput className="h-4 w-4 mr-2" />
|
||||
Export JSON
|
||||
</DropdownMenuItem>
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-6 w-6 opacity-70 hover:opacity-100">
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
<DropdownMenuItem
|
||||
onSelect={(e: Event) => {
|
||||
e.preventDefault();
|
||||
}}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DialogTrigger>
|
||||
</div>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Delete @{account.username}?</DialogTitle>
|
||||
<DialogDescription>
|
||||
This will permanently delete the saved data for this account.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={() => handleDelete(account.id, account.username)}
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<DialogContent className="[&>button]:hidden">
|
||||
<div className="absolute right-4 top-4">
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="h-6 w-6 opacity-70 hover:opacity-100">
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
</div>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Delete @{account.username}?</DialogTitle>
|
||||
<DialogDescription>
|
||||
This will permanently delete the saved data for this account.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={() => handleDelete(account.id, account.username)}
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
{/* Progress bar for this account */}
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { Bug, Trash2, X, Copy, Check } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { logger, type LogEntry } from "@/lib/logger";
|
||||
|
||||
const levelColors: Record<string, string> = {
|
||||
info: "text-blue-500",
|
||||
success: "text-green-500",
|
||||
warning: "text-yellow-500",
|
||||
error: "text-red-500",
|
||||
debug: "text-gray-500",
|
||||
};
|
||||
|
||||
function formatTime(date: Date): string {
|
||||
return date.toLocaleTimeString("en-US", {
|
||||
hour12: false,
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
});
|
||||
}
|
||||
|
||||
export function DebugLogger() {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [logs, setLogs] = useState<LogEntry[]>([]);
|
||||
const [copied, setCopied] = useState(false);
|
||||
const scrollRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = logger.subscribe(() => {
|
||||
setLogs(logger.getLogs());
|
||||
});
|
||||
setLogs(logger.getLogs());
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (scrollRef.current) {
|
||||
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
||||
}
|
||||
}, [logs]);
|
||||
|
||||
const handleClear = () => {
|
||||
logger.clear();
|
||||
};
|
||||
|
||||
const handleCopy = async () => {
|
||||
const logText = logs
|
||||
.map((log) => `[${formatTime(log.timestamp)}] [${log.level}] ${log.message}`)
|
||||
.join("\n");
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(logText);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 500);
|
||||
} catch (err) {
|
||||
console.error("Failed to copy logs:", err);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 opacity-50 hover:opacity-100"
|
||||
>
|
||||
<Bug className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-[600px] max-h-[80vh] p-6 [&>button]:hidden">
|
||||
<DialogTitle className="text-sm font-medium">Debug Logs</DialogTitle>
|
||||
<div className="absolute right-4 top-4 flex items-center gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 opacity-70 hover:opacity-100"
|
||||
onClick={handleCopy}
|
||||
disabled={logs.length === 0}
|
||||
>
|
||||
{copied ? <Check className="h-4 w-4" /> : <Copy className="h-4 w-4" />}
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 opacity-70 hover:opacity-100"
|
||||
onClick={handleClear}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 opacity-70 hover:opacity-100"
|
||||
onClick={() => setOpen(false)}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<div
|
||||
ref={scrollRef}
|
||||
className="h-[400px] overflow-y-auto bg-muted/50 rounded-md p-3 font-mono text-xs"
|
||||
>
|
||||
{logs.length === 0 ? (
|
||||
<p className="text-muted-foreground lowercase">no logs yet...</p>
|
||||
) : (
|
||||
logs.map((log, i) => (
|
||||
<div key={i} className="flex gap-2 py-0.5">
|
||||
<span className="text-muted-foreground shrink-0">
|
||||
[{formatTime(log.timestamp)}]
|
||||
</span>
|
||||
<span className={`shrink-0 w-16 ${levelColors[log.level]}`}>
|
||||
[{log.level}]
|
||||
</span>
|
||||
<span className="break-all">{log.message}</span>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -72,21 +72,33 @@ interface MediaListProps {
|
||||
timeline: TimelineEntry[];
|
||||
totalUrls: number;
|
||||
fetchedMediaType?: string;
|
||||
newMediaCount?: number | null;
|
||||
}
|
||||
|
||||
function getThumbnailUrl(url: string): string {
|
||||
// For animated_gif: video.twimg.com/tweet_video/XXX.mp4 -> pbs.twimg.com/tweet_video_thumb/XXX?format=jpg&name=360x360
|
||||
if (url.includes("video.twimg.com/tweet_video/")) {
|
||||
// Extract filename from URL (e.g., GzstJyDbIAAPuX9.mp4 -> GzstJyDbIAAPuX9)
|
||||
const match = url.match(/tweet_video\/([^\/]+)\.mp4/);
|
||||
if (match && match[1]) {
|
||||
const filename = match[1];
|
||||
return `https://pbs.twimg.com/tweet_video_thumb/${filename}?format=jpg&name=360x360`;
|
||||
}
|
||||
}
|
||||
|
||||
// For photos: pbs.twimg.com/media/XXX -> use 360x360 for consistency
|
||||
if (url.includes("pbs.twimg.com/media/")) {
|
||||
if (url.includes("?format=")) {
|
||||
if (url.includes("&name=")) {
|
||||
const parts = url.split("&name=");
|
||||
return parts[0] + "&name=thumb";
|
||||
return parts[0] + "&name=360x360";
|
||||
}
|
||||
return url + "&name=thumb";
|
||||
return url + "&name=360x360";
|
||||
}
|
||||
if (url.includes("?")) {
|
||||
return url + "&name=thumb";
|
||||
return url + "&name=360x360";
|
||||
}
|
||||
return url + "?format=jpg&name=thumb";
|
||||
return url + "?format=jpg&name=360x360";
|
||||
}
|
||||
return url;
|
||||
}
|
||||
@@ -209,6 +221,7 @@ export function MediaList({
|
||||
timeline,
|
||||
totalUrls,
|
||||
fetchedMediaType = "all",
|
||||
newMediaCount = null,
|
||||
}: MediaListProps) {
|
||||
const [selectedItems, setSelectedItems] = useState<Set<number>>(new Set());
|
||||
const [sortBy, setSortBy] = useState<string>("date-desc");
|
||||
@@ -227,6 +240,9 @@ export function MediaList({
|
||||
const [failedItems, setFailedItems] = useState<Set<string>>(new Set());
|
||||
const [skippedItems, setSkippedItems] = useState<Set<string>>(new Set());
|
||||
const [downloadingItem, setDownloadingItem] = useState<string | null>(null);
|
||||
// Lazy loading: start with 10 thumbnails, load more on scroll
|
||||
const [visibleCount, setVisibleCount] = useState<number>(10);
|
||||
const loadMoreRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// Listen for scroll to show/hide scroll-to-top button
|
||||
useEffect(() => {
|
||||
@@ -237,6 +253,69 @@ export function MediaList({
|
||||
return () => window.removeEventListener("scroll", handleScroll);
|
||||
}, []);
|
||||
|
||||
// Filter and sort timeline
|
||||
const filteredTimeline = useMemo(() => {
|
||||
let filtered = [...timeline];
|
||||
|
||||
// Filter by media type
|
||||
if (filterType !== "all") {
|
||||
filtered = filtered.filter((item) => {
|
||||
if (filterType === "photo") return item.type === "photo";
|
||||
if (filterType === "video") return item.type === "video";
|
||||
if (filterType === "gif") return item.type === "animated_gif" || item.type === "gif";
|
||||
if (filterType === "text") return item.type === "text";
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
// Sort
|
||||
filtered.sort((a, b) => {
|
||||
if (sortBy === "date-desc") {
|
||||
return new Date(b.date).getTime() - new Date(a.date).getTime();
|
||||
} else if (sortBy === "date-asc") {
|
||||
return new Date(a.date).getTime() - new Date(b.date).getTime();
|
||||
} else if (sortBy === "tweet-id-desc") {
|
||||
return Number(b.tweet_id) - Number(a.tweet_id);
|
||||
} else if (sortBy === "tweet-id-asc") {
|
||||
return Number(a.tweet_id) - Number(b.tweet_id);
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
return filtered;
|
||||
}, [timeline, filterType, sortBy]);
|
||||
|
||||
// Reset visible count when filtered timeline changes
|
||||
useEffect(() => {
|
||||
setVisibleCount(10);
|
||||
}, [filteredTimeline.length]);
|
||||
|
||||
// Intersection Observer for lazy loading thumbnails
|
||||
useEffect(() => {
|
||||
if (!loadMoreRef.current) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
if (entries[0].isIntersecting) {
|
||||
setVisibleCount((prev) => {
|
||||
// Load 10 more items at a time
|
||||
const filteredLength = filteredTimeline.length;
|
||||
return Math.min(prev + 10, filteredLength);
|
||||
});
|
||||
}
|
||||
},
|
||||
{ threshold: 0.1 }
|
||||
);
|
||||
|
||||
observer.observe(loadMoreRef.current);
|
||||
|
||||
return () => {
|
||||
if (loadMoreRef.current) {
|
||||
observer.unobserve(loadMoreRef.current);
|
||||
}
|
||||
};
|
||||
}, [filteredTimeline.length]);
|
||||
|
||||
const scrollToTop = () => {
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
};
|
||||
@@ -328,31 +407,6 @@ export function MediaList({
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Filter and sort timeline
|
||||
const filteredTimeline = useMemo(() => {
|
||||
let filtered = [...timeline];
|
||||
|
||||
// Filter by media type
|
||||
if (filterType !== "all") {
|
||||
filtered = filtered.filter((item) => {
|
||||
if (filterType === "photo") return item.type === "photo";
|
||||
if (filterType === "video") return item.type === "video";
|
||||
if (filterType === "gif") return item.type === "gif" || item.type === "animated_gif";
|
||||
if (filterType === "text") return item.type === "text";
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
// Sort
|
||||
if (sortBy === "date-asc") {
|
||||
filtered.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
|
||||
} else {
|
||||
filtered.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
|
||||
}
|
||||
|
||||
return filtered;
|
||||
}, [timeline, sortBy, filterType]);
|
||||
|
||||
const goToPrevious = () => {
|
||||
if (previewIndex !== null && previewIndex > 0) {
|
||||
setPreviewIndex(previewIndex - 1);
|
||||
@@ -407,9 +461,21 @@ export function MediaList({
|
||||
setSelectedItems(newSelected);
|
||||
};
|
||||
|
||||
const handleDownload = async () => {
|
||||
// Helper function to get output directory (adds "My Bookmarks" or "My Likes" folder)
|
||||
const getOutputDir = (): string => {
|
||||
const settings = getSettings();
|
||||
|
||||
const isBookmarks = accountInfo.nick === "My Bookmarks";
|
||||
const isLikes = accountInfo.nick === "My Likes";
|
||||
if (isBookmarks || isLikes) {
|
||||
// Use path separator that backend will normalize (filepath.Join handles both / and \)
|
||||
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
|
||||
const folderName = isBookmarks ? "My Bookmarks" : "My Likes";
|
||||
return `${settings.downloadPath}${separator}${folderName}`;
|
||||
}
|
||||
return settings.downloadPath;
|
||||
};
|
||||
|
||||
const handleDownload = async () => {
|
||||
// Get items with their original indices in filteredTimeline
|
||||
const itemsWithIndices = selectedItems.size > 0
|
||||
? Array.from(selectedItems).map((i) => ({ item: filteredTimeline[i], originalIndex: i }))
|
||||
@@ -432,6 +498,7 @@ export function MediaList({
|
||||
logger.info(`Starting download of ${itemsWithIndices.length} files...`);
|
||||
|
||||
try {
|
||||
const settings = getSettings();
|
||||
const request = new main.DownloadMediaWithMetadataRequest({
|
||||
items: itemsWithIndices.map(({ item }) => new main.MediaItemRequest({
|
||||
url: item.url,
|
||||
@@ -439,15 +506,36 @@ export function MediaList({
|
||||
tweet_id: item.tweet_id,
|
||||
type: item.type,
|
||||
content: item.content || "",
|
||||
original_filename: item.original_filename || "",
|
||||
author_username: item.author_username || "",
|
||||
})),
|
||||
output_dir: settings.downloadPath,
|
||||
output_dir: getOutputDir(),
|
||||
username: accountInfo.name,
|
||||
proxy: settings.proxy || "",
|
||||
});
|
||||
const response = await DownloadMediaWithMetadata(request);
|
||||
|
||||
if (response.success) {
|
||||
logger.success(`Downloaded ${response.downloaded} files`);
|
||||
toast.success(`${response.downloaded} files downloaded`);
|
||||
const parts: string[] = [];
|
||||
if (response.downloaded > 0) {
|
||||
parts.push(`${response.downloaded} file${response.downloaded !== 1 ? 's' : ''} downloaded`);
|
||||
}
|
||||
if (response.skipped > 0) {
|
||||
parts.push(`${response.skipped} file${response.skipped !== 1 ? 's' : ''} already exist${response.skipped !== 1 ? '' : 's'}`);
|
||||
}
|
||||
if (response.failed > 0) {
|
||||
parts.push(`${response.failed} failed`);
|
||||
}
|
||||
const message = parts.length > 0 ? parts.join(', ') : 'Download completed';
|
||||
|
||||
// Use info toast if only skipped files (no downloaded, no failed)
|
||||
if (response.downloaded === 0 && response.failed === 0 && response.skipped > 0) {
|
||||
logger.info(message);
|
||||
toast.info(message);
|
||||
} else {
|
||||
logger.success(message);
|
||||
toast.success(message);
|
||||
}
|
||||
setHasDownloaded(true);
|
||||
|
||||
// Check if there are GIFs and FFmpeg is installed
|
||||
@@ -486,10 +574,22 @@ export function MediaList({
|
||||
|
||||
const handleOpenFolder = async () => {
|
||||
const settings = getSettings();
|
||||
// Build path - backend will handle path separators with filepath.Clean
|
||||
const folderPath = settings.downloadPath
|
||||
? `${settings.downloadPath}/${accountInfo.name}`
|
||||
: accountInfo.name;
|
||||
const isBookmarks = accountInfo.nick === "My Bookmarks";
|
||||
const isLikes = accountInfo.nick === "My Likes";
|
||||
|
||||
// Build path - for bookmarks/likes, use the folder structure
|
||||
let folderPath: string;
|
||||
if (isBookmarks || isLikes) {
|
||||
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
|
||||
const folderName = isBookmarks ? "My Bookmarks" : "My Likes";
|
||||
folderPath = settings.downloadPath
|
||||
? `${settings.downloadPath}${separator}${folderName}`
|
||||
: folderName;
|
||||
} else {
|
||||
folderPath = settings.downloadPath
|
||||
? `${settings.downloadPath}/${accountInfo.name}`
|
||||
: accountInfo.name;
|
||||
}
|
||||
|
||||
try {
|
||||
await OpenFolder(folderPath);
|
||||
@@ -508,8 +608,18 @@ export function MediaList({
|
||||
|
||||
const handleConvertGifs = async () => {
|
||||
const settings = getSettings();
|
||||
// Use forward slash for cross-platform compatibility (Go's filepath.Join handles it)
|
||||
const folderPath = `${settings.downloadPath}/${accountInfo.name}`;
|
||||
const isBookmarks = accountInfo.nick === "My Bookmarks";
|
||||
const isLikes = accountInfo.nick === "My Likes";
|
||||
|
||||
// Build path - for bookmarks/likes, use the folder structure
|
||||
let folderPath: string;
|
||||
if (isBookmarks || isLikes) {
|
||||
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
|
||||
const folderName = isBookmarks ? "My Bookmarks" : "My Likes";
|
||||
folderPath = `${settings.downloadPath}${separator}${folderName}`;
|
||||
} else {
|
||||
folderPath = `${settings.downloadPath}/${accountInfo.name}`;
|
||||
}
|
||||
|
||||
setIsConverting(true);
|
||||
logger.info("Converting GIFs...");
|
||||
@@ -542,20 +652,28 @@ export function MediaList({
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Account Info Card */}
|
||||
{accountInfo.name === "bookmarks" ? (
|
||||
// Bookmarks mode - simple card without account info
|
||||
{accountInfo.name === "bookmarks" || accountInfo.name === "likes" ? (
|
||||
// Bookmarks/Likes mode - simple card without account info
|
||||
<div className="flex items-center gap-4 p-4 bg-muted/50 rounded-lg">
|
||||
<div className="w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center">
|
||||
<Bookmark className="h-8 w-8 text-primary" />
|
||||
{accountInfo.name === "bookmarks" ? (
|
||||
<Bookmark className="h-8 w-8 text-primary" />
|
||||
) : (
|
||||
<Heart className="h-8 w-8 text-primary" />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<h2 className="text-xl font-semibold">My Bookmarks</h2>
|
||||
<p className="text-sm text-muted-foreground mt-1">
|
||||
Your saved tweets from various accounts
|
||||
</p>
|
||||
<h2 className="text-xl font-semibold">{accountInfo.nick}</h2>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="text-2xl font-bold text-primary">{formatNumberWithComma(totalUrls)}</div>
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
{newMediaCount !== null && newMediaCount > 0 && (
|
||||
<div className="text-lg font-semibold text-green-600 dark:text-green-400 animate-in fade-in slide-in-from-left-2 duration-300">
|
||||
{formatNumberWithComma(newMediaCount)}+
|
||||
</div>
|
||||
)}
|
||||
<div className="text-2xl font-bold text-primary">{formatNumberWithComma(totalUrls)}</div>
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground">items found</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -594,7 +712,14 @@ export function MediaList({
|
||||
</div>
|
||||
</div>
|
||||
<div className="text-right">
|
||||
<div className="text-2xl font-bold text-primary">{formatNumberWithComma(totalUrls)}</div>
|
||||
<div className="flex items-center justify-end gap-2">
|
||||
{newMediaCount !== null && newMediaCount > 0 && (
|
||||
<div className="text-lg font-semibold text-green-600 dark:text-green-400 animate-in fade-in slide-in-from-left-2 duration-300">
|
||||
{formatNumberWithComma(newMediaCount)}+
|
||||
</div>
|
||||
)}
|
||||
<div className="text-2xl font-bold text-primary">{formatNumberWithComma(totalUrls)}</div>
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground">items found</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -745,7 +870,7 @@ export function MediaList({
|
||||
{/* Media Grid/List */}
|
||||
{viewMode === "list" ? (
|
||||
<div className="space-y-2">
|
||||
{filteredTimeline.map((item, index) => {
|
||||
{filteredTimeline.slice(0, visibleCount).map((item, index) => {
|
||||
const isSelected = selectedItems.has(index);
|
||||
const itemKey = getItemKey(item);
|
||||
const isItemDownloaded = downloadedItems.has(itemKey);
|
||||
@@ -770,7 +895,7 @@ export function MediaList({
|
||||
className="w-16 h-16 rounded overflow-hidden bg-muted shrink-0 cursor-pointer hover:opacity-80 transition-opacity"
|
||||
onClick={() => openPreview(index)}
|
||||
>
|
||||
{item.type === "photo" ? (
|
||||
{item.type === "photo" || item.type === "animated_gif" || item.type === "gif" ? (
|
||||
<img
|
||||
src={getThumbnailUrl(item.url)}
|
||||
alt=""
|
||||
@@ -828,10 +953,10 @@ export function MediaList({
|
||||
size="icon"
|
||||
variant="default"
|
||||
onClick={async () => {
|
||||
const settings = getSettings();
|
||||
setDownloadingItem(itemKey);
|
||||
currentDownloadingItemKeyRef.current = itemKey;
|
||||
try {
|
||||
const settings = getSettings();
|
||||
const request = new main.DownloadMediaWithMetadataRequest({
|
||||
items: [new main.MediaItemRequest({
|
||||
url: item.url,
|
||||
@@ -839,9 +964,12 @@ export function MediaList({
|
||||
tweet_id: item.tweet_id,
|
||||
type: item.type,
|
||||
content: item.content || "",
|
||||
original_filename: item.original_filename || "",
|
||||
author_username: item.author_username || "",
|
||||
})],
|
||||
output_dir: settings.downloadPath,
|
||||
output_dir: getOutputDir(),
|
||||
username: accountInfo.name,
|
||||
proxy: settings.proxy || "",
|
||||
});
|
||||
const response = await DownloadMediaWithMetadata(request);
|
||||
if (response.success) {
|
||||
@@ -903,7 +1031,7 @@ export function MediaList({
|
||||
</div>
|
||||
) : (
|
||||
<div className={`grid gap-3 ${viewMode === "large" ? "grid-cols-4" : "grid-cols-6"}`}>
|
||||
{filteredTimeline.map((item, index) => {
|
||||
{filteredTimeline.slice(0, visibleCount).map((item, index) => {
|
||||
const isSelected = selectedItems.has(index);
|
||||
const itemKey = getItemKey(item);
|
||||
const isItemDownloaded = downloadedItems.has(itemKey);
|
||||
@@ -923,7 +1051,7 @@ export function MediaList({
|
||||
className="aspect-square bg-muted relative cursor-pointer"
|
||||
onClick={() => openPreview(index)}
|
||||
>
|
||||
{item.type === "photo" ? (
|
||||
{item.type === "photo" || item.type === "animated_gif" || item.type === "gif" ? (
|
||||
<img
|
||||
src={getThumbnailUrl(item.url)}
|
||||
alt=""
|
||||
@@ -946,10 +1074,10 @@ export function MediaList({
|
||||
className="h-8 w-8"
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation();
|
||||
const settings = getSettings();
|
||||
setDownloadingItem(itemKey);
|
||||
currentDownloadingItemKeyRef.current = itemKey;
|
||||
try {
|
||||
const settings = getSettings();
|
||||
const request = new main.DownloadMediaWithMetadataRequest({
|
||||
items: [new main.MediaItemRequest({
|
||||
url: item.url,
|
||||
@@ -957,9 +1085,11 @@ export function MediaList({
|
||||
tweet_id: item.tweet_id,
|
||||
type: item.type,
|
||||
content: item.content || "",
|
||||
author_username: item.author_username || "",
|
||||
})],
|
||||
output_dir: settings.downloadPath,
|
||||
output_dir: getOutputDir(),
|
||||
username: accountInfo.name,
|
||||
proxy: settings.proxy || "",
|
||||
});
|
||||
const response = await DownloadMediaWithMetadata(request);
|
||||
if (response.success) {
|
||||
@@ -1075,6 +1205,13 @@ export function MediaList({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Sentinel for lazy loading - only show if there are more items to load */}
|
||||
{visibleCount < filteredTimeline.length && (
|
||||
<div ref={loadMoreRef} className="h-20 flex items-center justify-center w-full">
|
||||
<Spinner />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Media Preview Overlay */}
|
||||
{previewIndex !== null && filteredTimeline[previewIndex] && (
|
||||
<div
|
||||
@@ -1193,10 +1330,10 @@ export function MediaList({
|
||||
size="sm"
|
||||
className="h-9"
|
||||
onClick={async () => {
|
||||
const settings = getSettings();
|
||||
setDownloadingItem(itemKey);
|
||||
currentDownloadingItemKeyRef.current = itemKey;
|
||||
try {
|
||||
const settings = getSettings();
|
||||
const request = new main.DownloadMediaWithMetadataRequest({
|
||||
items: [new main.MediaItemRequest({
|
||||
url: item.url,
|
||||
@@ -1204,9 +1341,12 @@ export function MediaList({
|
||||
tweet_id: item.tweet_id,
|
||||
type: item.type,
|
||||
content: item.content || "",
|
||||
original_filename: item.original_filename || "",
|
||||
author_username: item.author_username || "",
|
||||
})],
|
||||
output_dir: settings.downloadPath,
|
||||
output_dir: getOutputDir(),
|
||||
username: accountInfo.name,
|
||||
proxy: settings.proxy || "",
|
||||
});
|
||||
const response = await DownloadMediaWithMetadata(request);
|
||||
if (response.success) {
|
||||
|
||||
@@ -3,7 +3,6 @@ import { Button } from "@/components/ui/button";
|
||||
import { InputWithContext } from "@/components/ui/input-with-context";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Search,
|
||||
XCircle,
|
||||
Calendar,
|
||||
StopCircle,
|
||||
@@ -19,6 +18,14 @@ import {
|
||||
Info,
|
||||
RotateCcw,
|
||||
Trash2,
|
||||
Clock,
|
||||
CloudDownload,
|
||||
User,
|
||||
Users,
|
||||
FileText,
|
||||
Hourglass,
|
||||
CheckCircle,
|
||||
AlertCircle,
|
||||
} from "lucide-react";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
@@ -41,11 +48,30 @@ import { cn } from "@/lib/utils";
|
||||
|
||||
export type FetchMode = "public" | "private";
|
||||
export type PrivateType = "bookmarks" | "likes";
|
||||
export type FetchType = "single" | "multiple";
|
||||
|
||||
// Local storage keys for auth tokens
|
||||
const PUBLIC_AUTH_TOKEN_KEY = "twitter_public_auth_token";
|
||||
const PRIVATE_AUTH_TOKEN_KEY = "twitter_private_auth_token";
|
||||
|
||||
export interface MultipleAccount {
|
||||
id: string;
|
||||
username: string;
|
||||
status: "pending" | "fetching" | "completed" | "incomplete" | "failed";
|
||||
accountInfo?: {
|
||||
name: string;
|
||||
nick: string;
|
||||
profile_image: string;
|
||||
};
|
||||
mediaCount: number;
|
||||
previousMediaCount: number;
|
||||
elapsedTime: number;
|
||||
remainingTime: number | null;
|
||||
error?: string;
|
||||
showDiff?: boolean;
|
||||
cursor?: string;
|
||||
}
|
||||
|
||||
interface SearchBarProps {
|
||||
username: string;
|
||||
loading: boolean;
|
||||
@@ -69,6 +95,22 @@ interface SearchBarProps {
|
||||
onHistorySelect: (item: HistoryItem) => void;
|
||||
onHistoryRemove: (id: string) => void;
|
||||
hasResult: boolean;
|
||||
elapsedTime?: number;
|
||||
remainingTime?: number | null;
|
||||
// Multiple mode props
|
||||
fetchType?: FetchType;
|
||||
onFetchTypeChange?: (type: FetchType) => void;
|
||||
multipleAccounts?: MultipleAccount[];
|
||||
onImportFile?: () => void;
|
||||
onFetchAll?: () => void;
|
||||
onStopAll?: () => void;
|
||||
onStopAccount?: (accountId: string) => void;
|
||||
onRetryAccount?: (accountId: string) => void;
|
||||
isFetchingAll?: boolean;
|
||||
// Mode control
|
||||
mode?: FetchMode;
|
||||
privateType?: PrivateType;
|
||||
onModeChange?: (mode: FetchMode, privateType?: PrivateType) => void;
|
||||
}
|
||||
|
||||
export function SearchBar({
|
||||
@@ -84,14 +126,41 @@ export function SearchBar({
|
||||
onHistorySelect,
|
||||
onHistoryRemove,
|
||||
hasResult,
|
||||
elapsedTime = 0,
|
||||
remainingTime = null,
|
||||
fetchType = "single",
|
||||
onFetchTypeChange,
|
||||
multipleAccounts = [],
|
||||
onImportFile,
|
||||
onFetchAll,
|
||||
onStopAll,
|
||||
onStopAccount,
|
||||
onRetryAccount,
|
||||
isFetchingAll = false,
|
||||
mode: externalMode,
|
||||
privateType: externalPrivateType,
|
||||
onModeChange,
|
||||
}: SearchBarProps) {
|
||||
const [useDateRange, setUseDateRange] = useState(false);
|
||||
const [startDate, setStartDate] = useState("");
|
||||
const [endDate, setEndDate] = useState("");
|
||||
const [mediaType, setMediaType] = useState("all");
|
||||
const [retweets, setRetweets] = useState(false);
|
||||
const [mode, setMode] = useState<FetchMode>("public");
|
||||
const [privateType, setPrivateType] = useState<PrivateType>("bookmarks");
|
||||
const [mode, setMode] = useState<FetchMode>(externalMode || "public");
|
||||
const [privateType, setPrivateType] = useState<PrivateType>(externalPrivateType || "bookmarks");
|
||||
|
||||
// Sync with external mode if provided
|
||||
useEffect(() => {
|
||||
if (externalMode !== undefined) {
|
||||
setMode(externalMode);
|
||||
}
|
||||
}, [externalMode]);
|
||||
|
||||
useEffect(() => {
|
||||
if (externalPrivateType !== undefined) {
|
||||
setPrivateType(externalPrivateType);
|
||||
}
|
||||
}, [externalPrivateType]);
|
||||
const [showAuthInput, setShowAuthInput] = useState(false);
|
||||
const [showAdvanced, setShowAdvanced] = useState(false);
|
||||
|
||||
@@ -138,42 +207,150 @@ export function SearchBar({
|
||||
const isLikesMode = mode === "private" && privateType === "likes";
|
||||
const isBookmarksMode = mode === "private" && privateType === "bookmarks";
|
||||
|
||||
const formatTime = (seconds: number): string => {
|
||||
const mins = Math.floor(seconds / 60);
|
||||
const secs = seconds % 60;
|
||||
return `${mins}:${String(secs).padStart(2, "0")}`;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{/* Mode Toggle */}
|
||||
<div className="flex justify-center">
|
||||
<div className="flex gap-1 p-1 bg-muted rounded-lg w-fit">
|
||||
{/* Fetch Type and Mode Toggle (Single/Multiple and Public/Private in one line) */}
|
||||
<div className="flex justify-center gap-2">
|
||||
<div className="flex gap-0.5 p-0.5 bg-muted rounded-lg w-fit">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMode("public")}
|
||||
onClick={() => onFetchTypeChange?.("single")}
|
||||
className={cn(
|
||||
"flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all cursor-pointer",
|
||||
mode === "public"
|
||||
"flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all cursor-pointer",
|
||||
fetchType === "single"
|
||||
? "bg-background text-foreground shadow-sm"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
)}
|
||||
>
|
||||
<Globe className="h-4 w-4" />
|
||||
Public
|
||||
<User className="h-3 w-3" />
|
||||
Single
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMode("private")}
|
||||
onClick={() => onFetchTypeChange?.("multiple")}
|
||||
className={cn(
|
||||
"flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all cursor-pointer",
|
||||
mode === "private"
|
||||
"flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all cursor-pointer",
|
||||
fetchType === "multiple"
|
||||
? "bg-background text-foreground shadow-sm"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
)}
|
||||
>
|
||||
<Lock className="h-4 w-4" />
|
||||
Private
|
||||
<Users className="h-3 w-3" />
|
||||
Multiple
|
||||
</button>
|
||||
</div>
|
||||
{fetchType === "single" && (
|
||||
<div className="flex gap-0.5 p-0.5 bg-muted rounded-lg w-fit">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMode("public");
|
||||
onModeChange?.("public");
|
||||
}}
|
||||
className={cn(
|
||||
"flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all cursor-pointer",
|
||||
mode === "public"
|
||||
? "bg-background text-foreground shadow-sm"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
)}
|
||||
>
|
||||
<Globe className="h-3 w-3" />
|
||||
Public
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMode("private");
|
||||
onModeChange?.("private");
|
||||
}}
|
||||
className={cn(
|
||||
"flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all cursor-pointer",
|
||||
mode === "private"
|
||||
? "bg-background text-foreground shadow-sm"
|
||||
: "text-muted-foreground hover:text-foreground"
|
||||
)}
|
||||
>
|
||||
<Lock className="h-3 w-3" />
|
||||
Private
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Username Input - for public mode and likes mode */}
|
||||
{(mode === "public" || isLikesMode) && (
|
||||
{/* Multiple Mode UI - Import and Fetch All Buttons */}
|
||||
{fetchType === "multiple" && (
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label htmlFor="import-txt" className="text-sm">
|
||||
Import Accounts
|
||||
</Label>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Info className="h-4 w-4 text-muted-foreground cursor-help" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent className="max-w-xs">
|
||||
<p className="text-sm">
|
||||
One username per line, example:
|
||||
<br />
|
||||
<span className="font-mono text-xs">masteraoko</span>
|
||||
<br />
|
||||
<span className="font-mono text-xs">xbatchdemo</span>
|
||||
<br />
|
||||
<span className="font-mono text-xs">takomayuyi</span>
|
||||
</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
id="import-txt"
|
||||
variant="outline"
|
||||
onClick={onImportFile}
|
||||
className="flex items-center gap-2 flex-1"
|
||||
>
|
||||
<FileText className="h-4 w-4" />
|
||||
Import TXT File
|
||||
</Button>
|
||||
<Button
|
||||
variant="default"
|
||||
onClick={onFetchAll}
|
||||
disabled={multipleAccounts.length === 0 || isFetchingAll}
|
||||
className="flex items-center gap-2 flex-1"
|
||||
>
|
||||
{isFetchingAll ? (
|
||||
<>
|
||||
<Spinner />
|
||||
Fetching All...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<CloudDownload className="h-4 w-4" />
|
||||
Fetch All
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
{isFetchingAll && (
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={onStopAll}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<StopCircle className="h-4 w-4" />
|
||||
Stop All
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Username Input - for public mode and likes mode, only in single mode */}
|
||||
{fetchType === "single" && (mode === "public" || isLikesMode) && (
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="username">
|
||||
{isLikesMode ? "Your Username" : "Username"}
|
||||
@@ -205,10 +382,23 @@ export function SearchBar({
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{loading && (
|
||||
<Button variant="destructive" onClick={onStopFetch}>
|
||||
<StopCircle className="h-4 w-4" />
|
||||
Stop
|
||||
</Button>
|
||||
<>
|
||||
{/* Timer Display */}
|
||||
{(remainingTime !== null || elapsedTime > 0) && (
|
||||
<div className="flex items-center gap-1.5 px-3 py-1.5 border rounded-md bg-muted/50 text-sm w-[85px]">
|
||||
<Clock className="h-3.5 w-3.5 text-muted-foreground flex-shrink-0" />
|
||||
<span className="font-mono">
|
||||
{remainingTime !== null && remainingTime >= 0
|
||||
? `${Math.floor(remainingTime / 60)}:${String(remainingTime % 60).padStart(2, "0")}`
|
||||
: `${Math.floor(elapsedTime / 60)}:${String(elapsedTime % 60).padStart(2, "0")}`}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<Button variant="destructive" onClick={onStopFetch}>
|
||||
<StopCircle className="h-4 w-4" />
|
||||
Stop
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{/* Resume button - show when there's resumable data */}
|
||||
{!loading && resumeInfo?.canResume && mode === "public" && (
|
||||
@@ -235,7 +425,7 @@ export function SearchBar({
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{isLikesMode ? <Heart className="h-4 w-4" /> : <Search className="h-4 w-4" />}
|
||||
{isLikesMode ? <Heart className="h-4 w-4" /> : <CloudDownload className="h-4 w-4" />}
|
||||
{isLikesMode ? "Fetch Likes" : "Fetch"}
|
||||
</>
|
||||
)}
|
||||
@@ -270,11 +460,14 @@ export function SearchBar({
|
||||
</button>
|
||||
|
||||
{/* Private Mode Options - My Bookmarks / My Likes */}
|
||||
{mode === "private" && (
|
||||
{mode === "private" && fetchType === "single" && (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setPrivateType("bookmarks")}
|
||||
onClick={() => {
|
||||
setPrivateType("bookmarks");
|
||||
onModeChange?.("private", "bookmarks");
|
||||
}}
|
||||
className={cn(
|
||||
"flex items-center gap-2 px-4 py-2 rounded-lg border text-sm font-medium transition-all cursor-pointer",
|
||||
privateType === "bookmarks"
|
||||
@@ -287,7 +480,10 @@ export function SearchBar({
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setPrivateType("likes")}
|
||||
onClick={() => {
|
||||
setPrivateType("likes");
|
||||
onModeChange?.("private", "likes");
|
||||
}}
|
||||
className={cn(
|
||||
"flex items-center gap-2 px-4 py-2 rounded-lg border text-sm font-medium transition-all cursor-pointer",
|
||||
privateType === "likes"
|
||||
@@ -305,10 +501,23 @@ export function SearchBar({
|
||||
{isBookmarksMode && (
|
||||
<div className="flex items-center gap-2 ml-auto">
|
||||
{loading && (
|
||||
<Button variant="destructive" onClick={onStopFetch}>
|
||||
<StopCircle className="h-4 w-4" />
|
||||
Stop
|
||||
</Button>
|
||||
<>
|
||||
{/* Timer Display */}
|
||||
{(remainingTime !== null || elapsedTime > 0) && (
|
||||
<div className="flex items-center gap-1.5 px-3 py-1.5 border rounded-md bg-muted/50 text-sm w-[85px]">
|
||||
<Clock className="h-3.5 w-3.5 text-muted-foreground flex-shrink-0" />
|
||||
<span className="font-mono">
|
||||
{remainingTime !== null && remainingTime >= 0
|
||||
? `${Math.floor(remainingTime / 60)}:${String(remainingTime % 60).padStart(2, "0")}`
|
||||
: `${Math.floor(elapsedTime / 60)}:${String(elapsedTime % 60).padStart(2, "0")}`}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<Button variant="destructive" onClick={onStopFetch}>
|
||||
<StopCircle className="h-4 w-4" />
|
||||
Stop
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
<Button onClick={handleFetch} disabled={loading || !hasAuthToken}>
|
||||
{loading ? (
|
||||
@@ -471,7 +680,167 @@ export function SearchBar({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!hasResult && mode === "public" && (
|
||||
{/* Statistics for Multiple Fetch - below auth token and advanced settings */}
|
||||
{fetchType === "multiple" && multipleAccounts.length > 0 && (
|
||||
<div className="p-3 border rounded-lg bg-muted/30">
|
||||
<div className="flex items-center gap-6 text-sm">
|
||||
<div className="flex items-center gap-2">
|
||||
<CheckCircle className="h-4 w-4 text-green-600 dark:text-green-400" />
|
||||
<span className="text-muted-foreground">Completed:</span>
|
||||
<span className="font-medium">
|
||||
{multipleAccounts.filter((acc) => acc.status === "completed").length}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<AlertCircle className="h-4 w-4 text-yellow-600 dark:text-yellow-400" />
|
||||
<span className="text-muted-foreground">Incomplete:</span>
|
||||
<span className="font-medium">
|
||||
{multipleAccounts.filter((acc) => acc.status === "incomplete").length}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<XCircle className="h-4 w-4 text-red-600 dark:text-red-400" />
|
||||
<span className="text-muted-foreground">Failed:</span>
|
||||
<span className="font-medium">
|
||||
{multipleAccounts.filter((acc) => acc.status === "failed").length}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 ml-auto">
|
||||
<span className="text-muted-foreground">Total:</span>
|
||||
<span className="font-medium">
|
||||
{multipleAccounts.filter((acc) =>
|
||||
acc.status === "completed" || acc.status === "incomplete" || acc.status === "failed"
|
||||
).length}/{multipleAccounts.length}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Account List - below auth token and advanced settings */}
|
||||
{fetchType === "multiple" && multipleAccounts.length > 0 && (
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm text-muted-foreground">Accounts to Fetch ({multipleAccounts.length})</p>
|
||||
<div className="space-y-2 max-h-[400px] overflow-y-auto">
|
||||
{multipleAccounts.map((account) => (
|
||||
<div
|
||||
key={account.id}
|
||||
className="p-3 border rounded-lg bg-card"
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
{account.accountInfo ? (
|
||||
<img
|
||||
src={account.accountInfo.profile_image}
|
||||
alt={account.accountInfo.nick}
|
||||
className="w-10 h-10 rounded-full"
|
||||
/>
|
||||
) : (
|
||||
<div className="w-10 h-10 rounded-full bg-muted flex items-center justify-center">
|
||||
<User className="h-5 w-5 text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
{account.accountInfo ? (
|
||||
<>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium">{account.accountInfo.nick}</span>
|
||||
<span className="text-sm text-muted-foreground">@{account.accountInfo.name}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-1">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
<span className="text-primary">{account.mediaCount.toLocaleString()}</span> items found
|
||||
</span>
|
||||
{account.showDiff && account.previousMediaCount > 0 && account.mediaCount > account.previousMediaCount && (
|
||||
<span className="text-sm text-green-600 dark:text-green-400 font-medium">
|
||||
+{account.mediaCount - account.previousMediaCount}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium">@{account.username}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{account.status === "fetching" && (
|
||||
<>
|
||||
<div className="flex items-center gap-1.5 px-3 py-1.5 border rounded-md bg-muted/50 text-sm w-[85px]">
|
||||
<Clock className="h-3.5 w-3.5 text-muted-foreground flex-shrink-0" />
|
||||
<span className="font-mono">
|
||||
{account.remainingTime !== null && account.remainingTime >= 0
|
||||
? formatTime(account.remainingTime)
|
||||
: formatTime(account.elapsedTime)}
|
||||
</span>
|
||||
</div>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={() => onStopAccount?.(account.id)}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<StopCircle className="h-4 w-4" />
|
||||
Stop
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{account.status === "pending" && (
|
||||
<span className="text-xs px-2 py-1 bg-gray-500/20 text-gray-600 dark:text-gray-400 rounded flex items-center gap-1.5">
|
||||
<Hourglass className="h-3 w-3" />
|
||||
Pending
|
||||
</span>
|
||||
)}
|
||||
{account.status === "completed" && (
|
||||
<span className="text-xs px-2 py-1 bg-green-500/20 text-green-600 dark:text-green-400 rounded flex items-center gap-1.5">
|
||||
<CheckCircle className="h-3 w-3" />
|
||||
Completed
|
||||
</span>
|
||||
)}
|
||||
{account.status === "incomplete" && (
|
||||
<>
|
||||
<span className="text-xs px-2 py-1 bg-yellow-500/20 text-yellow-600 dark:text-yellow-400 rounded flex items-center gap-1.5">
|
||||
<AlertCircle className="h-3 w-3" />
|
||||
Incomplete
|
||||
</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onRetryAccount?.(account.id)}
|
||||
disabled={isFetchingAll}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<RotateCcw className="h-3.5 w-3.5" />
|
||||
Retry
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{account.status === "failed" && (
|
||||
<>
|
||||
<span className="text-xs px-2 py-1 bg-red-500/20 text-red-600 dark:text-red-400 rounded flex items-center gap-1.5">
|
||||
<XCircle className="h-3 w-3" />
|
||||
Failed
|
||||
</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => onRetryAccount?.(account.id)}
|
||||
disabled={isFetchingAll}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<RotateCcw className="h-3.5 w-3.5" />
|
||||
Retry
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!hasResult && mode === "public" && fetchType === "single" && (
|
||||
<FetchHistory
|
||||
history={history}
|
||||
onSelect={onHistorySelect}
|
||||
|
||||
@@ -1,327 +0,0 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { InputWithContext } from "@/components/ui/input-with-context";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Settings as SettingsIcon, FolderOpen, Save, RotateCcw, X, Info, Download, Check, Volume2 } from "lucide-react";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { getSettings, getSettingsWithDefaults, saveSettings, resetToDefaultSettings, applyThemeMode, type Settings as SettingsType } from "@/lib/settings";
|
||||
import { themes, applyTheme } from "@/lib/themes";
|
||||
import { toastWithSound as toast } from "@/lib/toast-with-sound";
|
||||
import { SelectFolder, IsFFmpegInstalled, DownloadFFmpeg } from "../../wailsjs/go/main/App";
|
||||
|
||||
export function Settings() {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [savedSettings, setSavedSettings] = useState<SettingsType>(getSettings());
|
||||
const [tempSettings, setTempSettings] = useState<SettingsType>(savedSettings);
|
||||
const [, setIsLoadingDefaults] = useState(false);
|
||||
const [isDark, setIsDark] = useState(document.documentElement.classList.contains('dark'));
|
||||
const [ffmpegInstalled, setFfmpegInstalled] = useState(false);
|
||||
const [downloadingFFmpeg, setDownloadingFFmpeg] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
applyThemeMode(savedSettings.themeMode);
|
||||
applyTheme(savedSettings.theme);
|
||||
|
||||
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
const handleChange = () => {
|
||||
if (savedSettings.themeMode === "auto") {
|
||||
applyThemeMode("auto");
|
||||
applyTheme(savedSettings.theme);
|
||||
}
|
||||
};
|
||||
|
||||
mediaQuery.addEventListener("change", handleChange);
|
||||
return () => mediaQuery.removeEventListener("change", handleChange);
|
||||
}, [savedSettings.themeMode, savedSettings.theme]);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
applyThemeMode(tempSettings.themeMode);
|
||||
applyTheme(tempSettings.theme);
|
||||
|
||||
setTimeout(() => {
|
||||
setIsDark(document.documentElement.classList.contains('dark'));
|
||||
}, 0);
|
||||
|
||||
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
const handleChange = () => {
|
||||
if (tempSettings.themeMode === "auto") {
|
||||
applyThemeMode("auto");
|
||||
applyTheme(tempSettings.theme);
|
||||
setTimeout(() => {
|
||||
setIsDark(document.documentElement.classList.contains('dark'));
|
||||
}, 0);
|
||||
}
|
||||
};
|
||||
|
||||
mediaQuery.addEventListener("change", handleChange);
|
||||
return () => mediaQuery.removeEventListener("change", handleChange);
|
||||
}
|
||||
}, [open, tempSettings.themeMode, tempSettings.theme]);
|
||||
|
||||
useEffect(() => {
|
||||
const loadDefaults = async () => {
|
||||
if (!savedSettings.downloadPath) {
|
||||
setIsLoadingDefaults(true);
|
||||
const settingsWithDefaults = await getSettingsWithDefaults();
|
||||
setSavedSettings(settingsWithDefaults);
|
||||
setTempSettings(settingsWithDefaults);
|
||||
setIsLoadingDefaults(false);
|
||||
}
|
||||
};
|
||||
loadDefaults();
|
||||
|
||||
// Check FFmpeg status
|
||||
IsFFmpegInstalled().then(setFfmpegInstalled);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setTempSettings(savedSettings);
|
||||
}
|
||||
}, [open, savedSettings]);
|
||||
|
||||
const handleSave = () => {
|
||||
saveSettings(tempSettings);
|
||||
setSavedSettings(tempSettings);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const handleReset = async () => {
|
||||
const defaultSettings = await resetToDefaultSettings();
|
||||
setTempSettings(defaultSettings);
|
||||
setSavedSettings(defaultSettings);
|
||||
applyThemeMode(defaultSettings.themeMode);
|
||||
applyTheme(defaultSettings.theme);
|
||||
};
|
||||
|
||||
const handleCancel = () => {
|
||||
applyThemeMode(savedSettings.themeMode);
|
||||
applyTheme(savedSettings.theme);
|
||||
setTempSettings(savedSettings);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const handleOpenChange = (newOpen: boolean) => {
|
||||
if (!newOpen) {
|
||||
applyThemeMode(savedSettings.themeMode);
|
||||
applyTheme(savedSettings.theme);
|
||||
setTempSettings(savedSettings);
|
||||
}
|
||||
setOpen(newOpen);
|
||||
};
|
||||
|
||||
const handleBrowseFolder = async () => {
|
||||
try {
|
||||
const selectedPath = await SelectFolder(tempSettings.downloadPath || "");
|
||||
if (selectedPath && selectedPath.trim() !== "") {
|
||||
setTempSettings((prev) => ({ ...prev, downloadPath: selectedPath }));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error selecting folder:", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDownloadFFmpeg = async () => {
|
||||
setDownloadingFFmpeg(true);
|
||||
try {
|
||||
await DownloadFFmpeg();
|
||||
setFfmpegInstalled(true);
|
||||
toast.success("FFmpeg downloaded successfully");
|
||||
} catch (error) {
|
||||
toast.error("Failed to download FFmpeg");
|
||||
console.error("Error downloading FFmpeg:", error);
|
||||
} finally {
|
||||
setDownloadingFFmpeg(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="outline" size="icon">
|
||||
<SettingsIcon className="h-5 w-5" />
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-[480px] flex flex-col p-6 [&>button]:hidden" aria-describedby={undefined}>
|
||||
<div className="absolute right-4 top-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-6 w-6 opacity-70 hover:opacity-100"
|
||||
onClick={handleCancel}
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<DialogTitle className="text-sm font-medium">Settings</DialogTitle>
|
||||
|
||||
{/* 2 Column Grid Layout */}
|
||||
<div className="grid grid-cols-2 gap-x-6 gap-y-4 py-2">
|
||||
{/* LEFT COLUMN */}
|
||||
{/* Download Path */}
|
||||
<div className="space-y-2 col-span-2">
|
||||
<Label htmlFor="download-path">Download Path</Label>
|
||||
<div className="flex gap-2">
|
||||
<InputWithContext
|
||||
id="download-path"
|
||||
value={tempSettings.downloadPath}
|
||||
onChange={(e) => setTempSettings((prev) => ({ ...prev, downloadPath: e.target.value }))}
|
||||
placeholder="C:\Users\YourUsername\Pictures"
|
||||
/>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button type="button" onClick={handleBrowseFolder} size="icon">
|
||||
<FolderOpen className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Browse Folder</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* LEFT: Mode */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="theme-mode">Mode</Label>
|
||||
<Select
|
||||
value={tempSettings.themeMode}
|
||||
onValueChange={(value) => setTempSettings((prev) => ({ ...prev, themeMode: value as any }))}
|
||||
>
|
||||
<SelectTrigger id="theme-mode">
|
||||
<SelectValue placeholder="Select theme mode" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="auto">Auto</SelectItem>
|
||||
<SelectItem value="light">Light</SelectItem>
|
||||
<SelectItem value="dark">Dark</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* RIGHT: GIF Conversion */}
|
||||
<div className="space-y-2">
|
||||
<Label className="flex items-center gap-2">
|
||||
GIF Conversion
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Info className="h-3.5 w-3.5 text-muted-foreground cursor-help" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top">
|
||||
<p>FFmpeg is required to convert Twitter's MP4 to actual GIF format</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</Label>
|
||||
<div className="h-9 flex items-center">
|
||||
{ffmpegInstalled ? (
|
||||
<div className="flex items-center gap-2 text-sm text-green-600 dark:text-green-400">
|
||||
<Check className="h-4 w-4" />
|
||||
Installed
|
||||
</div>
|
||||
) : (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-9"
|
||||
onClick={handleDownloadFFmpeg}
|
||||
disabled={downloadingFFmpeg}
|
||||
>
|
||||
{downloadingFFmpeg ? (
|
||||
<>
|
||||
<Spinner />
|
||||
Downloading...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download className="h-4 w-4" />
|
||||
Download FFmpeg
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* LEFT: Accent */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="theme">Accent</Label>
|
||||
<Select
|
||||
value={tempSettings.theme}
|
||||
onValueChange={(value) => setTempSettings((prev) => ({ ...prev, theme: value }))}
|
||||
>
|
||||
<SelectTrigger id="theme">
|
||||
<SelectValue placeholder="Select a theme" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{themes.map((theme) => (
|
||||
<SelectItem key={theme.name} value={theme.name}>
|
||||
<span className="flex items-center gap-2">
|
||||
<span
|
||||
className="w-3 h-3 rounded-full border border-border"
|
||||
style={{
|
||||
backgroundColor: isDark
|
||||
? theme.cssVars.dark.primary
|
||||
: theme.cssVars.light.primary
|
||||
}}
|
||||
/>
|
||||
{theme.label}
|
||||
</span>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* RIGHT: Sound Effects */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="sfx-enabled" className="flex items-center gap-2">
|
||||
<Volume2 className="h-4 w-4 text-muted-foreground" />
|
||||
Sound Effects
|
||||
</Label>
|
||||
<div className="h-9 flex items-center">
|
||||
<Switch
|
||||
id="sfx-enabled"
|
||||
checked={tempSettings.sfxEnabled}
|
||||
onCheckedChange={(checked) => setTempSettings(prev => ({ ...prev, sfxEnabled: checked }))}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter className="gap-2 sm:justify-between">
|
||||
<Button variant="outline" onClick={handleReset} className="gap-1.5">
|
||||
<RotateCcw className="h-4 w-4" />
|
||||
Reset to Default
|
||||
</Button>
|
||||
<div className="flex gap-2">
|
||||
<Button variant="outline" onClick={handleCancel}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={handleSave} className="gap-1.5">
|
||||
<Save className="h-4 w-4" />
|
||||
Save Changes
|
||||
</Button>
|
||||
</div>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import { Spinner } from "@/components/ui/spinner";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { getSettings, getSettingsWithDefaults, saveSettings, resetToDefaultSettings, applyThemeMode, applyFont, FONT_OPTIONS, type Settings as SettingsType, type FontFamily, type GifQuality, type GifResolution } from "@/lib/settings";
|
||||
import { themes, applyTheme } from "@/lib/themes";
|
||||
import { SelectFolder, IsFFmpegInstalled, DownloadFFmpeg } from "../../wailsjs/go/main/App";
|
||||
import { SelectFolder, IsFFmpegInstalled, DownloadFFmpeg, IsExifToolInstalled, DownloadExifTool } from "../../wailsjs/go/main/App";
|
||||
import { toastWithSound as toast } from "@/lib/toast-with-sound";
|
||||
|
||||
export function SettingsPage() {
|
||||
@@ -24,6 +24,8 @@ export function SettingsPage() {
|
||||
const [isDark, setIsDark] = useState(document.documentElement.classList.contains('dark'));
|
||||
const [ffmpegInstalled, setFfmpegInstalled] = useState(false);
|
||||
const [downloadingFFmpeg, setDownloadingFFmpeg] = useState(false);
|
||||
const [exiftoolInstalled, setExiftoolInstalled] = useState(false);
|
||||
const [downloadingExifTool, setDownloadingExifTool] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
applyThemeMode(savedSettings.themeMode);
|
||||
@@ -60,8 +62,9 @@ export function SettingsPage() {
|
||||
};
|
||||
loadDefaults();
|
||||
|
||||
// Check FFmpeg status
|
||||
// Check FFmpeg and ExifTool status
|
||||
IsFFmpegInstalled().then(setFfmpegInstalled);
|
||||
IsExifToolInstalled().then(setExiftoolInstalled);
|
||||
}, []);
|
||||
|
||||
const handleSave = () => {
|
||||
@@ -106,6 +109,20 @@ export function SettingsPage() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDownloadExifTool = async () => {
|
||||
setDownloadingExifTool(true);
|
||||
try {
|
||||
await DownloadExifTool();
|
||||
setExiftoolInstalled(true);
|
||||
toast.success("ExifTool downloaded successfully");
|
||||
} catch (error) {
|
||||
toast.error("Failed to download ExifTool");
|
||||
console.error("Error downloading ExifTool:", error);
|
||||
} finally {
|
||||
setDownloadingExifTool(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h1 className="text-2xl font-bold">Settings</h1>
|
||||
@@ -210,6 +227,49 @@ export function SettingsPage() {
|
||||
|
||||
{/* Right Column */}
|
||||
<div className="space-y-4">
|
||||
{/* Metadata Embedding */}
|
||||
<div className="space-y-2">
|
||||
<Label className="flex items-center gap-2">
|
||||
Metadata Embedding
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Info className="h-3.5 w-3.5 text-muted-foreground cursor-help" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top">
|
||||
<p>ExifTool is required to embed tweet URL and original filename into media file metadata</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</Label>
|
||||
<div className="h-9 flex items-center">
|
||||
{exiftoolInstalled ? (
|
||||
<div className="flex items-center gap-2 text-sm text-green-600 dark:text-green-400">
|
||||
<Check className="h-4 w-4" />
|
||||
Installed
|
||||
</div>
|
||||
) : (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-9"
|
||||
onClick={handleDownloadExifTool}
|
||||
disabled={downloadingExifTool}
|
||||
>
|
||||
{downloadingExifTool ? (
|
||||
<>
|
||||
<Spinner />
|
||||
Downloading...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download className="h-4 w-4" />
|
||||
Download ExifTool
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* GIF Conversion */}
|
||||
<div className="space-y-2">
|
||||
<Label className="flex items-center gap-2">
|
||||
@@ -301,6 +361,73 @@ export function SettingsPage() {
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Proxy */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="proxy" className="flex items-center gap-2">
|
||||
Proxy
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Info className="h-3.5 w-3.5 text-muted-foreground cursor-help" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top">
|
||||
<p>If download fails, try using a proxy server</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</Label>
|
||||
<InputWithContext
|
||||
id="proxy"
|
||||
value={tempSettings.proxy || ""}
|
||||
onChange={(e) => setTempSettings((prev) => ({ ...prev, proxy: e.target.value }))}
|
||||
placeholder="http://proxy:port or socks5://proxy:port (optional)"
|
||||
className="w-[90%]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Fetch Timeout */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="fetch-timeout" className="flex items-center gap-2">
|
||||
Fetch Timeout
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Info className="h-3.5 w-3.5 text-muted-foreground cursor-help" />
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="top">
|
||||
<p>Timeout in seconds. Fetch stops automatically when reached</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</Label>
|
||||
<InputWithContext
|
||||
id="fetch-timeout"
|
||||
type="number"
|
||||
value={tempSettings.fetchTimeout || 60}
|
||||
onChange={(e) => {
|
||||
const inputValue = e.target.value;
|
||||
// Allow empty input for user to type freely
|
||||
if (inputValue === "") {
|
||||
setTempSettings((prev) => ({ ...prev, fetchTimeout: 60 }));
|
||||
return;
|
||||
}
|
||||
const value = parseInt(inputValue, 10);
|
||||
// Allow any number while typing (including values less than min during typing)
|
||||
// Validation will happen on blur
|
||||
if (!isNaN(value)) {
|
||||
setTempSettings((prev) => ({ ...prev, fetchTimeout: value }));
|
||||
}
|
||||
}}
|
||||
onBlur={(e) => {
|
||||
// Validate and clamp value on blur
|
||||
const value = parseInt(e.target.value, 10);
|
||||
if (isNaN(value) || value < 30) {
|
||||
setTempSettings((prev) => ({ ...prev, fetchTimeout: 30 }));
|
||||
} else if (value > 900) {
|
||||
setTempSettings((prev) => ({ ...prev, fetchTimeout: 900 }));
|
||||
}
|
||||
}}
|
||||
placeholder="60"
|
||||
className="w-[20%]"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
import * as React from "react"
|
||||
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
|
||||
import { CheckIcon, ChevronRightIcon } from "lucide-react"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
const DropdownMenu = DropdownMenuPrimitive.Root
|
||||
|
||||
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger
|
||||
|
||||
const DropdownMenuGroup = DropdownMenuPrimitive.Group
|
||||
|
||||
const DropdownMenuPortal = DropdownMenuPrimitive.Portal
|
||||
|
||||
const DropdownMenuSub = DropdownMenuPrimitive.Sub
|
||||
|
||||
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup
|
||||
|
||||
const DropdownMenuSubTrigger = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean
|
||||
}
|
||||
>(({ className, inset, children, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.SubTrigger
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",
|
||||
inset && "pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto h-4 w-4" />
|
||||
</DropdownMenuPrimitive.SubTrigger>
|
||||
))
|
||||
DropdownMenuSubTrigger.displayName =
|
||||
DropdownMenuPrimitive.SubTrigger.displayName
|
||||
|
||||
const DropdownMenuSubContent = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.SubContent
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"z-50 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
DropdownMenuSubContent.displayName =
|
||||
DropdownMenuPrimitive.SubContent.displayName
|
||||
|
||||
const DropdownMenuContent = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
|
||||
>(({ className, sideOffset = 4, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
ref={ref}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
))
|
||||
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName
|
||||
|
||||
const DropdownMenuItem = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
|
||||
inset?: boolean
|
||||
}
|
||||
>(({ className, inset, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Item
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50",
|
||||
inset && "pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName
|
||||
|
||||
const DropdownMenuCheckboxItem = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
|
||||
>(({ className, children, checked, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.CheckboxItem
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon className="h-4 w-4" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.CheckboxItem>
|
||||
))
|
||||
DropdownMenuCheckboxItem.displayName =
|
||||
DropdownMenuPrimitive.CheckboxItem.displayName
|
||||
|
||||
const DropdownMenuRadioItem = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
|
||||
>(({ className, children, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.RadioItem
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon className="h-4 w-4" />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.RadioItem>
|
||||
))
|
||||
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName
|
||||
|
||||
const DropdownMenuLabel = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {
|
||||
inset?: boolean
|
||||
}
|
||||
>(({ className, inset, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Label
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"px-2 py-1.5 text-sm font-semibold",
|
||||
inset && "pl-8",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName
|
||||
|
||||
const DropdownMenuSeparator = React.forwardRef<
|
||||
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
|
||||
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
|
||||
>(({ className, ...props }, ref) => (
|
||||
<DropdownMenuPrimitive.Separator
|
||||
ref={ref}
|
||||
className={cn("-mx-1 my-1 h-px bg-muted", className)}
|
||||
{...props}
|
||||
/>
|
||||
))
|
||||
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName
|
||||
|
||||
const DropdownMenuShortcut = ({
|
||||
className,
|
||||
...props
|
||||
}: React.HTMLAttributes<HTMLSpanElement>) => {
|
||||
return (
|
||||
<span
|
||||
className={cn("ml-auto text-xs tracking-widest opacity-60", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
DropdownMenuShortcut.displayName = "DropdownMenuShortcut"
|
||||
|
||||
export {
|
||||
DropdownMenu,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuRadioGroup,
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import type { TwitterResponse, TimelineEntry, AccountInfo } from "@/types/api";
|
||||
|
||||
const FETCH_STATE_KEY = "twitter_fetch_state";
|
||||
const CURSOR_STATE_KEY = "twitter_cursor_state"; // Lightweight cursor-only storage
|
||||
|
||||
export interface FetchState {
|
||||
username: string;
|
||||
@@ -166,6 +167,63 @@ export function stateToResponse(state: FetchState): TwitterResponse | null {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Save cursor only (lightweight, can be called every batch)
|
||||
*/
|
||||
export function saveCursor(username: string, cursor: string): void {
|
||||
try {
|
||||
const allCursors = getAllCursors();
|
||||
allCursors[username.toLowerCase()] = {
|
||||
cursor,
|
||||
lastUpdated: Date.now(),
|
||||
};
|
||||
localStorage.setItem(CURSOR_STATE_KEY, JSON.stringify(allCursors));
|
||||
} catch (error) {
|
||||
console.error("Failed to save cursor:", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cursor for username from localStorage (lightweight, synchronous)
|
||||
*/
|
||||
export function getCursor(username: string): string | null {
|
||||
try {
|
||||
const allCursors = getAllCursors();
|
||||
return allCursors[username.toLowerCase()]?.cursor || null;
|
||||
} catch (error) {
|
||||
console.error("Failed to get cursor:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all cursors
|
||||
*/
|
||||
function getAllCursors(): Record<string, { cursor: string; lastUpdated: number }> {
|
||||
try {
|
||||
const stored = localStorage.getItem(CURSOR_STATE_KEY);
|
||||
if (stored) {
|
||||
return JSON.parse(stored);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to parse cursors:", error);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear cursor for username
|
||||
*/
|
||||
export function clearCursor(username: string): void {
|
||||
try {
|
||||
const allCursors = getAllCursors();
|
||||
delete allCursors[username.toLowerCase()];
|
||||
localStorage.setItem(CURSOR_STATE_KEY, JSON.stringify(allCursors));
|
||||
} catch (error) {
|
||||
console.error("Failed to clear cursor:", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge new timeline entries with existing (deduplicate by tweet_id)
|
||||
*/
|
||||
|
||||
@@ -12,6 +12,8 @@ export interface Settings {
|
||||
sfxEnabled: boolean;
|
||||
gifQuality: GifQuality;
|
||||
gifResolution: GifResolution;
|
||||
proxy: string; // Proxy URL (e.g., http://proxy:port or socks5://proxy:port). Empty to use system proxy or no proxy.
|
||||
fetchTimeout: number; // Fetch timeout in seconds. Default: 60 seconds.
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: Settings = {
|
||||
@@ -22,6 +24,8 @@ export const DEFAULT_SETTINGS: Settings = {
|
||||
sfxEnabled: true,
|
||||
gifQuality: "fast",
|
||||
gifResolution: "high",
|
||||
proxy: "",
|
||||
fetchTimeout: 60, // Default: 60 seconds
|
||||
};
|
||||
|
||||
export const FONT_OPTIONS: { value: FontFamily; label: string; fontFamily: string }[] = [
|
||||
|
||||
@@ -27,6 +27,8 @@ export interface TimelineEntry {
|
||||
reply_count?: number;
|
||||
source?: string;
|
||||
verified?: boolean;
|
||||
original_filename?: string; // Original filename from API
|
||||
author_username?: string; // Username of tweet author (for bookmarks and likes)
|
||||
}
|
||||
|
||||
export interface ExtractMetadata {
|
||||
|
||||
Reference in new issue
Block a user