byse.sx requires each account to upload >=80 videos in the last 30 days (measured across a rolling 3-month window) or it goes dormant. With a single primary account doing all the work, the other configured accounts decay and eventually get suspended. This adds an opt-in "Accounts rotieren" toggle per hoster that round-robins files across every enabled account that has credentials: file 1 -> account 1, file 2 -> account 2, file 3 -> account 3, then wraps. Off by default, so existing single-account behavior is unchanged. Mechanics: - New lib/account-rotation.js: createAccountPicker() returns a stateful pick(hoster) closure holding a per-hoster round-robin index. It only rotates when rotateAccounts === true AND more than one usable account exists; otherwise it returns the first enabled account (the old primary). enabledAccountsFor() filters disabled + credential-less accounts while preserving configured order, so a disabled account is simply skipped in the cycle rather than leaving a gap. - main.js: both buildUploadTasks() and buildUploadTasksFromJobs() now build one picker per call and use pick(hoster) instead of getPrimaryAccount(), which is now removed (dead code). A fresh picker per batch means each upload session starts the cycle at account 1, matching "die erste Datei auf Account eins". - config-store.js: rotateAccounts: false added to HOSTER_SETTINGS_DEFAULTS. - renderer/app.js: "Accounts rotieren" checkbox in the per-hoster upload settings (Accounts tab). Persisted by the existing generic checkbox path in saveHosterSettingsFromDom(). Composes with failover: rotation only chooses the *initial* account per file. On a hard account failure the existing failover (_failedAccounts + pre-job account swap) reroutes just that account's jobs; the healthy accounts keep their rotation share. Single enabled account (or rotation off) = no behavior change. Tests: tests/account-rotation.test.js (10 cases) covers off=primary, on=round-robin+wrap, single-account no-op, skip disabled, skip no-creds, null when none usable, per-hoster index independence, byse-only rotation, 100-file 50/50 split, and the enabledAccountsFor filter. Full suite 294/294. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
23 lines
824 B
JavaScript
23 lines
824 B
JavaScript
function enabledAccountsFor(hosters, hoster, hasCreds) {
|
|
const list = hosters && hosters[hoster];
|
|
if (!Array.isArray(list)) return [];
|
|
return list.filter(a => a && a.enabled !== false && hasCreds(hoster, a));
|
|
}
|
|
|
|
function createAccountPicker({ hosters, hosterSettings, hasCreds }) {
|
|
const rotIdx = Object.create(null);
|
|
return function pick(hoster) {
|
|
const enabled = enabledAccountsFor(hosters, hoster, hasCreds);
|
|
if (enabled.length === 0) return null;
|
|
const hs = (hosterSettings && hosterSettings[hoster]) || {};
|
|
if (hs.rotateAccounts === true && enabled.length > 1) {
|
|
const i = (rotIdx[hoster] || 0) % enabled.length;
|
|
rotIdx[hoster] = (rotIdx[hoster] || 0) + 1;
|
|
return enabled[i];
|
|
}
|
|
return enabled[0];
|
|
};
|
|
}
|
|
|
|
module.exports = { createAccountPicker, enabledAccountsFor };
|