Keep account fallback healthy across concurrent upload failures
CI / verify (push) Canceled after 0s
CI / verify (push) Canceled after 0s
This commit is contained in:
1 parent
e9287545ee
commit
2ba21993c8
3 files changed
+50
-17
No files matched your search
@@ -24,6 +24,21 @@ function createAccountPicker({ hosters, hosterSettings, hasCreds, indices }) {
|
||||
return pick;
|
||||
}
|
||||
|
||||
function selectFallbackAccount({ accounts, hoster, currentAccountId, failedKeys, preferredAccountId, excludedIds, hasCreds = () => true }) {
|
||||
if (!Array.isArray(accounts)) return null;
|
||||
const usable = account => account && account.id && account.id !== currentAccountId
|
||||
&& account.enabled !== false && hasCreds(hoster, account)
|
||||
&& !failedKeys?.has(`${hoster}:${account.id}`) && !excludedIds?.has(account.id);
|
||||
const preferred = accounts.find(account => account?.id === preferredAccountId && usable(account));
|
||||
if (preferred) return preferred;
|
||||
const currentIndex = accounts.findIndex(account => account?.id === currentAccountId);
|
||||
for (let offset = 1; offset <= accounts.length; offset++) {
|
||||
const account = accounts[(currentIndex + offset) % accounts.length];
|
||||
if (usable(account)) return account;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function classifyAccountFailure(error) {
|
||||
if (!error || error.transientNetwork === true || error.hosterTransient === true || error.fileRejected === true) return 'none';
|
||||
if (error.otpRequired === true) return 'manual';
|
||||
@@ -175,5 +190,6 @@ module.exports = {
|
||||
classifyAccountFailure,
|
||||
createAccountCooldownController,
|
||||
createAccountPicker,
|
||||
selectFallbackAccount,
|
||||
enabledAccountsFor
|
||||
};
|
||||
Reference in new issue
Block a user