Add configurable SUB2API account priority
This commit is contained in:
@@ -210,6 +210,10 @@
|
||||
<button id="btn-add-sub2api-group" class="btn btn-outline btn-sm data-inline-btn" type="button">添加</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="data-row" id="row-sub2api-account-priority" style="display:none;">
|
||||
<span class="data-label">优先级</span>
|
||||
<input type="number" id="input-sub2api-account-priority" class="data-input mono" value="1" min="1" step="1" />
|
||||
</div>
|
||||
<div class="data-row" id="row-sub2api-default-proxy" style="display:none;">
|
||||
<span class="data-label">默认代理</span>
|
||||
<input type="text" id="input-sub2api-default-proxy" class="data-input" placeholder="留空则不使用代理;或填写代理名称 / ID" />
|
||||
|
||||
@@ -100,6 +100,8 @@ const btnSub2ApiGroupMenu = document.getElementById('btn-sub2api-group-menu');
|
||||
const sub2ApiGroupCurrent = document.getElementById('sub2api-group-current');
|
||||
const sub2ApiGroupMenu = document.getElementById('sub2api-group-menu');
|
||||
const btnAddSub2ApiGroup = document.getElementById('btn-add-sub2api-group');
|
||||
const rowSub2ApiAccountPriority = document.getElementById('row-sub2api-account-priority');
|
||||
const inputSub2ApiAccountPriority = document.getElementById('input-sub2api-account-priority');
|
||||
const rowSub2ApiDefaultProxy = document.getElementById('row-sub2api-default-proxy');
|
||||
const inputSub2ApiDefaultProxy = document.getElementById('input-sub2api-default-proxy');
|
||||
const rowIpProxyEnabled = document.getElementById('row-ip-proxy-enabled');
|
||||
@@ -1150,6 +1152,15 @@ function normalizeSub2ApiGroupOptions(...sources) {
|
||||
return normalizeEditableListValues(...sources);
|
||||
}
|
||||
|
||||
function normalizeSub2ApiAccountPriorityValue(value) {
|
||||
const rawValue = String(value ?? '').trim();
|
||||
const numeric = Number(rawValue);
|
||||
if (!rawValue || !Number.isSafeInteger(numeric) || numeric < 1) {
|
||||
return 1;
|
||||
}
|
||||
return numeric;
|
||||
}
|
||||
|
||||
function getSelectedSub2ApiGroupName() {
|
||||
return String(inputSub2ApiGroup?.value || '').trim()
|
||||
|| DEFAULT_SUB2API_GROUP_OPTIONS[0];
|
||||
@@ -3181,6 +3192,12 @@ function collectSettingsPayload() {
|
||||
if (sub2apiGroupNames.length === 0) {
|
||||
appendSub2ApiGroupNames(['codex', 'openai-plus']);
|
||||
}
|
||||
const sub2apiAccountPriorityNormalizer = typeof normalizeSub2ApiAccountPriorityValue === 'function'
|
||||
? normalizeSub2ApiAccountPriorityValue
|
||||
: ((value) => {
|
||||
const numeric = Number(String(value ?? '').trim());
|
||||
return Number.isSafeInteger(numeric) && numeric >= 1 ? numeric : 1;
|
||||
});
|
||||
return {
|
||||
...(contributionModeEnabled ? {} : {
|
||||
panelMode: selectPanelMode.value,
|
||||
@@ -3193,6 +3210,11 @@ function collectSettingsPayload() {
|
||||
sub2apiPassword: inputSub2ApiPassword.value,
|
||||
sub2apiGroupName: selectedSub2ApiGroupName,
|
||||
sub2apiGroupNames,
|
||||
sub2apiAccountPriority: sub2apiAccountPriorityNormalizer(
|
||||
typeof inputSub2ApiAccountPriority !== 'undefined' && inputSub2ApiAccountPriority
|
||||
? inputSub2ApiAccountPriority.value
|
||||
: latestState?.sub2apiAccountPriority
|
||||
),
|
||||
sub2apiDefaultProxyName: inputSub2ApiDefaultProxy.value.trim(),
|
||||
ipProxyEnabled: getSelectedIpProxyEnabledSafe(),
|
||||
ipProxyService: selectedIpProxyService,
|
||||
@@ -7550,6 +7572,9 @@ function applyAutoRunStatus(payload = currentAutoRun) {
|
||||
if (typeof inputSignupPhone !== 'undefined' && inputSignupPhone) {
|
||||
inputSignupPhone.disabled = locked;
|
||||
}
|
||||
if (typeof inputSub2ApiAccountPriority !== 'undefined' && inputSub2ApiAccountPriority) {
|
||||
inputSub2ApiAccountPriority.disabled = locked;
|
||||
}
|
||||
inputAutoSkipFailures.disabled = scheduled;
|
||||
|
||||
const lockedRunCount = typeof getLockedRunCountFromEmailPool === 'function'
|
||||
@@ -7847,6 +7872,9 @@ function applySettingsState(state) {
|
||||
inputSub2ApiEmail.value = state?.sub2apiEmail || '';
|
||||
inputSub2ApiPassword.value = state?.sub2apiPassword || '';
|
||||
renderSub2ApiGroupOptions(state, state?.sub2apiGroupName || '');
|
||||
if (typeof inputSub2ApiAccountPriority !== 'undefined' && inputSub2ApiAccountPriority) {
|
||||
inputSub2ApiAccountPriority.value = String(normalizeSub2ApiAccountPriorityValue(state?.sub2apiAccountPriority));
|
||||
}
|
||||
inputSub2ApiDefaultProxy.value = state?.sub2apiDefaultProxyName || '';
|
||||
const normalizedIpProxyService = resolveIpProxyService(state?.ipProxyService);
|
||||
const normalizedIpProxyServiceProfiles = typeof normalizeIpProxyServiceProfiles === 'function'
|
||||
@@ -9613,6 +9641,7 @@ function updatePanelModeUI() {
|
||||
rowSub2ApiEmail.style.display = useSub2Api ? '' : 'none';
|
||||
rowSub2ApiPassword.style.display = useSub2Api ? '' : 'none';
|
||||
rowSub2ApiGroup.style.display = useSub2Api ? '' : 'none';
|
||||
rowSub2ApiAccountPriority.style.display = useSub2Api ? '' : 'none';
|
||||
rowSub2ApiDefaultProxy.style.display = useSub2Api ? '' : 'none';
|
||||
rowCodex2ApiUrl.style.display = useCodex2Api ? '' : 'none';
|
||||
rowCodex2ApiAdminKey.style.display = useCodex2Api ? '' : 'none';
|
||||
@@ -10354,6 +10383,7 @@ const contributionModeManager = window.SidepanelContributionMode?.createContribu
|
||||
rowPhoneVerificationEnabled,
|
||||
rowCustomPassword,
|
||||
rowLocalCpaStep9Mode,
|
||||
rowSub2ApiAccountPriority,
|
||||
rowSub2ApiDefaultProxy,
|
||||
rowSub2ApiEmail,
|
||||
rowSub2ApiGroup,
|
||||
@@ -11700,6 +11730,16 @@ inputSub2ApiGroup.addEventListener('change', () => {
|
||||
markSettingsDirty(true);
|
||||
saveSettings({ silent: true }).catch(() => { });
|
||||
});
|
||||
|
||||
inputSub2ApiAccountPriority.addEventListener('input', () => {
|
||||
markSettingsDirty(true);
|
||||
scheduleSettingsAutoSave();
|
||||
});
|
||||
inputSub2ApiAccountPriority.addEventListener('blur', () => {
|
||||
inputSub2ApiAccountPriority.value = String(normalizeSub2ApiAccountPriorityValue(inputSub2ApiAccountPriority.value));
|
||||
saveSettings({ silent: true }).catch(() => { });
|
||||
});
|
||||
|
||||
btnAddSub2ApiGroup?.addEventListener('click', () => {
|
||||
handleAddSub2ApiGroup().catch((error) => {
|
||||
showToast(error?.message || '添加 SUB2API 分组失败。', 'error');
|
||||
|
||||
Reference in New Issue
Block a user