Files
new-api/web/src/hooks/channels/upstreamUpdateUtils.js
T
Seefs 70821e2051 feat: auto fetch upstream models (#2979)
* feat: add upstream model update detection with scheduled sync and manual apply flows

* feat: support upstream model removal sync and selectable deletes in update modal

* feat: add detect-only upstream updates and show compact +/- model badges

* feat: improve upstream model update UX

* feat: improve upstream model update UX

* fix: respect model_mapping in upstream update detection

* feat: improve upstream update modal to prevent missed add/remove actions

* feat: add admin upstream model update notifications with digest and truncation

* fix: avoid repeated partial-submit confirmation in upstream update modal

* feat: improve ui/ux

* feat: suppress upstream update alerts for unchanged channel-count within 24h

* fix: submit upstream update choices even when no models are selected

* feat: improve upstream model update flow and split frontend updater

* fix merge conflict
2026-03-02 22:01:53 +08:00

57 lines
1.6 KiB
JavaScript
Vendored

/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
export const normalizeModelList = (models = []) =>
Array.from(
new Set(
(models || []).map((model) => String(model || '').trim()).filter(Boolean),
),
);
export const parseUpstreamUpdateMeta = (settings) => {
let parsed = null;
if (settings && typeof settings === 'object') {
parsed = settings;
} else if (typeof settings === 'string') {
try {
parsed = JSON.parse(settings);
} catch (error) {
parsed = null;
}
}
if (!parsed || typeof parsed !== 'object') {
return {
enabled: false,
pendingAddModels: [],
pendingRemoveModels: [],
};
}
return {
enabled: parsed.upstream_model_update_check_enabled === true,
pendingAddModels: normalizeModelList(
parsed.upstream_model_update_last_detected_models,
),
pendingRemoveModels: normalizeModelList(
parsed.upstream_model_update_last_removed_models,
),
};
};