mirror of
https://github.com/Alvin-Zilverstand/Twitter-X-Media-Batch-Downloader.git
synced 2026-11-29 17:47:54 +01:00
f
This commit is contained in:
1 parent
9c269bc8f2
commit
6964753e3e
8 files changed
+164
-2
No files matched your search
@@ -3,6 +3,7 @@ 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 { createFetchDelayGate } from "@/lib/fetch-delay";
|
||||
import { applyTheme } from "@/lib/themes";
|
||||
import { openExternal } from "@/lib/utils";
|
||||
import { isNewerVersion } from "@/lib/version";
|
||||
@@ -29,6 +30,7 @@ const HISTORY_KEY = "twitter_media_fetch_history";
|
||||
const MAX_HISTORY = 10;
|
||||
const CURRENT_VERSION = __APP_VERSION__;
|
||||
const BATCH_SIZE = 100;
|
||||
const waitForFetch = createFetchDelayGate();
|
||||
function formatNumberWithComma(num: number): string {
|
||||
return num.toLocaleString();
|
||||
}
|
||||
@@ -446,6 +448,7 @@ function App() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!await waitForFetch(settings.fetchDelaySeconds, settings.fetchDelayJitterSeconds, () => stopFetchRef.current)) return;
|
||||
const response = await ExtractDateRange({
|
||||
username: username.trim(),
|
||||
auth_token: authToken.trim(),
|
||||
@@ -522,6 +525,7 @@ function App() {
|
||||
}
|
||||
}
|
||||
const batchNum = page + 1;
|
||||
if (!await waitForFetch(settings.fetchDelaySeconds, settings.fetchDelayJitterSeconds, () => stopFetchRef.current)) break;
|
||||
logger.info(`Fetching batch ${batchNum}${cursor ? " (resuming)" : ""}...`);
|
||||
const response = await ExtractTimeline({
|
||||
username: isBookmarks ? "" : username.trim(),
|
||||
@@ -977,6 +981,7 @@ function App() {
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!await waitForFetch(settings.fetchDelaySeconds, settings.fetchDelayJitterSeconds, () => stopAllRef.current || !!accountStopFlagsRef.current.get(accountId))) break;
|
||||
const response = await ExtractTimeline({
|
||||
username: cleanUsername,
|
||||
auth_token: authToken.trim(),
|
||||
@@ -1336,6 +1341,7 @@ function App() {
|
||||
if (accountStopFlagsRef.current.get(accountId)) {
|
||||
break;
|
||||
}
|
||||
if (!await waitForFetch(settings.fetchDelaySeconds, settings.fetchDelayJitterSeconds, () => stopAllRef.current || !!accountStopFlagsRef.current.get(accountId))) break;
|
||||
const response = await ExtractTimeline({
|
||||
username: cleanUsername,
|
||||
auth_token: authToken.trim(),
|
||||
|
||||
@@ -743,6 +743,30 @@ export function SettingsPage({ onUnsavedChangesChange, onResetRequest }: Setting
|
||||
<InputWithContext id="proxy" value={tempSettings.proxy || ""} onChange={(e) => setTempSettings((prev) => ({ ...prev, proxy: e.target.value }))} placeholder="http://proxy1:port, socks5://proxy2:port (optional)" className="max-w-md"/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>Fetch Delay</Label>
|
||||
<div className="flex flex-wrap gap-4">
|
||||
{([
|
||||
["fetchDelaySeconds", "Base Delay"],
|
||||
["fetchDelayJitterSeconds", "Random Extra"],
|
||||
] as const).map(([key, label]) => (
|
||||
<div key={key} className="space-y-1.5">
|
||||
<Label htmlFor={key} className="text-xs">{label}</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<InputWithContext id={key} type="number" min="0" max="3600" step="0.1" value={tempSettings[key]} onChange={(e) => {
|
||||
const value = Number(e.target.value);
|
||||
setTempSettings((prev) => ({ ...prev, [key]: Number.isFinite(value) ? Math.min(3600, Math.max(0, value)) : 0 }));
|
||||
}} className="w-24"/>
|
||||
<span className="text-xs text-muted-foreground">sec</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">Spaces out fetch batch starts, including account switches and retries. Random Extra adds between 0 and the chosen number of seconds. Set both to 0 to disable.</p>
|
||||
<p className="text-xs text-muted-foreground">Suggested starting point: 5 sec base + 5 sec random extra. No delay guarantees avoidance of rate limits. Waiting counts toward Fetch Timeout; increase it for longer delays.</p>
|
||||
<p className="text-xs text-muted-foreground">Applies between extractor runs, including date-range fetches, rather than individual requests inside the extractor.</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="fetch-timeout" className="flex items-center gap-2">
|
||||
Fetch Timeout
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
export function normalizeFetchDelay(value: unknown): number {
|
||||
return typeof value === "number" && Number.isFinite(value)
|
||||
? Math.round(Math.min(3600, Math.max(0, value)) * 1000) / 1000
|
||||
: 0;
|
||||
}
|
||||
|
||||
// One gate shared by all fetch paths, so switching accounts also respects pacing.
|
||||
export function createFetchDelayGate({
|
||||
now = () => performance.now(),
|
||||
random = Math.random,
|
||||
sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)),
|
||||
} = {}) {
|
||||
let lastStarted: number | null = null;
|
||||
return async (baseSeconds: number, extraSeconds: number, stopped: () => boolean): Promise<boolean> => {
|
||||
const delay = (normalizeFetchDelay(baseSeconds) + random() * normalizeFetchDelay(extraSeconds)) * 1000;
|
||||
while (!stopped()) {
|
||||
const remaining = lastStarted === null ? 0 : lastStarted + delay - now();
|
||||
if (remaining <= 0) {
|
||||
lastStarted = now();
|
||||
return true;
|
||||
}
|
||||
// Recheck the shared timestamp after each wait to space concurrent callers too.
|
||||
await sleep(Math.min(remaining, 100));
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { GetDefaults } from "../../wailsjs/go/main/App";
|
||||
import { normalizeFetchDelay } from "./fetch-delay";
|
||||
import { normalizeBaseColorName, normalizeThemeName, type BaseColorName, type ThemeName } from "./themes";
|
||||
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}`;
|
||||
@@ -171,6 +172,8 @@ export interface Settings {
|
||||
gifResolution: GifResolution;
|
||||
proxy: string;
|
||||
fetchTimeout: number;
|
||||
fetchDelaySeconds: number;
|
||||
fetchDelayJitterSeconds: number;
|
||||
includePhotos: boolean;
|
||||
includeVideos: boolean;
|
||||
includeGifs: boolean;
|
||||
@@ -204,6 +207,8 @@ export const DEFAULT_SETTINGS: Settings = {
|
||||
gifResolution: "original",
|
||||
proxy: "",
|
||||
fetchTimeout: 60,
|
||||
fetchDelaySeconds: 0,
|
||||
fetchDelayJitterSeconds: 0,
|
||||
includePhotos: true,
|
||||
includeVideos: true,
|
||||
includeGifs: true,
|
||||
@@ -550,6 +555,8 @@ function toNormalizedSettings(settings: Partial<Settings>): Settings {
|
||||
downloadSpeedLimitKBps: normalizeDownloadSpeedLimit(settings.downloadSpeedLimitKBps),
|
||||
downloadDelaySeconds: normalizeDownloadDelay(settings.downloadDelaySeconds),
|
||||
downloadDelayJitterSeconds: normalizeDownloadDelay(settings.downloadDelayJitterSeconds),
|
||||
fetchDelaySeconds: normalizeFetchDelay(settings.fetchDelaySeconds),
|
||||
fetchDelayJitterSeconds: normalizeFetchDelay(settings.fetchDelayJitterSeconds),
|
||||
showUpdateNotifications: normalizeBoolean(settings.showUpdateNotifications, DEFAULT_SETTINGS.showUpdateNotifications),
|
||||
autoConvertGifs: normalizeBoolean(settings.autoConvertGifs, DEFAULT_SETTINGS.autoConvertGifs),
|
||||
filenameTemplate: normalizeFilenameTemplate(settings.filenameTemplate),
|
||||
|
||||
Reference in new issue
Block a user