This commit is contained in:
429Enjoyer committed 2026-05-13 08:49:42 +07:00
1 parent 84b067ebd4
commit e67d09a248
47 files changed
+3688 -958

No files matched your search

+165 -86
View File
@@ -1,10 +1,13 @@
import { useState, useEffect, useRef, useCallback } from "react";
import { TooltipProvider } from "@/components/ui/tooltip";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { getSettings, applyThemeMode, applyFont } from "@/lib/settings";
import { applyTheme } from "@/lib/themes";
import { compareVersionNumbers } from "@/lib/version";
import { toastWithSound as toast } from "@/lib/toast-with-sound";
import { logger } from "@/lib/logger";
import { saveFetchState, getFetchState, clearFetchState, getResumableInfo, stateToResponse, mergeTimelines, saveCursor, getCursor, clearCursor, type FetchState, } from "@/lib/fetch-state";
import { saveFetchState, getFetchState, clearFetchState, getResumableInfo, mergeTimelines, saveCursor, getCursor, clearCursor, type FetchState, } from "@/lib/fetch-state";
import { TitleBar } from "@/components/TitleBar";
import { Sidebar, type PageType } from "@/components/Sidebar";
import { Header } from "@/components/Header";
@@ -13,10 +16,11 @@ import { MediaList } from "@/components/MediaList";
import { DatabaseView } from "@/components/DatabaseView";
import { SettingsPage } from "@/components/SettingsPage";
import { DebugLoggerPage } from "@/components/DebugLoggerPage";
import { SupportPage } from "@/components/SupportPage";
import { DependencySetupDialog } from "@/components/DependencySetupDialog";
import type { HistoryItem } from "@/components/FetchHistory";
import type { TwitterResponse } from "@/types/api";
import { ExtractTimeline, ExtractDateRange, SaveAccountToDBWithStatus, CleanupExtractorProcesses, GetAllAccountsFromDB } from "../wailsjs/go/main/App";
import { ExtractTimeline, ExtractDateRange, SaveAccountToDBWithStatus, CleanupExtractorProcesses, GetAllAccountsFromDB, GetSavedAccountFromDB } from "../wailsjs/go/main/App";
const HISTORY_KEY = "twitter_media_fetch_history";
const MAX_HISTORY = 10;
const CURRENT_VERSION = __APP_VERSION__;
@@ -24,6 +28,28 @@ const BATCH_SIZE = 200;
function formatNumberWithComma(num: number): string {
return num.toLocaleString();
}
function normalizeTimeline(timeline: TwitterResponse["timeline"] | null | undefined): TwitterResponse["timeline"] {
return Array.isArray(timeline) ? timeline : [];
}
function normalizeTwitterResponse(data: TwitterResponse): TwitterResponse {
return {
...data,
timeline: normalizeTimeline(data.timeline),
};
}
async function loadSavedAccountResponse(username: string, mediaType: string): Promise<TwitterResponse | null> {
try {
const savedResponseJSON = await GetSavedAccountFromDB(username, mediaType);
return normalizeTwitterResponse(JSON.parse(savedResponseJSON) as TwitterResponse);
}
catch {
return null;
}
}
function App() {
const [currentPage, setCurrentPage] = useState<PageType>("main");
const [username, setUsername] = useState("");
@@ -48,6 +74,10 @@ function App() {
const [isFetchingAll, setIsFetchingAll] = useState(false);
const [searchMode, setSearchMode] = useState<FetchMode>("public");
const [searchPrivateType, setSearchPrivateType] = useState<PrivateType>("bookmarks");
const [hasUnsavedSettings, setHasUnsavedSettings] = useState(false);
const [pendingPageChange, setPendingPageChange] = useState<PageType | null>(null);
const [showUnsavedChangesDialog, setShowUnsavedChangesDialog] = useState(false);
const [resetSettingsFn, setResetSettingsFn] = useState<(() => void) | null>(null);
const stopAllRef = useRef(false);
const accountTimersRef = useRef<Map<string, number>>(new Map());
const accountStartTimesRef = useRef<Map<string, number>>(new Map());
@@ -83,7 +113,7 @@ function App() {
const settings = getSettings();
applyThemeMode(settings.themeMode);
applyTheme(settings.theme);
applyFont(settings.fontFamily);
applyFont(settings.fontFamily, settings.customFonts);
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
const handleChange = () => {
const currentSettings = getSettings();
@@ -107,7 +137,7 @@ function App() {
if (data.published_at) {
setReleaseDate(data.published_at);
}
if (latestVersion && latestVersion > CURRENT_VERSION) {
if (latestVersion && compareVersionNumbers(latestVersion, CURRENT_VERSION) > 0) {
setHasUpdate(true);
}
}
@@ -188,7 +218,8 @@ function App() {
try {
await CleanupExtractorProcesses();
}
catch {
catch (cleanupError) {
console.error("Failed to stop extractor processes:", cleanupError);
}
}, []);
useEffect(() => {
@@ -254,7 +285,8 @@ function App() {
try {
await CleanupExtractorProcesses();
}
catch {
catch (cleanupError) {
console.error("Failed to clean extractor processes before fetch:", cleanupError);
}
const fetchTarget = isBookmarks
? "your bookmarks"
@@ -262,6 +294,7 @@ function App() {
? "your likes"
: `@${username}`;
const cleanUsername = isBookmarks ? "bookmarks" : isLikes ? "likes" : username.trim();
const requestedMediaType = mediaType || "all";
let existingState: FetchState | null = null;
let cursor: string | undefined;
let allTimeline: TwitterResponse["timeline"] = [];
@@ -270,17 +303,18 @@ function App() {
existingState = getFetchState(cleanUsername);
if (existingState && existingState.cursor && !existingState.completed) {
cursor = existingState.cursor;
allTimeline = existingState.timeline;
accountInfo = existingState.accountInfo;
logger.info(`Resuming ${fetchTarget} from ${allTimeline.length} items...`);
if (accountInfo) {
setResult({
account_info: accountInfo,
timeline: allTimeline,
total_urls: allTimeline.length,
metadata: { new_entries: 0, page: 0, batch_size: 0, has_more: true },
});
const savedResponse = await loadSavedAccountResponse(cleanUsername, existingState.mediaType || requestedMediaType);
if (!savedResponse) {
clearFetchState(cleanUsername);
clearCursor(cleanUsername);
toast.error("Resume data is no longer available");
setLoading(false);
return;
}
allTimeline = savedResponse.timeline;
accountInfo = savedResponse.account_info;
logger.info(`Resuming ${fetchTarget} from ${existingState.totalFetched} items...`);
setResult(savedResponse);
}
else {
toast.error("No resumable fetch found");
@@ -314,21 +348,13 @@ function App() {
auth_token: authToken.trim(),
start_date: startDate,
end_date: endDate,
media_filter: mediaType || "all",
media_filter: requestedMediaType,
retweets: retweets || false,
});
finalData = JSON.parse(response);
finalData = normalizeTwitterResponse(JSON.parse(response) as TwitterResponse);
if (finalData && finalData.account_info) {
try {
await SaveAccountToDBWithStatus(finalData.account_info.name, finalData.account_info.nick, finalData.account_info.profile_image, finalData.total_urls, JSON.stringify(finalData), mediaType || "all", finalData.cursor || "", finalData.completed ?? true);
}
catch (err) {
reportDatabaseSaveError("date range data", err);
}
}
if (finalData && finalData.account_info) {
try {
await SaveAccountToDBWithStatus(finalData.account_info.name, finalData.account_info.nick, finalData.account_info.profile_image, finalData.total_urls, JSON.stringify(finalData), mediaType || "all", finalData.cursor || "", finalData.completed ?? true);
await SaveAccountToDBWithStatus(finalData.account_info.name, finalData.account_info.nick, finalData.account_info.profile_image, finalData.total_urls, JSON.stringify(finalData), requestedMediaType, finalData.cursor || "", finalData.completed ?? true);
}
catch (err) {
reportDatabaseSaveError("date range data", err);
@@ -361,12 +387,9 @@ function App() {
saveFetchState({
username: cleanUsername,
cursor: cursor || "",
timeline: allTimeline,
accountInfo: accountInfo,
totalFetched: allTimeline.length,
completed: false,
authToken: authToken.trim(),
mediaType: mediaType || "all",
mediaType: requestedMediaType,
retweets: retweets || false,
timelineType: timelineType,
});
@@ -386,7 +409,7 @@ function App() {
completed: false,
};
try {
await SaveAccountToDBWithStatus(accountInfo.name, accountInfo.nick, accountInfo.profile_image, allTimeline.length, JSON.stringify(timeoutResponse), mediaType || "all", cursor || "", false);
await SaveAccountToDBWithStatus(accountInfo.name, accountInfo.nick, accountInfo.profile_image, allTimeline.length, JSON.stringify(timeoutResponse), requestedMediaType, cursor || "", false);
logger.info(`Saved ${allTimeline.length} items before timeout`);
}
catch (err) {
@@ -404,11 +427,11 @@ function App() {
timeline_type: timelineType,
batch_size: batchSize,
page: page,
media_type: mediaType || "all",
media_type: requestedMediaType,
retweets: retweets || false,
cursor: cursor,
});
const data: TwitterResponse = JSON.parse(response);
const data = normalizeTwitterResponse(JSON.parse(response) as TwitterResponse);
if (!accountInfo && data.account_info) {
accountInfo = data.account_info;
if (isBookmarks) {
@@ -454,12 +477,9 @@ function App() {
saveFetchState({
username: cleanUsername,
cursor: cursor || "",
timeline: allTimeline,
accountInfo: accountInfo,
totalFetched: allTimeline.length,
completed: !hasMore,
authToken: authToken.trim(),
mediaType: mediaType || "all",
mediaType: requestedMediaType,
retweets: retweets || false,
timelineType: timelineType,
});
@@ -480,7 +500,7 @@ function App() {
completed: !hasMore,
};
try {
await SaveAccountToDBWithStatus(accountInfo.name, accountInfo.nick, accountInfo.profile_image, allTimeline.length, JSON.stringify(currentResponse), mediaType || "all", cursor || "", !hasMore);
await SaveAccountToDBWithStatus(accountInfo.name, accountInfo.nick, accountInfo.profile_image, allTimeline.length, JSON.stringify(currentResponse), requestedMediaType, cursor || "", !hasMore);
}
catch (err) {
reportDatabaseSaveError("fetch progress", err);
@@ -523,7 +543,7 @@ function App() {
}
if (!useDateRange) {
try {
await SaveAccountToDBWithStatus(finalData.account_info.name, finalData.account_info.nick, finalData.account_info.profile_image, finalData.total_urls, JSON.stringify(finalData), mediaType || "all", finalData.cursor || "", finalData.completed ?? true);
await SaveAccountToDBWithStatus(finalData.account_info.name, finalData.account_info.nick, finalData.account_info.profile_image, finalData.total_urls, JSON.stringify(finalData), requestedMediaType, finalData.cursor || "", finalData.completed ?? true);
}
catch (err) {
reportDatabaseSaveError("final fetch status", err);
@@ -547,14 +567,14 @@ function App() {
toast.error("Failed to fetch media");
}
const savedState = getFetchState(cleanUsername);
if (savedState && savedState.timeline.length > 0) {
const partialResponse = stateToResponse(savedState);
if (savedState && savedState.totalFetched > 0) {
const partialResponse = await loadSavedAccountResponse(cleanUsername, savedState.mediaType || requestedMediaType);
if (partialResponse) {
setResult(partialResponse);
setResumeInfo({ canResume: true, mediaCount: savedState.timeline.length });
toast.info(`Saved ${formatNumberWithComma(savedState.timeline.length)} items - can resume`);
setResumeInfo({ canResume: true, mediaCount: savedState.totalFetched });
toast.info(`Saved ${formatNumberWithComma(savedState.totalFetched)} items - can resume`);
try {
await SaveAccountToDBWithStatus(partialResponse.account_info.name, partialResponse.account_info.nick, partialResponse.account_info.profile_image, partialResponse.total_urls, JSON.stringify(partialResponse), mediaType || "all", savedState.cursor || "", false);
await SaveAccountToDBWithStatus(partialResponse.account_info.name, partialResponse.account_info.nick, partialResponse.account_info.profile_image, partialResponse.total_urls, JSON.stringify(partialResponse), savedState.mediaType || requestedMediaType, savedState.cursor || "", false);
}
catch (dbErr) {
reportDatabaseSaveError("partial fetch data", dbErr);
@@ -575,13 +595,14 @@ function App() {
const handleClearResume = () => {
if (username.trim()) {
clearFetchState(username.trim());
clearCursor(username.trim());
setResumeInfo(null);
toast.info("Resume data cleared");
}
};
const handleLoadFromDB = (responseJSON: string, loadedUsername: string) => {
try {
const data: TwitterResponse = JSON.parse(responseJSON);
const data = normalizeTwitterResponse(JSON.parse(responseJSON) as TwitterResponse);
setResult(data);
setUsername(loadedUsername);
setCurrentPage("main");
@@ -603,6 +624,7 @@ function App() {
toast.success(`Loaded @${loadedUsername} from database`);
}
catch (error) {
console.error("Failed to parse saved data:", error);
toast.error("Failed to parse saved data");
}
};
@@ -677,26 +699,27 @@ function App() {
toast.success(`Imported ${formatNumberWithComma(accounts.length)} account(s)`);
}
catch (error) {
console.error("Failed to read imported account list:", error);
toast.error("Failed to read file");
}
};
input.click();
};
const handleFetchAll = async () => {
const handleFetchAll = async (authToken: string) => {
if (multipleAccounts.length === 0) {
toast.error("No accounts to fetch");
return;
}
setIsFetchingAll(true);
stopAllRef.current = false;
const PUBLIC_AUTH_TOKEN_KEY = "twitter_public_auth_token";
const authToken = localStorage.getItem(PUBLIC_AUTH_TOKEN_KEY) || "";
if (!authToken.trim()) {
toast.error("Please enter your auth token");
setIsFetchingAll(false);
return;
}
const settings = getSettings();
const selectedMediaType = settings.mediaType || "all";
setFetchedMediaType(selectedMediaType);
const timeoutSeconds = settings.fetchTimeout || 60;
setMultipleAccounts((prev) => prev.map((acc) => ({
...acc,
@@ -708,7 +731,7 @@ function App() {
error: undefined,
showDiff: false,
})));
let currentAccounts = [...multipleAccounts];
const currentAccounts = [...multipleAccounts];
for (let i = 0; i < currentAccounts.length; i++) {
if (stopAllRef.current) {
break;
@@ -785,12 +808,9 @@ function App() {
saveFetchState({
username: cleanUsername,
cursor: cursor || "",
timeline: allTimeline,
accountInfo: accountInfo,
totalFetched: allTimeline.length,
completed: false,
authToken: authToken.trim(),
mediaType: fetchedMediaType || "all",
mediaType: selectedMediaType,
retweets: false,
timelineType: "timeline",
});
@@ -809,7 +829,7 @@ function App() {
},
cursor: cursor,
completed: false,
}), fetchedMediaType || "all", cursor || "", false);
}), selectedMediaType, cursor || "", false);
}
catch (err) {
reportDatabaseSaveError("multi-account timeout state", err);
@@ -823,11 +843,11 @@ function App() {
timeline_type: "timeline",
batch_size: batchSizeMultiple,
page: page,
media_type: fetchedMediaType || "all",
media_type: selectedMediaType,
retweets: false,
cursor: cursor,
});
const data: TwitterResponse = JSON.parse(response);
const data = normalizeTwitterResponse(JSON.parse(response) as TwitterResponse);
if (!accountInfo && data.account_info) {
accountInfo = data.account_info;
}
@@ -864,12 +884,9 @@ function App() {
saveFetchState({
username: cleanUsername,
cursor: cursor || "",
timeline: allTimeline,
accountInfo: accountInfo,
totalFetched: allTimeline.length,
completed: !hasMore,
authToken: authToken.trim(),
mediaType: fetchedMediaType || "all",
mediaType: selectedMediaType,
retweets: false,
timelineType: "timeline",
});
@@ -890,7 +907,7 @@ function App() {
},
cursor: cursor,
completed: !hasMore,
}), fetchedMediaType || "all", cursor || "", !hasMore);
}), selectedMediaType, cursor || "", !hasMore);
}
catch (err) {
reportDatabaseSaveError("multi-account progress", err);
@@ -1004,17 +1021,44 @@ function App() {
CleanupExtractorProcesses().catch(() => { });
toast.info("Stopped account fetch");
};
const handleRetryAccount = async (accountId: string) => {
const handlePageChange = (page: PageType) => {
if (currentPage === "settings" && hasUnsavedSettings && page !== "settings") {
setPendingPageChange(page);
setShowUnsavedChangesDialog(true);
return;
}
setCurrentPage(page);
};
const handleDiscardChanges = () => {
setShowUnsavedChangesDialog(false);
if (resetSettingsFn) {
resetSettingsFn();
}
const savedSettings = getSettings();
applyThemeMode(savedSettings.themeMode);
applyTheme(savedSettings.theme);
applyFont(savedSettings.fontFamily, savedSettings.customFonts);
setHasUnsavedSettings(false);
if (pendingPageChange) {
setCurrentPage(pendingPageChange);
setPendingPageChange(null);
}
};
const handleCancelNavigation = () => {
setShowUnsavedChangesDialog(false);
setPendingPageChange(null);
};
const handleRetryAccount = async (accountId: string, authToken: string) => {
const account = multipleAccounts.find((acc) => acc.id === accountId);
if (!account)
return;
const PUBLIC_AUTH_TOKEN_KEY = "twitter_public_auth_token";
const authToken = localStorage.getItem(PUBLIC_AUTH_TOKEN_KEY) || "";
if (!authToken.trim()) {
toast.error("Please enter your auth token");
return;
}
const retrySettings = getSettings();
const selectedMediaType = retrySettings.mediaType || fetchedMediaType || "all";
setFetchedMediaType(selectedMediaType);
const isSingleModeRetry = retrySettings.fetchMode === "single";
const batchSizeRetry = isSingleModeRetry ? 0 : BATCH_SIZE;
const cleanUsername = account.username.trim();
@@ -1026,12 +1070,22 @@ function App() {
existingState = getFetchState(cleanUsername);
if (existingState && existingState.cursor && !existingState.completed) {
cursor = existingState.cursor;
allTimeline = existingState.timeline;
if (existingState.accountInfo) {
accountInfo = existingState.accountInfo;
const savedResponse = await loadSavedAccountResponse(cleanUsername, existingState.mediaType || selectedMediaType);
if (savedResponse) {
allTimeline = savedResponse.timeline;
accountInfo = savedResponse.account_info;
previousMediaCount = existingState.totalFetched;
logger.info(`Resuming @${cleanUsername} from ${existingState.totalFetched} items...`);
}
else {
clearFetchState(cleanUsername);
clearCursor(cleanUsername);
logger.info(`Saved retry state for @${cleanUsername} was missing. Starting from beginning...`);
cursor = undefined;
allTimeline = [];
accountInfo = null;
previousMediaCount = 0;
}
previousMediaCount = existingState.timeline.length;
logger.info(`Resuming @${cleanUsername} from ${allTimeline.length} items...`);
}
else {
if (!cursor) {
@@ -1044,7 +1098,7 @@ function App() {
else {
try {
const accounts = await GetAllAccountsFromDB();
const dbAccount = accounts.find((acc) => acc.username.toLowerCase() === cleanUsername.toLowerCase());
const dbAccount = accounts.find((acc) => acc.username.toLowerCase() === cleanUsername.toLowerCase() && (acc.media_type || "all") === selectedMediaType);
if (dbAccount?.cursor) {
cursor = dbAccount.cursor;
previousMediaCount = account.mediaCount || 0;
@@ -1130,11 +1184,11 @@ function App() {
timeline_type: "timeline",
batch_size: batchSizeRetry,
page: page,
media_type: fetchedMediaType || "all",
media_type: selectedMediaType,
retweets: false,
cursor: cursor,
});
const data: TwitterResponse = JSON.parse(response);
const data = normalizeTwitterResponse(JSON.parse(response) as TwitterResponse);
if (!accountInfo && data.account_info) {
accountInfo = data.account_info;
}
@@ -1165,12 +1219,9 @@ function App() {
saveFetchState({
username: cleanUsername,
cursor: cursor || "",
timeline: allTimeline,
accountInfo: accountInfo,
totalFetched: allTimeline.length,
completed: !hasMore,
authToken: authToken.trim(),
mediaType: fetchedMediaType || "all",
mediaType: selectedMediaType,
retweets: false,
timelineType: "timeline",
});
@@ -1197,7 +1248,7 @@ function App() {
},
cursor: cursor,
completed: !hasMore,
}), fetchedMediaType || "all", cursor || "", !hasMore);
}), selectedMediaType, cursor || "", !hasMore);
}
catch (err) {
reportDatabaseSaveError("retry progress", err);
@@ -1271,11 +1322,13 @@ function App() {
const renderPage = () => {
switch (currentPage) {
case "settings":
return <SettingsPage />;
return <SettingsPage onUnsavedChangesChange={setHasUnsavedSettings} onResetRequest={setResetSettingsFn}/>;
case "debug":
return <DebugLoggerPage />;
case "database":
return (<DatabaseView onBack={() => setCurrentPage("main")} onLoadAccount={handleLoadFromDB} onUpdateSelected={handleUpdateSelected}/>);
case "support":
return <SupportPage />;
default:
return (<>
<Header version={CURRENT_VERSION} hasUpdate={hasUpdate} releaseDate={releaseDate}/>
@@ -1294,17 +1347,43 @@ function App() {
}
};
return (<TooltipProvider>
<div className="min-h-screen bg-background flex flex-col">
<div className="h-screen overflow-hidden bg-background">
<DependencySetupDialog />
<TitleBar />
<Sidebar currentPage={currentPage} onPageChange={setCurrentPage}/>
<div className="flex-1 ml-14 mt-10 p-4 md:p-8">
<div className="max-w-5xl mx-auto">
{renderPage()}
<Sidebar currentPage={currentPage} onPageChange={handlePageChange}/>
<div id="app-content-scroll" className="fixed top-10 right-0 bottom-0 left-14 overflow-y-auto overflow-x-hidden">
<div className="p-4 md:p-8">
<div className="max-w-5xl mx-auto">
{renderPage()}
</div>
</div>
</div>
<Dialog open={showUnsavedChangesDialog} onOpenChange={(open) => {
if (open) {
setShowUnsavedChangesDialog(true);
return;
}
handleCancelNavigation();
}}>
<DialogContent className="sm:max-w-[425px] [&>button]:hidden">
<DialogHeader>
<DialogTitle>Unsaved Changes</DialogTitle>
<DialogDescription>
You have unsaved changes in Settings. If you leave now, your changes will be lost.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button variant="outline" onClick={handleCancelNavigation}>
Cancel
</Button>
<Button variant="destructive" onClick={handleDiscardChanges}>
Discard Changes
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
</TooltipProvider>);
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 903 KiB

+13
View File
@@ -0,0 +1,13 @@
<svg width="241" height="194" viewBox="0 0 241 194" fill="none" xmlns="http://www.w3.org/2000/svg">
<mask id="mask0_1_219" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="-1" y="0" width="242" height="194">
<path d="M240.469 0.958984H-0.00585938V193.918H240.469V0.958984Z" fill="white"/>
</mask>
<g mask="url(#mask0_1_219)">
<path d="M96.1344 193.911C61.1312 193.911 32.6597 178.256 15.9721 149.829C1.19788 124.912 -0.00585938 97.9229 -0.00585938 67.7662C-0.00585938 49.8876 5.37293 34.3215 15.5413 22.7466C24.8861 12.1157 38.1271 5.22907 52.8317 3.35378C70.2858 1.14271 91.9848 0.958984 114.545 0.958984C151.259 0.958984 161.63 1.4088 176.075 2.85328C195.29 4.76026 211.458 11.932 222.824 23.5955C234.368 35.4428 240.469 51.2624 240.469 69.3627V72.9994C240.469 103.885 219.821 129.733 191.046 136.759C188.898 141.827 186.237 146.871 183.089 151.837L183.006 151.964C172.869 167.632 149.042 193.918 103.401 193.918H96.1281L96.1344 193.911Z" fill="white"/>
<path d="M174.568 17.9772C160.927 16.6151 151.38 16.1589 114.552 16.1589C90.908 16.1589 70.9008 16.387 54.7644 18.4334C33.3949 21.164 15.2058 37.5285 15.2058 67.7674C15.2058 98.0066 16.796 121.422 29.0741 142.107C42.9425 165.751 66.1302 178.707 96.1412 178.707H103.414C140.242 178.707 160.25 159.156 170.253 143.698C174.574 136.874 177.754 130.058 179.801 123.234C205.947 120.96 225.27 99.3624 225.27 72.9941V69.3577C225.27 40.9432 206.631 21.164 174.574 17.9772H174.568Z" fill="white"/>
<path d="M15.1975 67.7674C15.1975 37.5285 33.3866 21.164 54.7559 18.4334C70.8987 16.387 90.906 16.1589 114.544 16.1589C151.372 16.1589 160.919 16.6151 174.559 17.9772C206.617 21.1576 225.255 40.937 225.255 69.3577V72.9941C225.255 99.3687 205.932 120.966 179.786 123.234C177.74 130.058 174.559 136.874 170.238 143.698C160.235 159.156 140.228 178.707 103.4 178.707H96.1264C66.1155 178.707 42.9277 165.751 29.0595 142.107C16.7814 121.422 15.1912 98.4563 15.1912 67.7674" fill="#202020"/>
<path d="M32.2469 67.9899C32.2469 97.3168 34.0654 116.184 43.6127 133.689C54.5225 153.924 74.3018 161.653 96.8117 161.653H103.857C133.411 161.653 147.736 147.329 155.693 134.829C159.558 128.462 162.966 121.417 164.784 112.547L166.147 106.864H174.332C192.521 106.864 208.208 92.09 208.208 73.2166V69.8082C208.208 48.6669 195.024 37.5228 172.058 34.7987C159.102 33.6646 151.372 33.2084 114.538 33.2084C89.7602 33.2084 72.0272 33.4364 58.6152 35.4828C39.7483 38.2134 32.2407 48.8951 32.2407 67.9899" fill="white"/>
<path d="M166.158 83.6801C166.158 86.4107 168.204 88.4572 171.841 88.4572C183.435 88.4572 189.802 81.8619 189.802 70.9523C189.802 60.0427 183.435 53.2195 171.841 53.2195C168.204 53.2195 166.158 55.2657 166.158 57.9963V83.6866V83.6801Z" fill="#202020"/>
<path d="M54.5321 82.3198C54.5321 95.732 62.0332 107.326 71.5807 116.424C77.9478 122.562 87.9515 128.93 94.7685 133.022C96.8147 134.157 98.8611 134.841 101.136 134.841C103.866 134.841 106.134 134.157 107.959 133.022C114.782 128.93 124.779 122.562 130.919 116.424C140.694 107.332 148.195 95.7383 148.195 82.3198C148.195 67.7673 137.286 54.8115 121.599 54.8115C112.28 54.8115 105.912 59.5882 101.136 66.1772C96.8147 59.582 90.2259 54.8115 80.9001 54.8115C64.9855 54.8115 54.5256 67.7673 54.5256 82.3198" fill="#FF5A16"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

+152 -90
View File
@@ -1,4 +1,4 @@
import { useState, useEffect, useRef } from "react";
import { useState, useEffect, useRef, useCallback, useMemo } from "react";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { Input } from "@/components/ui/input";
@@ -15,7 +15,7 @@ import { Trash2, FileInput, FileOutput, Pencil, Tag, Shuffle, X, XCircle, Downlo
import { toastWithSound as toast } from "@/lib/toast-with-sound";
import { getSettings } from "@/lib/settings";
import { openExternal } from "@/lib/utils";
import { GetAllAccountsFromDB, GetAccountFromDB, DeleteAccountFromDB, SaveAccountToDB, ExportAccountJSON, ExportAccountsTXT, UpdateAccountGroup, GetAllGroups, DownloadMediaWithMetadata, StopDownload, CheckFolderExists, OpenFolder, GetFolderPath, } from "../../wailsjs/go/main/App";
import { GetAllAccountsFromDB, GetAccountFromDB, DeleteAccountFromDB, SaveAccountToDB, ExportAccountJSON, ExportAccountsTXT, UpdateAccountGroup, GetAllGroups, DownloadMediaWithMetadata, StopDownload, CheckFoldersExist, OpenFolder, GetFolderPath, } from "../../wailsjs/go/main/App";
import { EventsOn, EventsOff } from "../../wailsjs/runtime/runtime";
import { main } from "../../wailsjs/go/models";
interface DownloadProgress {
@@ -66,6 +66,11 @@ interface DatabaseViewProps {
}
const INITIAL_LOAD_COUNT = 12;
const LOAD_MORE_COUNT = 12;
function getContentScrollElement(): HTMLElement | null {
return document.getElementById("app-content-scroll");
}
export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewProps) {
const [accounts, setAccounts] = useState<AccountListItem[]>([]);
const [loading, setLoading] = useState(true);
@@ -92,26 +97,16 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
const stopBulkDownloadRef = useRef(false);
const loadMoreRef = useRef<HTMLDivElement>(null);
const [folderExistence, setFolderExistence] = useState<Map<number, boolean>>(new Map());
const checkFolderExistence = async (accountsList: AccountListItem[]) => {
const settings = getSettings();
const basePath = settings.downloadPath;
if (!basePath)
return;
const folderMap = new Map<number, boolean>();
for (const account of accountsList) {
let folderName = account.username;
if (account.username === "bookmarks") {
folderName = "My Bookmarks";
}
else if (account.username === "likes") {
folderName = "My Likes";
}
const exists = await CheckFolderExists(basePath, folderName);
folderMap.set(account.id, exists);
const getFolderNameForAccount = (username: string) => {
if (username === "bookmarks") {
return "My Bookmarks";
}
setFolderExistence(folderMap);
if (username === "likes") {
return "My Likes";
}
return username;
};
const loadAccounts = async () => {
const loadAccounts = useCallback(async () => {
setLoading(true);
try {
const data = await GetAllAccountsFromDB();
@@ -120,9 +115,6 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
if (groupsData) {
setGroups(groupsData.map((g) => ({ name: g.name || "", color: g.color || "" })));
}
if (data && data.length > 0) {
checkFolderExistence(data);
}
}
catch (error) {
console.error("Failed to load accounts:", error);
@@ -131,19 +123,24 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
finally {
setLoading(false);
}
};
useEffect(() => {
loadAccounts();
}, []);
useEffect(() => {
void loadAccounts();
}, [loadAccounts]);
useEffect(() => {
setVisibleCount(INITIAL_LOAD_COUNT);
}, [gridView, searchQuery, filterGroup, filterMediaType, accountViewMode, sortOrder]);
useEffect(() => {
const scrollElement = getContentScrollElement();
if (!scrollElement) {
return;
}
const handleScroll = () => {
setShowScrollTop(window.scrollY > 300);
setShowScrollTop(scrollElement.scrollTop > 300);
};
window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
handleScroll();
scrollElement.addEventListener("scroll", handleScroll);
return () => scrollElement.removeEventListener("scroll", handleScroll);
}, []);
useEffect(() => {
const unsubscribe = EventsOn("download-progress", (progress: DownloadProgress) => {
@@ -155,72 +152,116 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
};
}, []);
const scrollToTop = () => {
window.scrollTo({ top: 0, behavior: "smooth" });
getContentScrollElement()?.scrollTo({ top: 0, behavior: "smooth" });
};
const isPrivateAccount = (username: string) => username === "bookmarks" || username === "likes";
const publicAccounts = accounts.filter((acc) => !isPrivateAccount(acc.username));
const privateAccounts = accounts.filter((acc) => isPrivateAccount(acc.username));
const baseAccounts = accountViewMode === "public" ? publicAccounts : privateAccounts;
const filteredAccounts = baseAccounts
.filter((acc) => {
if (searchQuery) {
const query = searchQuery.toLowerCase();
const matchesUsername = acc.username.toLowerCase().includes(query);
const matchesName = acc.name.toLowerCase().includes(query);
if (!matchesUsername && !matchesName)
return false;
}
if (filterGroup !== "all") {
if (filterGroup === "ungrouped" && acc.group_name)
return false;
if (filterGroup !== "ungrouped" && acc.group_name !== filterGroup)
return false;
}
if (filterMediaType !== "all") {
const accMediaType = acc.media_type || "all";
if (filterMediaType === "all-media") {
if (accMediaType !== "all")
const currentDownloadPath = getSettings().downloadPath || "";
const publicAccounts = useMemo(() => accounts.filter((acc) => !isPrivateAccount(acc.username)), [accounts]);
const privateAccounts = useMemo(() => accounts.filter((acc) => isPrivateAccount(acc.username)), [accounts]);
const filteredAccounts = useMemo(() => {
const baseAccounts = accountViewMode === "public" ? publicAccounts : privateAccounts;
return baseAccounts
.filter((acc) => {
if (searchQuery) {
const query = searchQuery.toLowerCase();
const matchesUsername = acc.username.toLowerCase().includes(query);
const matchesName = acc.name.toLowerCase().includes(query);
if (!matchesUsername && !matchesName)
return false;
}
else {
if (accMediaType !== filterMediaType)
if (filterGroup !== "all") {
if (filterGroup === "ungrouped" && acc.group_name)
return false;
if (filterGroup !== "ungrouped" && acc.group_name !== filterGroup)
return false;
}
}
return true;
})
.sort((a, b) => {
switch (sortOrder) {
case "newest": {
const dateA = new Date(a.last_fetched).getTime();
const dateB = new Date(b.last_fetched).getTime();
return dateB - dateA;
if (filterMediaType !== "all") {
const accMediaType = acc.media_type || "all";
if (filterMediaType === "all-media") {
if (accMediaType !== "all")
return false;
}
else if (accMediaType !== filterMediaType) {
return false;
}
}
case "oldest": {
const dateA = new Date(a.last_fetched).getTime();
const dateB = new Date(b.last_fetched).getTime();
return dateA - dateB;
return true;
})
.sort((a, b) => {
switch (sortOrder) {
case "newest": {
const dateA = new Date(a.last_fetched).getTime();
const dateB = new Date(b.last_fetched).getTime();
return dateB - dateA;
}
case "oldest": {
const dateA = new Date(a.last_fetched).getTime();
const dateB = new Date(b.last_fetched).getTime();
return dateA - dateB;
}
case "username-asc":
return a.username.toLowerCase().localeCompare(b.username.toLowerCase());
case "username-desc":
return b.username.toLowerCase().localeCompare(a.username.toLowerCase());
case "followers-high":
return (b.followers_count || 0) - (a.followers_count || 0);
case "followers-low":
return (a.followers_count || 0) - (b.followers_count || 0);
case "posts-high":
return (b.statuses_count || 0) - (a.statuses_count || 0);
case "posts-low":
return (a.statuses_count || 0) - (b.statuses_count || 0);
case "media-high":
return (b.total_media || 0) - (a.total_media || 0);
case "media-low":
return (a.total_media || 0) - (b.total_media || 0);
default:
return 0;
}
case "username-asc":
return a.username.toLowerCase().localeCompare(b.username.toLowerCase());
case "username-desc":
return b.username.toLowerCase().localeCompare(a.username.toLowerCase());
case "followers-high":
return (b.followers_count || 0) - (a.followers_count || 0);
case "followers-low":
return (a.followers_count || 0) - (b.followers_count || 0);
case "posts-high":
return (b.statuses_count || 0) - (a.statuses_count || 0);
case "posts-low":
return (a.statuses_count || 0) - (b.statuses_count || 0);
case "media-high":
return (b.total_media || 0) - (a.total_media || 0);
case "media-low":
return (a.total_media || 0) - (b.total_media || 0);
default:
return 0;
});
}, [accountViewMode, filterGroup, filterMediaType, privateAccounts, publicAccounts, searchQuery, sortOrder]);
const visibleAccounts = useMemo(() => filteredAccounts.slice(0, visibleCount), [filteredAccounts, visibleCount]);
const visibleAccountsKey = visibleAccounts
.map((account) => `${account.id}:${account.username}`)
.join("|");
useEffect(() => {
const basePath = currentDownloadPath;
if (!basePath) {
setFolderExistence(new Map());
return;
}
});
if (visibleAccounts.length === 0) {
return;
}
let active = true;
const loadVisibleFolderExistence = async () => {
try {
const folderNames = visibleAccounts.map((account) => getFolderNameForAccount(account.username));
const results = await CheckFoldersExist(basePath, folderNames);
if (!active) {
return;
}
setFolderExistence((prev) => {
const next = new Map(prev);
for (const account of visibleAccounts) {
next.set(account.id, results[getFolderNameForAccount(account.username)] ?? false);
}
return next;
});
}
catch (error) {
console.error("Failed to check visible folders:", error);
}
};
void loadVisibleFolderExistence();
return () => {
active = false;
};
}, [currentDownloadPath, visibleAccounts, visibleAccountsKey]);
useEffect(() => {
const currentRef = loadMoreRef.current;
if (!currentRef)
@@ -247,9 +288,10 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
await UpdateAccountGroup(editingAccount.id, editGroupName, editGroupColor);
toast.success(`Updated group for @${editingAccount.username}`);
setEditingAccount(null);
loadAccounts();
await loadAccounts();
}
catch (error) {
console.error("Failed to update group:", error);
toast.error("Failed to update group");
}
};
@@ -257,9 +299,10 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
try {
await DeleteAccountFromDB(id);
toast.success(`Deleted @${username}`);
loadAccounts();
await loadAccounts();
}
catch (error) {
console.error(`Failed to delete @${username}:`, error);
toast.error("Failed to delete account");
}
};
@@ -269,6 +312,7 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
onLoadAccount(responseJSON, username);
}
catch (error) {
console.error(`Failed to load @${username} from database:`, error);
toast.error("Failed to load account data");
}
};
@@ -286,6 +330,7 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
await OpenFolder(folderPath);
}
catch (error) {
console.error(`Failed to open folder for @${username}:`, error);
toast.error("Failed to open folder");
}
};
@@ -335,7 +380,13 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
proxy: settings.proxy || "",
});
const response = await DownloadMediaWithMetadata(request);
if (response.success) {
if (response.cancelled) {
const message = response.downloaded > 0 || response.skipped > 0
? `Download stopped for @${username} after ${response.downloaded + response.skipped} items`
: `Download stopped for @${username}`;
toast.info(message);
}
else if (response.success) {
const parts: string[] = [];
if (response.downloaded > 0) {
parts.push(`${response.downloaded} file${response.downloaded !== 1 ? 's' : ''} downloaded`);
@@ -448,6 +499,11 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
proxy: settings.proxy || "",
});
const response = await DownloadMediaWithMetadata(request);
if (response.cancelled) {
toast.info(`Stopped while downloading @${account.username}`);
stopBulkDownloadRef.current = true;
break;
}
if (response.success) {
totalDownloaded += response.downloaded;
totalSkipped += response.skipped || 0;
@@ -521,6 +577,7 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
toast.success(`Exported ${exported} account(s) to ${outputDir}\\twitterxmediabatchdownloader_backups`);
}
catch (error) {
console.error("Failed to export JSON backups:", error);
toast.error("Failed to export");
}
};
@@ -537,6 +594,7 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
toast.success(`Exported ${formatNumberWithComma(idsToExport.length)} account(s) to ${outputDir}\\twitterxmediabatchdownloader_backups\\twitterxmediabatchdownloader_multiple.txt`);
}
catch (error) {
console.error("Failed to export TXT backup:", error);
toast.error("Failed to export");
}
};
@@ -782,9 +840,10 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
toast.success(`Deleted ${formatNumberWithComma(idsToDelete.length)} account${idsToDelete.length !== 1 ? 's' : ''}`);
setClearAllDialogOpen(false);
setSelectedIds(new Set());
loadAccounts();
await loadAccounts();
}
catch (error) {
console.error("Failed to delete selected accounts:", error);
toast.error("Failed to delete accounts");
}
}}>
@@ -993,6 +1052,7 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
toast.success(`Exported @${account.username}`);
}
catch (error) {
console.error(`Failed to export @${account.username}:`, error);
toast.error("Failed to export");
}
}}>
@@ -1081,6 +1141,7 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
toast.success(`Exported @${account.username}`);
}
catch (error) {
console.error(`Failed to export @${account.username}:`, error);
toast.error("Failed to export");
}
}}>
@@ -1209,6 +1270,7 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
toast.success(`Exported @${account.username} to ${outputDir}\\twitterxmediabatchdownloader_backups`);
}
catch (error) {
console.error(`Failed to export @${account.username}:`, error);
toast.error("Failed to export");
}
}}>
+1 -2
View File
@@ -18,14 +18,13 @@ function formatTime(date: Date): string {
});
}
export function DebugLoggerPage() {
const [logs, setLogs] = useState<LogEntry[]>([]);
const [logs, setLogs] = useState<LogEntry[]>(() => logger.getLogs());
const [copied, setCopied] = useState(false);
const scrollRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const unsubscribe = logger.subscribe(() => {
setLogs(logger.getLogs());
});
setLogs(logger.getLogs());
return () => {
unsubscribe();
};
@@ -4,17 +4,31 @@ import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
import { Spinner } from "@/components/ui/spinner";
import { toastWithSound as toast } from "@/lib/toast-with-sound";
import { Quit } from "../../wailsjs/runtime/runtime";
import { DownloadExtractor, IsExtractorInstalled } from "../../wailsjs/go/main/App";
interface DependencySetupDialogProps {
onInstalled?: () => void;
}
interface GithubReleaseResponse {
tag_name?: string;
}
const extractorReleaseAPIURL = "https://api.github.com/repos/afkarxyz/xtractor-binaries/releases/latest";
export function DependencySetupDialog({ onInstalled }: DependencySetupDialogProps) {
const [open, setOpen] = useState(false);
const [checking, setChecking] = useState(true);
const [downloading, setDownloading] = useState(false);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [releaseVersion, setReleaseVersion] = useState<string | null>(null);
const [releaseStatusMessage, setReleaseStatusMessage] = useState("Checking latest GitHub release...");
useEffect(() => {
let cancelled = false;
const abortController = new AbortController();
const checkDependency = async () => {
try {
const installed = await IsExtractorInstalled();
@@ -26,7 +40,7 @@ export function DependencySetupDialog({ onInstalled }: DependencySetupDialogProp
catch {
if (!cancelled) {
setOpen(true);
setErrorMessage("Couldn't verify the core dependency. You can install it now.");
setErrorMessage("Couldn't verify Xtractor. Download it to continue.");
}
}
finally {
@@ -35,48 +49,94 @@ export function DependencySetupDialog({ onInstalled }: DependencySetupDialogProp
}
}
};
checkDependency();
const loadReleaseInfo = async () => {
try {
const response = await fetch(extractorReleaseAPIURL, {
headers: {
Accept: "application/vnd.github+json",
},
signal: abortController.signal,
});
if (!response.ok) {
throw new Error(`GitHub release status ${response.status}`);
}
const release = (await response.json()) as GithubReleaseResponse;
const version = release.tag_name?.trim();
if (!version) {
throw new Error("Missing GitHub release tag");
}
if (!cancelled) {
setReleaseVersion(version);
setReleaseStatusMessage(`Latest GitHub release: ${version}`);
}
}
catch {
if (!cancelled && !abortController.signal.aborted) {
setReleaseVersion(null);
setReleaseStatusMessage("Latest GitHub release unavailable.");
}
}
};
void checkDependency();
void loadReleaseInfo();
return () => {
cancelled = true;
abortController.abort();
};
}, []);
const handleDownload = async () => {
setDownloading(true);
setErrorMessage(null);
try {
await DownloadExtractor();
setOpen(false);
toast.success("Core dependency installed");
toast.success("Xtractor installed");
onInstalled?.();
}
catch (error) {
const message = error instanceof Error ? error.message : String(error);
setErrorMessage(message || "Failed to download dependency.");
toast.error("Failed to download dependency");
setErrorMessage(message || "Failed to download Xtractor.");
toast.error("Failed to download Xtractor");
}
finally {
setDownloading(false);
}
};
const handleExit = () => {
if (!downloading) {
void Quit();
}
};
if (checking && !open) {
return null;
}
return (<Dialog open={open} onOpenChange={(nextOpen) => !downloading && setOpen(nextOpen)}>
<DialogContent className="max-w-xl [&>button]:hidden" showCloseButton={false}>
return (<Dialog open={open} onOpenChange={(nextOpen) => {
if (nextOpen) {
setOpen(true);
}
}}>
<DialogContent className="max-w-xl [&>button]:hidden" showCloseButton={false} onEscapeKeyDown={(event) => event.preventDefault()} onInteractOutside={(event) => event.preventDefault()}>
<DialogHeader>
<div className="mb-2 flex h-12 w-12 items-center justify-center rounded-2xl border bg-muted/50">
<Package className="h-6 w-6"/>
</div>
<DialogTitle>Download Core Dependency</DialogTitle>
<DialogDescription>
This app now uses a prebuilt xtractor binary from GitHub releases. Download it once so fetching can work on this device.
</DialogDescription>
<DialogTitle>Download Xtractor</DialogTitle>
<DialogDescription>Xtractor is required before you can use this app.</DialogDescription>
</DialogHeader>
<div className="space-y-3">
<div className="rounded-lg border bg-muted/40 p-3 text-sm text-muted-foreground">
The binary is stored in the app data folder and reused on the next launch. Optional tools like FFmpeg and ExifTool stay available in Settings.
</div>
<p className="text-sm text-muted-foreground">{releaseVersion ? `Latest GitHub release: ${releaseVersion}` : releaseStatusMessage}</p>
{errorMessage && (<div className="flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive">
<AlertCircle className="mt-0.5 h-4 w-4 shrink-0"/>
@@ -85,16 +145,16 @@ export function DependencySetupDialog({ onInstalled }: DependencySetupDialogProp
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setOpen(false)} disabled={downloading}>
Later
<Button variant="outline" onClick={handleExit} disabled={downloading}>
Exit App
</Button>
<Button onClick={handleDownload} disabled={downloading}>
{downloading ? (<>
<Spinner />
Downloading...
Downloading Xtractor...
</>) : (<>
<Download className="h-4 w-4"/>
Download Dependency
Download Xtractor
</>)}
</Button>
</DialogFooter>
+97 -47
View File
@@ -11,6 +11,7 @@ import type { TimelineEntry, AccountInfo } from "@/types/api";
import { logger } from "@/lib/logger";
import { toastWithSound as toast } from "@/lib/toast-with-sound";
import { getSettings } from "@/lib/settings";
import { getCachedDependencyStatus, getCachedMediaFolderStatus, setCachedDependencyStatus, setCachedMediaFolderStatus } from "@/lib/runtime-cache";
import { openExternal } from "@/lib/utils";
import { DownloadMediaWithMetadata, OpenFolder, IsFFmpegInstalled, ConvertGIFs, StopDownload, CheckFolderExists, CheckGifsFolderHasMP4 } from "../../wailsjs/go/main/App";
import { EventsOn, EventsOff } from "../../wailsjs/runtime/runtime";
@@ -32,9 +33,15 @@ interface MediaListProps {
fetchedMediaType?: string;
newMediaCount?: number | null;
}
const MEDIA_LIST_PAGE_SIZE = 30;
function getContentScrollElement(): HTMLElement | null {
return document.getElementById("app-content-scroll");
}
function getThumbnailUrl(url: string): string {
if (url.includes("video.twimg.com/tweet_video/")) {
const match = url.match(/tweet_video\/([^\/]+)\.mp4/);
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`;
@@ -161,7 +168,23 @@ function formatJoinDate(dateStr: string): string {
return dateStr;
}
}
function getAccountFolderName(accountInfo: AccountInfo): string {
if (accountInfo.nick === "My Bookmarks" || accountInfo.name === "bookmarks") {
return "My Bookmarks";
}
if (accountInfo.nick === "My Likes" || accountInfo.name === "likes") {
return "My Likes";
}
return accountInfo.name;
}
export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType = "all", newMediaCount = null, }: MediaListProps) {
const settings = getSettings();
const folderName = getAccountFolderName(accountInfo);
const cachedMediaFolderStatus = settings.downloadPath
? getCachedMediaFolderStatus(settings.downloadPath, folderName)
: null;
const [selectedItems, setSelectedItems] = useState<Set<number>>(new Set());
const [sortBy, setSortBy] = useState<string>("date-desc");
const [filterType, setFilterType] = useState<string>("all");
@@ -170,23 +193,28 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
const [downloadProgress, setDownloadProgress] = useState<DownloadProgress | null>(null);
const [hasDownloaded, setHasDownloaded] = useState(false);
const [isConverting, setIsConverting] = useState(false);
const [ffmpegInstalled, setFfmpegInstalled] = useState(false);
const [ffmpegInstalled, setFfmpegInstalled] = useState(() => getCachedDependencyStatus("ffmpeg").installed ?? false);
const [showScrollTop, setShowScrollTop] = useState(false);
const [folderExists, setFolderExists] = useState(false);
const [gifsFolderHasMP4, setGifsFolderHasMP4] = useState(false);
const [folderExists, setFolderExists] = useState(cachedMediaFolderStatus?.folderExists ?? false);
const [gifsFolderHasMP4, setGifsFolderHasMP4] = useState(cachedMediaFolderStatus?.gifsFolderHasMP4 ?? false);
const [previewIndex, setPreviewIndex] = useState<number | null>(null);
const [downloadedItems, setDownloadedItems] = useState<Set<string>>(new Set());
const [failedItems, setFailedItems] = useState<Set<string>>(new Set());
const [skippedItems, setSkippedItems] = useState<Set<string>>(new Set());
const [downloadingItem, setDownloadingItem] = useState<string | null>(null);
const [visibleCount, setVisibleCount] = useState<number>(10);
const [visibleCount, setVisibleCount] = useState<number>(MEDIA_LIST_PAGE_SIZE);
const loadMoreRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const scrollElement = getContentScrollElement();
if (!scrollElement) {
return;
}
const handleScroll = () => {
setShowScrollTop(window.scrollY > 300);
setShowScrollTop(scrollElement.scrollTop > 300);
};
window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
handleScroll();
scrollElement.addEventListener("scroll", handleScroll);
return () => scrollElement.removeEventListener("scroll", handleScroll);
}, []);
const filteredTimeline = useMemo(() => {
let filtered = [...timeline];
@@ -221,55 +249,50 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
return filtered;
}, [timeline, filterType, sortBy]);
useEffect(() => {
setVisibleCount(10);
setVisibleCount(MEDIA_LIST_PAGE_SIZE);
}, [filteredTimeline.length]);
useEffect(() => {
const checkFoldersAndFFmpeg = async () => {
const settings = getSettings();
const basePath = settings.downloadPath;
const installed = await IsFFmpegInstalled();
setCachedDependencyStatus("ffmpeg", { installed });
setFfmpegInstalled(installed);
if (!basePath || !accountInfo.name)
return;
let folderName = accountInfo.name;
if (accountInfo.nick === "My Bookmarks" || accountInfo.name === "bookmarks") {
folderName = "My Bookmarks";
}
else if (accountInfo.nick === "My Likes" || accountInfo.name === "likes") {
folderName = "My Likes";
}
const exists = await CheckFolderExists(basePath, folderName);
const hasMP4 = exists ? await CheckGifsFolderHasMP4(basePath, folderName) : false;
setCachedMediaFolderStatus(basePath, folderName, {
folderExists: exists,
gifsFolderHasMP4: hasMP4,
});
setFolderExists(exists);
if (exists) {
const hasMP4 = await CheckGifsFolderHasMP4(basePath, folderName);
setGifsFolderHasMP4(hasMP4);
}
else {
setGifsFolderHasMP4(false);
}
setGifsFolderHasMP4(hasMP4);
};
checkFoldersAndFFmpeg();
}, [accountInfo.name, accountInfo.nick, hasDownloaded]);
}, [accountInfo.name, accountInfo.nick, folderName, hasDownloaded]);
useEffect(() => {
if (!loadMoreRef.current)
const sentinel = loadMoreRef.current;
if (!sentinel || visibleCount >= filteredTimeline.length)
return;
const observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
if (entries.some((entry) => entry.isIntersecting)) {
setVisibleCount((prev) => {
const filteredLength = filteredTimeline.length;
return Math.min(prev + 10, filteredLength);
return Math.min(prev + MEDIA_LIST_PAGE_SIZE, filteredLength);
});
}
}, { threshold: 0.1 });
observer.observe(loadMoreRef.current);
}, {
rootMargin: "400px 0px",
threshold: 0,
});
observer.observe(sentinel);
return () => {
if (loadMoreRef.current) {
observer.unobserve(loadMoreRef.current);
}
observer.disconnect();
};
}, [filteredTimeline.length]);
}, [visibleCount, filteredTimeline.length]);
const scrollToTop = () => {
window.scrollTo({ top: 0, behavior: "smooth" });
getContentScrollElement()?.scrollTo({ top: 0, behavior: "smooth" });
};
const openPreview = (index: number) => {
setPreviewIndex(index);
@@ -442,7 +465,14 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
proxy: settings.proxy || "",
});
const response = await DownloadMediaWithMetadata(request);
if (response.success) {
if (response.cancelled) {
logger.info(response.message || "Download stopped");
toast.info(response.message || "Download stopped");
if (response.downloaded > 0 || response.skipped > 0) {
setHasDownloaded(true);
}
}
else if (response.success) {
const parts: string[] = [];
if (response.downloaded > 0) {
parts.push(`${response.downloaded} file${response.downloaded !== 1 ? 's' : ''} downloaded`);
@@ -464,7 +494,17 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
}
setHasDownloaded(true);
const installed = await IsFFmpegInstalled();
setCachedDependencyStatus("ffmpeg", { installed });
setFfmpegInstalled(installed);
if (settings.downloadPath) {
const hasMP4 = await CheckGifsFolderHasMP4(settings.downloadPath, folderName);
setCachedMediaFolderStatus(settings.downloadPath, folderName, {
folderExists: true,
gifsFolderHasMP4: hasMP4,
});
setFolderExists(true);
setGifsFolderHasMP4(hasMP4);
}
}
else {
logger.error(response.message);
@@ -551,15 +591,11 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
if (response.success) {
logger.success(`Converted ${response.converted} GIFs`);
toast.success(`${response.converted} GIFs converted`);
const settings = getSettings();
let folderName = accountInfo.name;
if (accountInfo.nick === "My Bookmarks" || accountInfo.name === "bookmarks") {
folderName = "My Bookmarks";
}
else if (accountInfo.nick === "My Likes" || accountInfo.name === "likes") {
folderName = "My Likes";
}
const hasMP4 = await CheckGifsFolderHasMP4(settings.downloadPath, folderName);
setCachedMediaFolderStatus(settings.downloadPath, folderName, {
folderExists: true,
gifsFolderHasMP4: hasMP4,
});
setGifsFolderHasMP4(hasMP4);
}
else {
@@ -800,7 +836,10 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
proxy: settings.proxy || "",
});
const response = await DownloadMediaWithMetadata(request);
if (response.success) {
if (response.cancelled) {
toast.info(response.message || "Download stopped");
}
else if (response.success) {
setHasDownloaded(true);
}
else {
@@ -870,7 +909,10 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
proxy: settings.proxy || "",
});
const response = await DownloadMediaWithMetadata(request);
if (response.success) {
if (response.cancelled) {
toast.info(response.message || "Download stopped");
}
else if (response.success) {
setHasDownloaded(true);
}
else {
@@ -946,8 +988,13 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
</div>)}
{visibleCount < filteredTimeline.length && (<div ref={loadMoreRef} className="h-20 flex items-center justify-center w-full">
{visibleCount < filteredTimeline.length && (<div ref={loadMoreRef} className="flex w-full flex-col items-center justify-center gap-3 py-6">
<Spinner />
<Button variant="outline" size="sm" onClick={() => {
setVisibleCount((prev) => Math.min(prev + MEDIA_LIST_PAGE_SIZE, filteredTimeline.length));
}}>
Load More ({formatNumberWithComma(Math.max(filteredTimeline.length - visibleCount, 0))} remaining)
</Button>
</div>)}
@@ -1035,7 +1082,10 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
proxy: settings.proxy || "",
});
const response = await DownloadMediaWithMetadata(request);
if (response.success) {
if (response.cancelled) {
toast.info(response.message || "Download stopped");
}
else if (response.success) {
setHasDownloaded(true);
}
else {
+83 -46
View File
@@ -2,7 +2,7 @@ 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 { XCircle, Calendar, StopCircle, Globe, Lock, Bookmark, Heart, Key, Eye, EyeOff, ChevronDown, ChevronUp, Info, RotateCcw, Trash2, Clock, CloudDownload, User, Users, FileText, Hourglass, CheckCircle, AlertCircle, } from "lucide-react";
import { XCircle, Calendar, StopCircle, Globe, Lock, Bookmark, Heart, Cookie, Eye, EyeOff, ChevronDown, ChevronUp, Info, RotateCcw, Trash2, Clock, CloudDownload, User, Users, FileText, Hourglass, CheckCircle, AlertCircle, SlidersHorizontal, } from "lucide-react";
import { Spinner } from "@/components/ui/spinner";
function formatNumberWithComma(num: number): string {
return num.toLocaleString();
@@ -10,16 +10,18 @@ function formatNumberWithComma(num: number): string {
import { Checkbox } from "@/components/ui/checkbox";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip";
import { Settings as SettingsIcon } from "lucide-react";
import { FetchHistory } from "@/components/FetchHistory";
import type { HistoryItem } from "@/components/FetchHistory";
import { cn } from "@/lib/utils";
import { getSettings, updateSettings, type FetchMode as SettingsFetchMode, type MediaType as SettingsMediaType } from "@/lib/settings";
import { GetStoredAuthToken, SetStoredAuthToken } from "../../wailsjs/go/main/App";
export type FetchMode = "public" | "private";
export type PrivateType = "bookmarks" | "likes";
export type FetchType = "single" | "multiple";
const PUBLIC_AUTH_TOKEN_KEY = "twitter_public_auth_token";
const PRIVATE_AUTH_TOKEN_KEY = "twitter_private_auth_token";
const LEGACY_PUBLIC_AUTH_TOKEN_KEY = "twitter_public_auth_token";
const LEGACY_PRIVATE_AUTH_TOKEN_KEY = "twitter_private_auth_token";
let sessionPublicAuthToken = "";
let sessionPrivateAuthToken = "";
export interface MultipleAccount {
id: string;
username: string;
@@ -59,10 +61,10 @@ interface SearchBarProps {
onFetchTypeChange?: (type: FetchType) => void;
multipleAccounts?: MultipleAccount[];
onImportFile?: () => void;
onFetchAll?: () => void;
onFetchAll?: (authToken: string) => void;
onStopAll?: () => void;
onStopAccount?: (accountId: string) => void;
onRetryAccount?: (accountId: string) => void;
onRetryAccount?: (accountId: string, authToken: string) => void;
isFetchingAll?: boolean;
mode?: FetchMode;
privateType?: PrivateType;
@@ -74,38 +76,77 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
const [endDate, setEndDate] = useState("");
const [mediaType, setMediaType] = useState<SettingsMediaType>(getSettings().mediaType);
const [retweets, setRetweets] = useState(getSettings().includeRetweets);
const [mode, setMode] = useState<FetchMode>(externalMode || "public");
const [privateType, setPrivateType] = useState<PrivateType>(externalPrivateType || "bookmarks");
useEffect(() => {
if (externalMode !== undefined) {
setMode(externalMode);
}
}, [externalMode]);
useEffect(() => {
if (externalPrivateType !== undefined) {
setPrivateType(externalPrivateType);
}
}, [externalPrivateType]);
const mode = externalMode || "public";
const privateType = externalPrivateType || "bookmarks";
const [showAuthInput, setShowAuthInput] = useState(false);
const [showAdvanced, setShowAdvanced] = useState(false);
const [currentFetchMode, setCurrentFetchMode] = useState<SettingsFetchMode>(getSettings().fetchMode);
const [publicAuthToken, setPublicAuthToken] = useState("");
const [privateAuthToken, setPrivateAuthToken] = useState("");
const [publicAuthToken, setPublicAuthToken] = useState(() => sessionPublicAuthToken || localStorage.getItem(LEGACY_PUBLIC_AUTH_TOKEN_KEY) || "");
const [privateAuthToken, setPrivateAuthToken] = useState(() => sessionPrivateAuthToken || localStorage.getItem(LEGACY_PRIVATE_AUTH_TOKEN_KEY) || "");
const [showPublicToken, setShowPublicToken] = useState(false);
const [showPrivateToken, setShowPrivateToken] = useState(false);
useEffect(() => {
const savedPublicToken = localStorage.getItem(PUBLIC_AUTH_TOKEN_KEY) || "";
const savedPrivateToken = localStorage.getItem(PRIVATE_AUTH_TOKEN_KEY) || "";
setPublicAuthToken(savedPublicToken);
setPrivateAuthToken(savedPrivateToken);
let active = true;
const syncStoredTokens = async () => {
const legacyPublicToken = localStorage.getItem(LEGACY_PUBLIC_AUTH_TOKEN_KEY) || "";
const legacyPrivateToken = localStorage.getItem(LEGACY_PRIVATE_AUTH_TOKEN_KEY) || "";
try {
if (legacyPublicToken) {
await SetStoredAuthToken("public", legacyPublicToken);
}
if (legacyPrivateToken) {
await SetStoredAuthToken("private", legacyPrivateToken);
}
}
catch (error) {
console.error("Failed to migrate legacy auth token:", error);
}
finally {
localStorage.removeItem(LEGACY_PUBLIC_AUTH_TOKEN_KEY);
localStorage.removeItem(LEGACY_PRIVATE_AUTH_TOKEN_KEY);
}
try {
const [storedPublicToken, storedPrivateToken] = await Promise.all([
GetStoredAuthToken("public"),
GetStoredAuthToken("private"),
]);
if (!active) {
return;
}
sessionPublicAuthToken = storedPublicToken || "";
setPublicAuthToken(storedPublicToken || "");
sessionPrivateAuthToken = storedPrivateToken || "";
setPrivateAuthToken(storedPrivateToken || "");
}
catch (error) {
console.error("Failed to load auth token from secure storage:", error);
}
};
void syncStoredTokens();
return () => {
active = false;
};
}, []);
const handlePublicTokenChange = (value: string) => {
const handlePublicTokenChange = async (value: string) => {
sessionPublicAuthToken = value;
setPublicAuthToken(value);
localStorage.setItem(PUBLIC_AUTH_TOKEN_KEY, value);
try {
await SetStoredAuthToken("public", value);
}
catch (error) {
console.error("Failed to store public auth token securely:", error);
}
};
const handlePrivateTokenChange = (value: string) => {
const handlePrivateTokenChange = async (value: string) => {
sessionPrivateAuthToken = value;
setPrivateAuthToken(value);
localStorage.setItem(PRIVATE_AUTH_TOKEN_KEY, value);
try {
await SetStoredAuthToken("private", value);
}
catch (error) {
console.error("Failed to store private auth token securely:", error);
}
};
const handleFetch = () => {
const authToken = mode === "public" ? publicAuthToken : privateAuthToken;
@@ -145,7 +186,6 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
</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"
@@ -154,7 +194,6 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
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"
@@ -193,7 +232,7 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
<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">
<Button variant="default" onClick={() => onFetchAll?.(publicAuthToken)} disabled={multipleAccounts.length === 0 || isFetchingAll} className="flex items-center gap-2 flex-1">
{isFetchingAll ? (<>
<Spinner />
Fetching All...
@@ -212,7 +251,7 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
{fetchType === "single" && (mode === "public" || isLikesMode) && (<div className="space-y-2">
<Label htmlFor="username">
{isLikesMode ? "Your Username" : "Username"}
X/Twitter URL or Username
</Label>
<div className="flex gap-2">
@@ -227,7 +266,7 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
<div className="flex items-center gap-2">
{loading && (<>
{(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]">
{(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-21.25">
<Clock className="h-3.5 w-3.5 text-muted-foreground shrink-0"/>
<span className="font-mono">
{remainingTime !== null && remainingTime >= 0
@@ -272,14 +311,14 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
<div className="flex items-center gap-2">
<button type="button" onClick={() => setShowAuthInput(!showAuthInput)} className="flex items-center gap-2 px-4 py-2 border rounded-lg text-sm font-medium hover:bg-muted/50 transition-colors cursor-pointer">
<Key className={cn("h-4 w-4", hasAuthToken ? "text-green-500" : "text-destructive")}/>
<Cookie className={cn("h-4 w-4", hasAuthToken ? "text-green-500" : "text-destructive")}/>
Auth Token
{showAuthInput ? <ChevronUp className="h-4 w-4"/> : <ChevronDown className="h-4 w-4"/>}
</button>
<button type="button" onClick={() => setShowAdvanced(!showAdvanced)} className="flex items-center gap-2 px-4 py-2 border rounded-lg text-sm font-medium hover:bg-muted/50 transition-colors cursor-pointer">
<SettingsIcon className="h-4 w-4"/>
<SlidersHorizontal className="h-4 w-4"/>
Advanced Settings
{showAdvanced ? <ChevronUp className="h-4 w-4"/> : <ChevronDown className="h-4 w-4"/>}
</button>
@@ -287,7 +326,6 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
{mode === "private" && fetchType === "single" && (<>
<button type="button" 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"
? "border-primary bg-primary/10 text-primary"
@@ -296,7 +334,6 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
My Bookmarks
</button>
<button type="button" 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"
? "border-primary bg-primary/10 text-primary"
@@ -310,7 +347,7 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
{isBookmarksMode && (<div className="flex items-center gap-2 ml-auto">
{loading && (<>
{(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]">
{(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-21.25">
<Clock className="h-3.5 w-3.5 text-muted-foreground shrink-0"/>
<span className="font-mono">
{remainingTime !== null && remainingTime >= 0
@@ -362,8 +399,8 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
? handlePublicTokenChange(e.target.value)
: handlePrivateTokenChange(e.target.value)} className="pr-10 bg-background"/>
<button type="button" className="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors" onClick={() => mode === "public"
? setShowPublicToken(!showPublicToken)
: setShowPrivateToken(!showPrivateToken)}>
? setShowPublicToken(!showPublicToken)
: setShowPrivateToken(!showPrivateToken)}>
{(mode === "public" ? showPublicToken : showPrivateToken) ? (<EyeOff className="h-4 w-4"/>) : (<Eye className="h-4 w-4"/>)}
</button>
</div>
@@ -439,9 +476,9 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
{useDateRange && (<>
<InputWithContext id="start-date" type="date" value={startDate} onChange={(e) => setStartDate(e.target.value)} className="w-[140px] h-8 bg-background"/>
<InputWithContext id="start-date" type="date" value={startDate} onChange={(e) => setStartDate(e.target.value)} className="w-35 h-8 bg-background"/>
<span className="text-sm text-muted-foreground">-</span>
<InputWithContext id="end-date" type="date" value={endDate} onChange={(e) => setEndDate(e.target.value)} className="w-[140px] h-8 bg-background"/>
<InputWithContext id="end-date" type="date" value={endDate} onChange={(e) => setEndDate(e.target.value)} className="w-35 h-8 bg-background"/>
</>)}
</>)}
</div>
@@ -483,7 +520,7 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
{fetchType === "multiple" && multipleAccounts.length > 0 && (<div className="space-y-2">
<p className="text-sm text-muted-foreground">Accounts to Fetch ({formatNumberWithComma(multipleAccounts.length)})</p>
<div className="space-y-2 max-h-[400px] overflow-y-auto">
<div className="space-y-2 max-h-100 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">
@@ -509,7 +546,7 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
</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]">
<div className="flex items-center gap-1.5 px-3 py-1.5 border rounded-md bg-muted/50 text-sm w-21.25">
<Clock className="h-3.5 w-3.5 text-muted-foreground shrink-0"/>
<span className="font-mono">
{account.remainingTime !== null && account.remainingTime >= 0
@@ -535,7 +572,7 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
<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">
<Button variant="outline" size="sm" onClick={() => onRetryAccount?.(account.id, publicAuthToken)} disabled={isFetchingAll} className="flex items-center gap-2">
<RotateCcw className="h-3.5 w-3.5"/>
Retry
</Button>
@@ -545,7 +582,7 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
<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">
<Button variant="outline" size="sm" onClick={() => onRetryAccount?.(account.id, publicAuthToken)} disabled={isFetchingAll} className="flex items-center gap-2">
<RotateCcw className="h-3.5 w-3.5"/>
Retry
</Button>
File diff suppressed because it is too large. Load diff
+63 -15
View File
@@ -1,18 +1,33 @@
import { useState } from "react";
import { HomeIcon } from "@/components/ui/home";
import { SettingsIcon } from "@/components/ui/settings";
import { ArchiveIcon } from "@/components/ui/archive";
import { TerminalIcon } from "@/components/ui/terminal";
import { GithubIcon } from "@/components/ui/github";
import { BugReportIcon } from "@/components/ui/bug-report-icon";
import { CoffeeIcon } from "@/components/ui/coffee";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Checkbox } from "@/components/ui/checkbox";
import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip";
import { Button } from "@/components/ui/button";
import { openExternal } from "@/lib/utils";
export type PageType = "main" | "settings" | "debug" | "database";
export type PageType = "main" | "settings" | "debug" | "database" | "support";
interface SidebarProps {
currentPage: PageType;
onPageChange: (page: PageType) => void;
}
export function Sidebar({ currentPage, onPageChange }: SidebarProps) {
const [isIssuesDialogOpen, setIsIssuesDialogOpen] = useState(false);
const [hasIssueAgreement, setHasIssueAgreement] = useState(false);
const handleIssuesDialogChange = (open: boolean) => {
setIsIssuesDialogOpen(open);
if (!open) {
setHasIssueAgreement(false);
}
};
const handleOpenIssues = () => {
openExternal("https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/issues");
handleIssuesDialogChange(false);
};
return (<div className="fixed left-0 top-0 h-full w-14 bg-card border-r border-border flex flex-col items-center py-14 z-30">
<div className="flex flex-col gap-2 flex-1">
@@ -55,7 +70,7 @@ export function Sidebar({ currentPage, onPageChange }: SidebarProps) {
<Tooltip delayDuration={0}>
<TooltipTrigger asChild>
<Button variant={currentPage === "debug" ? "secondary" : "ghost"} size="icon" className="h-10 w-10" onClick={() => onPageChange("debug")}>
<TerminalIcon size={20}/>
<TerminalIcon size={20} loop={true}/>
</Button>
</TooltipTrigger>
<TooltipContent side="right">
@@ -66,20 +81,53 @@ export function Sidebar({ currentPage, onPageChange }: SidebarProps) {
<div className="mt-auto flex flex-col gap-2">
<Dialog open={isIssuesDialogOpen} onOpenChange={handleIssuesDialogChange}>
<Tooltip delayDuration={0}>
<TooltipTrigger asChild>
<Button variant="ghost" size="icon" className="h-10 w-10 hover:bg-primary/10 hover:text-primary" onClick={() => setIsIssuesDialogOpen(true)}>
<BugReportIcon size={20} loop={true}/>
</Button>
</TooltipTrigger>
<TooltipContent side="right">
<p>Report Bugs or Request Features</p>
</TooltipContent>
</Tooltip>
<DialogContent className="max-w-xl">
<DialogHeader>
<DialogTitle>Before Opening GitHub Issues</DialogTitle>
<DialogDescription />
</DialogHeader>
<div className="space-y-4 text-sm">
<div className="rounded-lg border border-amber-500/40 bg-amber-500/10 p-4">
<p className="font-semibold text-amber-900 dark:text-amber-200">Important</p>
<p className="mt-1 text-amber-950/90 dark:text-amber-100/90">
Search existing issues first and use the issue template when opening a new bug report or feature request.
</p>
</div>
<label className="flex cursor-pointer items-center gap-3 rounded-lg border p-4">
<Checkbox className="shrink-0" checked={hasIssueAgreement} onCheckedChange={(checked) => setHasIssueAgreement(checked === true)}/>
<span className="leading-5 text-foreground/90">
I understand that I should use the issue template and avoid duplicate issues.
</span>
</label>
</div>
<DialogFooter className="sm:justify-between gap-2">
<Button variant="outline" onClick={() => handleIssuesDialogChange(false)}>
Cancel
</Button>
<Button disabled={!hasIssueAgreement} onClick={handleOpenIssues}>
Open Issues
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
<Tooltip delayDuration={0}>
<TooltipTrigger asChild>
<Button variant="ghost" size="icon" className="h-10 w-10" onClick={() => openExternal("https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/issues")}>
<GithubIcon size={20}/>
</Button>
</TooltipTrigger>
<TooltipContent side="right">
<p>Report Bug</p>
</TooltipContent>
</Tooltip>
<Tooltip delayDuration={0}>
<TooltipTrigger asChild>
<Button variant="ghost" size="icon" className="h-10 w-10" onClick={() => openExternal("https://ko-fi.com/afkarxyz")}>
<CoffeeIcon size={20}/>
<Button variant={currentPage === "support" ? "secondary" : "ghost"} size="icon" className="h-10 w-10" onClick={() => onPageChange("support")}>
<CoffeeIcon size={20} loop={true}/>
</Button>
</TooltipTrigger>
<TooltipContent side="right">
+59
View File
@@ -0,0 +1,59 @@
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { CircleCheck, Copy } from "lucide-react";
import { openExternal } from "@/lib/utils";
import KofiLogo from "@/assets/ko-fi.gif";
import KofiSvg from "@/assets/kofi_symbol.svg";
import UsdtBarcode from "@/assets/usdt.jpg";
const USDT_ADDRESS = "THnzAAwZgp2Sq5CAXLP2njQDhTvgZG9EWs";
export function SupportPage() {
const [copiedUsdt, setCopiedUsdt] = useState(false);
return (<div className="flex min-h-[70vh] items-center justify-center p-4">
<div className="flex w-full max-w-3xl flex-col items-stretch rounded-xl border bg-card shadow-sm md:flex-row">
<div className="flex flex-1 flex-col items-center justify-between space-y-6 border-b p-6 md:border-r md:border-b-0">
<div className="flex flex-col items-center space-y-4">
<div className="relative flex h-32 w-full items-center justify-center">
<img src={KofiLogo} className="pointer-events-none absolute w-72" alt="Ko-fi"/>
</div>
<h4 className="font-semibold text-foreground">Support via Ko-fi</h4>
<p className="px-4 text-center text-sm text-muted-foreground">
Enjoying the project? You can support ongoing development by buying me a coffee.
</p>
</div>
<Button className="h-10 w-full gap-2 bg-[#72a4f2] text-sm font-semibold text-white hover:bg-[#5f8cd6]" onClick={() => openExternal("https://ko-fi.com/afkarxyz")}>
<img src={KofiSvg} className="h-5 w-5 shrink-0" alt="" aria-hidden="true"/>
Support me on Ko-fi
</Button>
</div>
<div className="flex flex-1 flex-col items-center justify-between space-y-6 p-6">
<div className="flex w-full flex-col items-center space-y-4">
<div className="flex h-32 items-center justify-center">
<div className="rounded-xl border bg-white p-2 shadow-sm">
<img src={UsdtBarcode} className="h-24 w-24 object-contain" alt="USDT Barcode"/>
</div>
</div>
<h4 className="font-semibold text-foreground">USDT (TRC20)</h4>
<p className="px-4 text-center text-sm text-muted-foreground">
Crypto donations are also accepted. Scan the QR code or copy the address.
</p>
</div>
<div className="flex h-10 w-full items-center justify-between gap-2 rounded-lg border bg-muted/50 py-1.5 pr-1.5 pl-3">
<code className="truncate text-xs font-mono text-muted-foreground" title={USDT_ADDRESS}>
{USDT_ADDRESS}
</code>
<Button variant="ghost" size="icon" className="h-7 w-7 shrink-0 hover:bg-background" onClick={() => {
navigator.clipboard.writeText(USDT_ADDRESS);
setCopiedUsdt(true);
setTimeout(() => setCopiedUsdt(false), 500);
}}>
{copiedUsdt ? <CircleCheck className="h-3.5 w-3.5 text-green-500"/> : <Copy className="h-3.5 w-3.5"/>}
</Button>
</div>
</div>
</div>
</div>);
}
@@ -0,0 +1,131 @@
"use client";
import type { Transition, Variants } from "motion/react";
import { AnimatePresence, motion } from "motion/react";
import { useEffect, useState, type HTMLAttributes } from "react";
import { cn } from "@/lib/utils";
type ReportIconMode = "bug" | "bulb";
interface BugReportIconProps extends HTMLAttributes<HTMLDivElement> {
size?: number;
loop?: boolean;
}
const LOOP_INTERVAL_MS = 2200;
const GROUP_VARIANTS: Variants = {
hidden: {
opacity: 0,
},
visible: {
opacity: 1,
transition: {
duration: 0.2,
ease: [0, 0, 0.2, 1],
},
},
exit: {
opacity: 0,
transition: {
duration: 0.18,
ease: [0.4, 0, 1, 1],
},
},
};
const DRAW_VARIANTS: Variants = {
hidden: {
pathLength: 0,
opacity: 0,
},
visible: {
pathLength: 1,
opacity: 1,
},
exit: {
pathLength: 1,
opacity: 0,
},
};
function createDrawTransition(delay = 0, duration = 0.36): Transition {
return {
duration,
delay,
ease: [0.4, 0, 0.2, 1],
opacity: { delay },
};
}
function BugPaths() {
return (<>
<motion.path d="m8 2 1.88 1.88" transition={createDrawTransition(0)} variants={DRAW_VARIANTS}/>
<motion.path d="M14.12 3.88 16 2" transition={createDrawTransition(0.04)} variants={DRAW_VARIANTS}/>
<motion.path d="M9 7.13V6a3 3 0 1 1 6 0v1.13" transition={createDrawTransition(0.08)} variants={DRAW_VARIANTS}/>
<motion.path d="M6.53 9A4 4 0 0 1 3 5" transition={createDrawTransition(0.14)} variants={DRAW_VARIANTS}/>
<motion.path d="M17.47 9A4 4 0 0 0 21 5" transition={createDrawTransition(0.18)} variants={DRAW_VARIANTS}/>
<motion.path d="M12 20v-9" transition={createDrawTransition(0.24)} variants={DRAW_VARIANTS}/>
<motion.path d="M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z" transition={createDrawTransition(0.3, 0.42)} variants={DRAW_VARIANTS}/>
<motion.path d="M22 13h-4" transition={createDrawTransition(0.42)} variants={DRAW_VARIANTS}/>
<motion.path d="M6 13H2" transition={createDrawTransition(0.46)} variants={DRAW_VARIANTS}/>
<motion.path d="M21 21a4 4 0 0 0-3.81-4" transition={createDrawTransition(0.52)} variants={DRAW_VARIANTS}/>
<motion.path d="M3 21a4 4 0 0 1 3.81-4" transition={createDrawTransition(0.56)} variants={DRAW_VARIANTS}/>
</>);
}
function BulbPaths() {
return (<>
<motion.path d="M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5" transition={createDrawTransition(0, 0.46)} variants={DRAW_VARIANTS}/>
<motion.path d="M9 18h6" transition={createDrawTransition(0.16)} variants={DRAW_VARIANTS}/>
<motion.path d="M10 22h4" transition={createDrawTransition(0.24)} variants={DRAW_VARIANTS}/>
</>);
}
function ReportIconGroup({ mode }: { mode: ReportIconMode; }) {
return (<motion.g animate="visible" exit="exit" initial="hidden" variants={GROUP_VARIANTS}>
{mode === "bug" ? <BugPaths /> : <BulbPaths />}
</motion.g>);
}
function StaticBugIcon() {
return (<g>
<path d="m8 2 1.88 1.88"/>
<path d="M14.12 3.88 16 2"/>
<path d="M9 7.13V6a3 3 0 1 1 6 0v1.13"/>
<path d="M6.53 9A4 4 0 0 1 3 5"/>
<path d="M17.47 9A4 4 0 0 0 21 5"/>
<path d="M12 20v-9"/>
<path d="M14 7a4 4 0 0 1 4 4v3a6 6 0 0 1-12 0v-3a4 4 0 0 1 4-4z"/>
<path d="M22 13h-4"/>
<path d="M6 13H2"/>
<path d="M21 21a4 4 0 0 0-3.81-4"/>
<path d="M3 21a4 4 0 0 1 3.81-4"/>
</g>);
}
function BugReportIcon({ className, size = 28, loop = false, ...props }: BugReportIconProps) {
const [mode, setMode] = useState<ReportIconMode>("bug");
useEffect(() => {
if (!loop) {
return;
}
const intervalId = window.setInterval(() => {
setMode((currentMode) => currentMode === "bug" ? "bulb" : "bug");
}, LOOP_INTERVAL_MS);
return () => window.clearInterval(intervalId);
}, [loop]);
return (<div className={cn("flex items-center justify-center", className)} {...props}>
<svg fill="none" height={size} stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" viewBox="0 0 24 24" width={size} xmlns="http://www.w3.org/2000/svg">
{loop ? (<AnimatePresence>
<ReportIconGroup key={mode} mode={mode} />
</AnimatePresence>) : (<StaticBugIcon />)}
</svg>
</div>);
}
export { BugReportIcon };
+5 -4
View File
@@ -10,6 +10,7 @@ export interface CoffeeIconHandle {
}
interface CoffeeIconProps extends HTMLAttributes<HTMLDivElement> {
size?: number;
loop?: boolean;
}
const PATH_VARIANTS: Variants = {
normal: {
@@ -27,7 +28,7 @@ const PATH_VARIANTS: Variants = {
},
}),
};
const CoffeeIcon = forwardRef<CoffeeIconHandle, CoffeeIconProps>(({ onMouseEnter, onMouseLeave, className, size = 28, ...props }, ref) => {
const CoffeeIcon = forwardRef<CoffeeIconHandle, CoffeeIconProps>(({ onMouseEnter, onMouseLeave, className, size = 28, loop = false, ...props }, ref) => {
const controls = useAnimation();
const isControlledRef = useRef(false);
useImperativeHandle(ref, () => {
@@ -55,9 +56,9 @@ const CoffeeIcon = forwardRef<CoffeeIconHandle, CoffeeIconProps>(({ onMouseEnter
}, [controls, onMouseLeave]);
return (<div className={cn(className)} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave} {...props}>
<svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" style={{ overflow: 'visible' }}>
<motion.path d="M10 2v2" animate={controls} variants={PATH_VARIANTS} custom={0.2}/>
<motion.path d="M14 2v2" animate={controls} variants={PATH_VARIANTS} custom={0.4}/>
<motion.path d="M6 2v2" animate={controls} variants={PATH_VARIANTS} custom={0}/>
<motion.path d="M10 2v2" animate={loop ? 'animate' : controls} variants={PATH_VARIANTS} custom={0.2}/>
<motion.path d="M14 2v2" animate={loop ? 'animate' : controls} variants={PATH_VARIANTS} custom={0.4}/>
<motion.path d="M6 2v2" animate={loop ? 'animate' : controls} variants={PATH_VARIANTS} custom={0}/>
<path d="M16 8a1 1 0 0 1 1 1v8a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1h14a4 4 0 1 1 0 8h-1"/>
</svg>
</div>);
@@ -9,6 +9,13 @@ const InputWithContext = React.forwardRef<HTMLInputElement, InputWithContextProp
const inputRef = React.useRef<HTMLInputElement>(null);
const [hasSelection, setHasSelection] = React.useState(false);
const [canPaste, setCanPaste] = React.useState(false);
const [uncontrolledHasValue, setUncontrolledHasValue] = React.useState(() => {
const defaultValue = props.defaultValue;
return defaultValue !== undefined && defaultValue !== null && String(defaultValue).length > 0;
});
const hasValue = props.value !== undefined && props.value !== null
? String(props.value).length > 0
: uncontrolledHasValue;
React.useImperativeHandle(ref, () => inputRef.current as HTMLInputElement);
const updateSelectionState = () => {
const input = inputRef.current;
@@ -50,6 +57,9 @@ const InputWithContext = React.forwardRef<HTMLInputElement, InputWithContextProp
if (onValueChange) {
onValueChange(newValue);
}
if (props.value === undefined) {
setUncontrolledHasValue(newValue.length > 0);
}
input.focus();
}
catch (err) {
@@ -96,6 +106,9 @@ const InputWithContext = React.forwardRef<HTMLInputElement, InputWithContextProp
if (onValueChange) {
onValueChange(newValue);
}
if (props.value === undefined) {
setUncontrolledHasValue(newValue.length > 0);
}
input.focus();
await checkClipboard();
}
@@ -118,6 +131,9 @@ const InputWithContext = React.forwardRef<HTMLInputElement, InputWithContextProp
if (onValueChange) {
onValueChange(e.target.value);
}
if (props.value === undefined) {
setUncontrolledHasValue(e.target.value.length > 0);
}
};
return (<ContextMenu onOpenChange={(open) => {
if (open) {
@@ -144,7 +160,7 @@ const InputWithContext = React.forwardRef<HTMLInputElement, InputWithContextProp
<span className="ml-auto text-xs text-muted-foreground">Ctrl+V</span>
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem onSelect={handleSelectAll} disabled={!inputRef.current?.value || props.disabled}>
<ContextMenuItem onSelect={handleSelectAll} disabled={!hasValue || props.disabled}>
<Type className="mr-2 h-4 w-4"/>
Select All
<span className="ml-auto text-xs text-muted-foreground">Ctrl+A</span>
+3 -2
View File
@@ -10,6 +10,7 @@ export interface TerminalIconHandle {
}
interface TerminalIconProps extends HTMLAttributes<HTMLDivElement> {
size?: number;
loop?: boolean;
}
const LINE_VARIANTS: Variants = {
normal: { opacity: 1 },
@@ -22,7 +23,7 @@ const LINE_VARIANTS: Variants = {
},
},
};
const TerminalIcon = forwardRef<TerminalIconHandle, TerminalIconProps>(({ onMouseEnter, onMouseLeave, className, size = 28, ...props }, ref) => {
const TerminalIcon = forwardRef<TerminalIconHandle, TerminalIconProps>(({ onMouseEnter, onMouseLeave, className, size = 28, loop = false, ...props }, ref) => {
const controls = useAnimation();
const isControlledRef = useRef(false);
useImperativeHandle(ref, () => {
@@ -51,7 +52,7 @@ const TerminalIcon = forwardRef<TerminalIconHandle, TerminalIconProps>(({ onMous
return (<div className={cn(className)} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave} {...props}>
<svg xmlns="http://www.w3.org/2000/svg" width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<polyline points="4 17 10 11 4 5"/>
<motion.line x1="12" x2="20" y1="19" y2="19" variants={LINE_VARIANTS} animate={controls} initial="normal"/>
<motion.line x1="12" x2="20" y1="19" y2="19" variants={LINE_VARIANTS} animate={loop ? 'animate' : controls} initial="normal"/>
</svg>
</div>);
});
+29
View File
@@ -72,6 +72,13 @@
}
@layer base {
html,
body,
#root {
height: 100%;
overflow: hidden;
}
* {
@apply border-border outline-ring/50;
}
@@ -234,6 +241,28 @@
scrollbar-color: var(--primary) var(--secondary);
}
input::-ms-reveal,
input::-ms-clear {
display: none;
}
input[type="number"] {
color-scheme: light;
}
.dark input[type="number"] {
color-scheme: dark;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
margin: 0;
background: transparent;
border: 0;
box-shadow: none;
opacity: 1;
}
/* Custom scrollbar class untuk komponen tertentu */
.custom-scrollbar::-webkit-scrollbar {
width: 6px;
+9 -1
View File
@@ -2,7 +2,15 @@ class AudioManager {
private audioContext: AudioContext | null = null;
private getAudioContext(): AudioContext {
if (!this.audioContext) {
this.audioContext = new (window.AudioContext || (window as any).webkitAudioContext)();
const AudioContextConstructor = window.AudioContext || (window as Window & {
webkitAudioContext?: typeof AudioContext;
}).webkitAudioContext;
if (!AudioContextConstructor) {
throw new Error("Web Audio API is not supported in this browser");
}
const context = new AudioContextConstructor();
this.audioContext = context;
return context;
}
return this.audioContext;
}
+36 -33
View File
@@ -1,19 +1,32 @@
import type { TwitterResponse, TimelineEntry, AccountInfo } from "@/types/api";
import type { TimelineEntry } from "@/types/api";
const FETCH_STATE_KEY = "twitter_fetch_state";
const CURSOR_STATE_KEY = "twitter_cursor_state";
export interface FetchState {
username: string;
cursor: string;
timeline: TimelineEntry[];
accountInfo: AccountInfo | null;
totalFetched: number;
completed: boolean;
lastUpdated: number;
authToken: string;
mediaType: string;
retweets: boolean;
timelineType: string;
}
function normalizeFetchState(state: FetchState | null | undefined): FetchState | null {
if (!state) {
return null;
}
return {
...state,
cursor: state.cursor || "",
totalFetched: state.totalFetched ?? 0,
mediaType: state.mediaType || "all",
retweets: state.retweets ?? false,
timelineType: state.timelineType || "timeline",
};
}
export function saveFetchState(state: Partial<FetchState> & {
username: string;
}): void {
@@ -22,12 +35,9 @@ export function saveFetchState(state: Partial<FetchState> & {
const updated: FetchState = {
username: state.username,
cursor: state.cursor || "",
timeline: state.timeline || existing?.timeline || [],
accountInfo: state.accountInfo || existing?.accountInfo || null,
totalFetched: state.totalFetched ?? existing?.totalFetched ?? 0,
completed: state.completed ?? false,
lastUpdated: Date.now(),
authToken: state.authToken || existing?.authToken || "",
mediaType: state.mediaType || existing?.mediaType || "all",
retweets: state.retweets ?? existing?.retweets ?? false,
timelineType: state.timelineType || existing?.timelineType || "timeline",
@@ -43,7 +53,7 @@ export function saveFetchState(state: Partial<FetchState> & {
export function getFetchState(username: string): FetchState | null {
try {
const allStates = getAllFetchStates();
return allStates[username.toLowerCase()] || null;
return normalizeFetchState(allStates[username.toLowerCase()]);
}
catch (error) {
console.error("Failed to get fetch state:", error);
@@ -54,7 +64,17 @@ export function getAllFetchStates(): Record<string, FetchState> {
try {
const stored = localStorage.getItem(FETCH_STATE_KEY);
if (stored) {
return JSON.parse(stored);
const parsed = JSON.parse(stored);
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
const normalized: Record<string, FetchState> = {};
for (const [key, value] of Object.entries(parsed as Record<string, FetchState | null | undefined>)) {
const state = normalizeFetchState(value);
if (state) {
normalized[key] = state;
}
}
return normalized;
}
}
}
catch (error) {
@@ -66,7 +86,7 @@ export function hasResumableFetch(username: string): boolean {
const state = getFetchState(username);
if (!state)
return false;
return !!state.cursor && !state.completed && state.timeline.length > 0;
return !!state.cursor && !state.completed && state.totalFetched > 0;
}
export function getResumableInfo(username: string): {
canResume: boolean;
@@ -79,7 +99,7 @@ export function getResumableInfo(username: string): {
}
return {
canResume: true,
mediaCount: state.timeline.length,
mediaCount: state.totalFetched,
lastUpdated: new Date(state.lastUpdated),
};
}
@@ -108,25 +128,6 @@ export function clearAllIncompleteFetchStates(): void {
console.error("Failed to clear fetch states:", error);
}
}
export function stateToResponse(state: FetchState): TwitterResponse | null {
if (!state.accountInfo)
return null;
return {
account_info: state.accountInfo,
total_urls: state.timeline.length,
timeline: state.timeline,
metadata: {
new_entries: state.timeline.length,
page: 0,
batch_size: 0,
has_more: !state.completed,
cursor: state.cursor,
completed: state.completed,
},
cursor: state.cursor,
completed: state.completed,
};
}
export function saveCursor(username: string, cursor: string): void {
try {
const allCursors = getAllCursors();
@@ -176,7 +177,9 @@ export function clearCursor(username: string): void {
}
}
export function mergeTimelines(existing: TimelineEntry[], newEntries: TimelineEntry[]): TimelineEntry[] {
const seenIds = new Set(existing.map((e) => e.tweet_id));
const unique = newEntries.filter((e) => !seenIds.has(e.tweet_id));
return [...existing, ...unique];
const existingTimeline = Array.isArray(existing) ? existing : [];
const incomingTimeline = Array.isArray(newEntries) ? newEntries : [];
const seenIds = new Set(existingTimeline.map((e) => e.tweet_id));
const unique = incomingTimeline.filter((e) => !seenIds.has(e.tweet_id));
return [...existingTimeline, ...unique];
}
+55
View File
@@ -0,0 +1,55 @@
export type DependencyName = "extractor" | "ffmpeg" | "exiftool";
export interface CachedDependencyStatus {
installed: boolean | null;
installedVersion: string | null;
latestVersion: string | null;
}
export interface CachedMediaFolderStatus {
folderExists: boolean;
gifsFolderHasMP4: boolean;
}
const dependencyStatusCache: Record<DependencyName, CachedDependencyStatus> = {
extractor: {
installed: null,
installedVersion: null,
latestVersion: null,
},
ffmpeg: {
installed: null,
installedVersion: null,
latestVersion: null,
},
exiftool: {
installed: null,
installedVersion: null,
latestVersion: null,
},
};
const mediaFolderStatusCache = new Map<string, CachedMediaFolderStatus>();
function getMediaFolderStatusKey(downloadPath: string, folderName: string): string {
return `${downloadPath}::${folderName}`;
}
export function getCachedDependencyStatus(name: DependencyName): CachedDependencyStatus {
return { ...dependencyStatusCache[name] };
}
export function setCachedDependencyStatus(name: DependencyName, status: Partial<CachedDependencyStatus>): void {
dependencyStatusCache[name] = {
...dependencyStatusCache[name],
...status,
};
}
export function getCachedMediaFolderStatus(downloadPath: string, folderName: string): CachedMediaFolderStatus | null {
return mediaFolderStatusCache.get(getMediaFolderStatusKey(downloadPath, folderName)) ?? null;
}
export function setCachedMediaFolderStatus(downloadPath: string, folderName: string, status: CachedMediaFolderStatus): void {
mediaFolderStatusCache.set(getMediaFolderStatusKey(downloadPath, folderName), status);
}
+339 -33
View File
@@ -1,14 +1,52 @@
import { GetDefaults } from "../../wailsjs/go/main/App";
export type FontFamily = "google-sans" | "inter" | "poppins" | "roboto" | "dm-sans" | "plus-jakarta-sans" | "manrope" | "space-grotesk" | "noto-sans" | "nunito-sans" | "figtree" | "raleway" | "public-sans" | "outfit" | "jetbrains-mono" | "geist-sans";
export type BuiltInFontFamily =
| "google-sans"
| "inter"
| "poppins"
| "roboto"
| "dm-sans"
| "plus-jakarta-sans"
| "manrope"
| "space-grotesk"
| "noto-sans"
| "nunito-sans"
| "figtree"
| "raleway"
| "public-sans"
| "outfit"
| "jetbrains-mono"
| "geist-sans"
| "bricolage-grotesque";
export type CustomFontFamily = `custom-${string}`;
export type FontFamily = BuiltInFontFamily | CustomFontFamily;
export interface CustomFontOption {
value: CustomFontFamily;
label: string;
fontFamily: string;
url: string;
}
export interface FontOption {
value: FontFamily;
label: string;
fontFamily: string;
url?: string;
}
export type GifQuality = "fast" | "better";
export type GifResolution = "original" | "high" | "medium" | "low";
export type FetchMode = "single" | "batch";
export type MediaType = "all" | "image" | "video" | "gif" | "text";
export interface Settings {
downloadPath: string;
theme: string;
themeMode: "auto" | "light" | "dark";
fontFamily: FontFamily;
customFonts: CustomFontOption[];
sfxEnabled: boolean;
gifQuality: GifQuality;
gifResolution: GifResolution;
@@ -18,11 +56,13 @@ export interface Settings {
mediaType: MediaType;
includeRetweets: boolean;
}
export const DEFAULT_SETTINGS: Settings = {
downloadPath: "",
theme: "yellow",
themeMode: "auto",
fontFamily: "google-sans",
customFonts: [],
sfxEnabled: true,
gifQuality: "fast",
gifResolution: "original",
@@ -32,35 +72,271 @@ export const DEFAULT_SETTINGS: Settings = {
mediaType: "all",
includeRetweets: false,
};
export const FONT_OPTIONS: {
value: FontFamily;
label: string;
fontFamily: string;
}[] = [
{ value: "dm-sans", label: "DM Sans", fontFamily: '"DM Sans", system-ui, sans-serif' },
{ value: "figtree", label: "Figtree", fontFamily: '"Figtree", system-ui, sans-serif' },
{ value: "geist-sans", label: "Geist Sans", fontFamily: '"Geist", system-ui, sans-serif' },
{ value: "google-sans", label: "Google Sans Flex", fontFamily: '"Google Sans Flex", system-ui, sans-serif' },
{ value: "inter", label: "Inter", fontFamily: '"Inter", system-ui, sans-serif' },
{ value: "jetbrains-mono", label: "JetBrains Mono", fontFamily: '"JetBrains Mono", ui-monospace, monospace' },
{ value: "manrope", label: "Manrope", fontFamily: '"Manrope", system-ui, sans-serif' },
{ value: "noto-sans", label: "Noto Sans", fontFamily: '"Noto Sans", system-ui, sans-serif' },
{ value: "nunito-sans", label: "Nunito Sans", fontFamily: '"Nunito Sans", system-ui, sans-serif' },
{ value: "outfit", label: "Outfit", fontFamily: '"Outfit", system-ui, sans-serif' },
{ value: "plus-jakarta-sans", label: "Plus Jakarta Sans", fontFamily: '"Plus Jakarta Sans", system-ui, sans-serif' },
{ value: "poppins", label: "Poppins", fontFamily: '"Poppins", system-ui, sans-serif' },
{ value: "public-sans", label: "Public Sans", fontFamily: '"Public Sans", system-ui, sans-serif' },
{ value: "raleway", label: "Raleway", fontFamily: '"Raleway", system-ui, sans-serif' },
{ value: "roboto", label: "Roboto", fontFamily: '"Roboto", system-ui, sans-serif' },
{ value: "space-grotesk", label: "Space Grotesk", fontFamily: '"Space Grotesk", system-ui, sans-serif' },
export const FONT_OPTIONS: FontOption[] = [
{
value: "bricolage-grotesque",
label: "Bricolage Grotesque",
fontFamily: '"Bricolage Grotesque", system-ui, sans-serif',
},
{
value: "dm-sans",
label: "DM Sans",
fontFamily: '"DM Sans", system-ui, sans-serif',
},
{
value: "figtree",
label: "Figtree",
fontFamily: '"Figtree", system-ui, sans-serif',
},
{
value: "geist-sans",
label: "Geist Sans",
fontFamily: '"Geist", system-ui, sans-serif',
},
{
value: "google-sans",
label: "Google Sans",
fontFamily: '"Google Sans Flex", system-ui, sans-serif',
},
{
value: "inter",
label: "Inter",
fontFamily: '"Inter", system-ui, sans-serif',
},
{
value: "jetbrains-mono",
label: "JetBrains Mono",
fontFamily: '"JetBrains Mono", ui-monospace, monospace',
},
{
value: "manrope",
label: "Manrope",
fontFamily: '"Manrope", system-ui, sans-serif',
},
{
value: "noto-sans",
label: "Noto Sans",
fontFamily: '"Noto Sans", system-ui, sans-serif',
},
{
value: "nunito-sans",
label: "Nunito Sans",
fontFamily: '"Nunito Sans", system-ui, sans-serif',
},
{
value: "outfit",
label: "Outfit",
fontFamily: '"Outfit", system-ui, sans-serif',
},
{
value: "plus-jakarta-sans",
label: "Plus Jakarta Sans",
fontFamily: '"Plus Jakarta Sans", system-ui, sans-serif',
},
{
value: "poppins",
label: "Poppins",
fontFamily: '"Poppins", system-ui, sans-serif',
},
{
value: "public-sans",
label: "Public Sans",
fontFamily: '"Public Sans", system-ui, sans-serif',
},
{
value: "raleway",
label: "Raleway",
fontFamily: '"Raleway", system-ui, sans-serif',
},
{
value: "roboto",
label: "Roboto",
fontFamily: '"Roboto", system-ui, sans-serif',
},
{
value: "space-grotesk",
label: "Space Grotesk",
fontFamily: '"Space Grotesk", system-ui, sans-serif',
},
];
export function applyFont(fontFamily: FontFamily): void {
const font = FONT_OPTIONS.find(f => f.value === fontFamily);
const BUILT_IN_FONT_VALUES = new Set(FONT_OPTIONS.map((font) => font.value));
const SETTINGS_KEY = "twitter-media-downloader-settings";
const GOOGLE_FONT_LINK_ID_PREFIX = "twitter-media-custom-font-";
const GOOGLE_FONTS_CSS_HOST = "fonts.googleapis.com";
const GOOGLE_FONTS_SPECIMEN_HOST = "fonts.google.com";
function extractGoogleFontInputUrl(input: string): string {
const trimmed = input.trim();
const hrefMatch = trimmed.match(/\bhref=["']([^"']+)["']/i);
if (hrefMatch?.[1]) {
return hrefMatch[1];
}
const importMatch = trimmed.match(/@import\s+url\(["']?([^"')]+)["']?\)/i);
if (importMatch?.[1]) {
return importMatch[1];
}
return trimmed;
}
function coerceGoogleFontUrl(rawUrl: string): string {
const trimmed = rawUrl.trim();
if (/^https?:\/\//i.test(trimmed)) {
return trimmed;
}
if (/^(fonts\.googleapis\.com|fonts\.google\.com)\//i.test(trimmed)) {
return `https://${trimmed}`;
}
return trimmed;
}
function normalizeFontLabel(label: string): string {
return label.replace(/\+/g, " ").replace(/\s+/g, " ").trim();
}
function slugifyFontLabel(label: string): string {
return label.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "font";
}
function toFontFamilyCss(label: string): string {
const escapedLabel = label.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
return `"${escapedLabel}", system-ui, sans-serif`;
}
function buildGoogleFontsCssUrl(label: string): string {
const url = new URL("https://fonts.googleapis.com/css2");
url.searchParams.set("family", label);
url.searchParams.set("display", "swap");
return url.toString();
}
function extractSpecimenFontLabel(parsed: URL): string {
const segments = parsed.pathname.split("/").filter(Boolean);
const specimenIndex = segments.findIndex((segment) => segment.toLowerCase() === "specimen");
const specimenName = specimenIndex >= 0 ? segments[specimenIndex + 1] : "";
return normalizeFontLabel(decodeURIComponent(specimenName || ""));
}
function normalizeGoogleFontCssUrl(rawUrl: string): string | null {
try {
const parsed = new URL(coerceGoogleFontUrl(extractGoogleFontInputUrl(rawUrl)));
if (parsed.protocol !== "https:") {
return null;
}
if (parsed.hostname === GOOGLE_FONTS_SPECIMEN_HOST) {
const label = extractSpecimenFontLabel(parsed);
return label ? buildGoogleFontsCssUrl(label) : null;
}
if (parsed.hostname !== GOOGLE_FONTS_CSS_HOST || (parsed.pathname !== "/css" && parsed.pathname !== "/css2")) {
return null;
}
if (parsed.searchParams.getAll("family").length === 0) {
return null;
}
if (!parsed.searchParams.has("display")) {
parsed.searchParams.set("display", "swap");
}
return parsed.toString();
}
catch {
return null;
}
}
export function parseGoogleFontUrl(rawUrl: string): CustomFontOption | null {
const normalizedUrl = normalizeGoogleFontCssUrl(rawUrl);
if (!normalizedUrl) {
return null;
}
const parsed = new URL(normalizedUrl);
const family = parsed.searchParams.getAll("family")[0];
const label = normalizeFontLabel((family || "").split(":")[0] || "");
if (!label) {
return null;
}
return {
value: `custom-${slugifyFontLabel(label)}` as CustomFontFamily,
label,
fontFamily: toFontFamilyCss(label),
url: normalizedUrl,
};
}
function normalizeCustomFonts(customFonts: unknown): CustomFontOption[] {
if (!Array.isArray(customFonts)) {
return [];
}
const normalizedFonts: CustomFontOption[] = [];
const seenValues = new Set<string>();
const seenUrls = new Set<string>();
for (const item of customFonts) {
if (!item || typeof item !== "object") {
continue;
}
const rawUrl = (item as { url?: unknown }).url;
if (typeof rawUrl !== "string") {
continue;
}
const parsed = parseGoogleFontUrl(rawUrl);
if (!parsed || seenValues.has(parsed.value) || seenUrls.has(parsed.url)) {
continue;
}
seenValues.add(parsed.value);
seenUrls.add(parsed.url);
normalizedFonts.push(parsed);
}
return normalizedFonts;
}
function normalizeFontFamily(fontFamily: unknown, customFonts: CustomFontOption[]): FontFamily {
if (typeof fontFamily !== "string") {
return DEFAULT_SETTINGS.fontFamily;
}
if (BUILT_IN_FONT_VALUES.has(fontFamily as BuiltInFontFamily)) {
return fontFamily as BuiltInFontFamily;
}
const customFont = customFonts.find((font) => font.value === fontFamily);
return customFont ? customFont.value : DEFAULT_SETTINGS.fontFamily;
}
export function getFontOptions(customFonts: CustomFontOption[] = []): FontOption[] {
return [...FONT_OPTIONS, ...normalizeCustomFonts(customFonts)];
}
export function loadGoogleFontUrl(url: string, id = `${GOOGLE_FONT_LINK_ID_PREFIX}preview`): void {
const normalizedUrl = normalizeGoogleFontCssUrl(url);
if (!normalizedUrl) {
return;
}
let link = document.getElementById(id) as HTMLLinkElement | null;
if (!link) {
link = document.createElement("link");
link.id = id;
link.rel = "stylesheet";
document.head.appendChild(link);
}
if (link.href !== normalizedUrl) {
link.href = normalizedUrl;
}
}
function loadCustomFontStylesheets(customFonts: CustomFontOption[]): void {
for (const font of normalizeCustomFonts(customFonts)) {
loadGoogleFontUrl(font.url, `${GOOGLE_FONT_LINK_ID_PREFIX}${font.value}`);
}
}
export function applyFont(fontFamily: FontFamily, customFonts: CustomFontOption[] = []): void {
const fontOptions = getFontOptions(customFonts);
loadCustomFontStylesheets(customFonts);
const font = fontOptions.find((option) => option.value === fontFamily) || FONT_OPTIONS.find((option) => option.value === DEFAULT_SETTINGS.fontFamily);
if (font) {
document.documentElement.style.setProperty('--font-sans', font.fontFamily);
document.documentElement.style.setProperty("--font-sans", font.fontFamily);
document.body.style.fontFamily = font.fontFamily;
}
}
async function fetchDefaultPath(): Promise<string> {
try {
const data = await GetDefaults();
@@ -71,13 +347,22 @@ async function fetchDefaultPath(): Promise<string> {
return "";
}
}
const SETTINGS_KEY = "twitter-media-downloader-settings";
function toNormalizedSettings(settings: Partial<Settings>): Settings {
const customFonts = normalizeCustomFonts(settings.customFonts);
return {
...DEFAULT_SETTINGS,
...settings,
customFonts,
fontFamily: normalizeFontFamily(settings.fontFamily, customFonts),
};
}
export function getSettings(): Settings {
try {
const stored = localStorage.getItem(SETTINGS_KEY);
if (stored) {
const parsed = JSON.parse(stored);
return { ...DEFAULT_SETTINGS, ...parsed };
return toNormalizedSettings(JSON.parse(stored) as Partial<Settings>);
}
}
catch (error) {
@@ -85,36 +370,57 @@ export function getSettings(): Settings {
}
return DEFAULT_SETTINGS;
}
export async function getSettingsWithDefaults(): Promise<Settings> {
const settings = getSettings();
if (!settings.downloadPath) {
settings.downloadPath = await fetchDefaultPath();
}
return settings;
return toNormalizedSettings(settings);
}
export function saveSettings(settings: Settings): void {
try {
localStorage.setItem(SETTINGS_KEY, JSON.stringify(settings));
const normalizedSettings = toNormalizedSettings(settings);
localStorage.setItem(SETTINGS_KEY, JSON.stringify(normalizedSettings));
}
catch (error) {
console.error("Failed to save settings:", error);
}
}
export function updateSettings(partial: Partial<Settings>): Settings {
const current = getSettings();
const updated = { ...current, ...partial };
const updated = toNormalizedSettings({ ...current, ...partial });
saveSettings(updated);
return updated;
}
export async function resetToDefaultSettings(): Promise<Settings> {
const defaultPath = await fetchDefaultPath();
const defaultSettings = {
const defaultSettings = toNormalizedSettings({
...DEFAULT_SETTINGS,
downloadPath: defaultPath,
};
});
saveSettings(defaultSettings);
return defaultSettings;
}
export async function loadCustomFonts(): Promise<CustomFontOption[]> {
return normalizeCustomFonts(getSettings().customFonts);
}
export async function saveCustomFonts(customFonts: CustomFontOption[]): Promise<CustomFontOption[]> {
const normalizedFonts = normalizeCustomFonts(customFonts);
const settings = getSettings();
saveSettings({
...settings,
customFonts: normalizedFonts,
fontFamily: normalizeFontFamily(settings.fontFamily, normalizedFonts),
});
return normalizedFonts;
}
export function applyThemeMode(mode: "auto" | "light" | "dark"): void {
if (mode === "auto") {
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
+6 -6
View File
@@ -1,4 +1,4 @@
import { toast } from "sonner";
import { toast, type ExternalToast } from "sonner";
import { playSuccessSound, playErrorSound, playWarningSound, playInfoSound, } from "./audio";
import { logger } from "./logger";
import { getSettings } from "./settings";
@@ -7,35 +7,35 @@ const toastStyle = {
};
const isSfxEnabled = () => getSettings().sfxEnabled;
export const toastWithSound = {
success: (message: string, data?: any) => {
success: (message: string, data?: ExternalToast) => {
const msg = message.toLowerCase();
logger.success(msg);
if (isSfxEnabled())
playSuccessSound();
return toast.success(msg, { ...toastStyle, ...data });
},
error: (message: string, data?: any) => {
error: (message: string, data?: ExternalToast) => {
const msg = message.toLowerCase();
logger.error(msg);
if (isSfxEnabled())
playErrorSound();
return toast.error(msg, { ...toastStyle, ...data });
},
warning: (message: string, data?: any) => {
warning: (message: string, data?: ExternalToast) => {
const msg = message.toLowerCase();
logger.warning(msg);
if (isSfxEnabled())
playWarningSound();
return toast.warning(msg, { ...toastStyle, ...data });
},
info: (message: string, data?: any) => {
info: (message: string, data?: ExternalToast) => {
const msg = message.toLowerCase();
logger.info(msg);
if (isSfxEnabled())
playInfoSound();
return toast.info(msg, { ...toastStyle, ...data });
},
message: (message: string, data?: any) => {
message: (message: string, data?: ExternalToast) => {
const msg = message.toLowerCase();
logger.info(msg);
if (isSfxEnabled())
+1 -1
View File
@@ -32,7 +32,7 @@ export function openExternal(url: string) {
try {
BrowserOpenURL(url);
}
catch (error) {
catch {
if (typeof window !== "undefined") {
window.open(url, "_blank", "noopener,noreferrer");
}
+22
View File
@@ -0,0 +1,22 @@
export function compareVersionNumbers(left: string, right: string) {
const toParts = (value: string) => value
.trim()
.replace(/^[^\d]*/, "")
.split(/[^0-9]+/)
.filter(Boolean)
.map((part) => Number.parseInt(part, 10));
const leftParts = toParts(left);
const rightParts = toParts(right);
const maxLength = Math.max(leftParts.length, rightParts.length);
for (let index = 0; index < maxLength; index += 1) {
const leftPart = leftParts[index] ?? 0;
const rightPart = rightParts[index] ?? 0;
if (leftPart > rightPart) {
return 1;
}
if (leftPart < rightPart) {
return -1;
}
}
return 0;
}