mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
fix: improve the behavior for the web app
This commit is contained in:
+11
-1
@@ -91,12 +91,14 @@ export async function exportDb() {
|
||||
customModels: [],
|
||||
mitmAlias: {},
|
||||
pricing: {},
|
||||
disabledModels: {},
|
||||
};
|
||||
|
||||
for (const r of db.all(`SELECT key, value FROM kv WHERE scope = 'modelAliases'`)) out.modelAliases[r.key] = parseJson(r.value);
|
||||
for (const r of db.all(`SELECT key, value FROM kv WHERE scope = 'customModels'`)) out.customModels.push(parseJson(r.value));
|
||||
for (const r of db.all(`SELECT key, value FROM kv WHERE scope = 'mitmAlias'`)) out.mitmAlias[r.key] = parseJson(r.value);
|
||||
for (const r of db.all(`SELECT key, value FROM kv WHERE scope = 'pricing'`)) out.pricing[r.key] = parseJson(r.value);
|
||||
for (const r of db.all(`SELECT key, value FROM kv WHERE scope = 'disabledModels'`)) out.disabledModels[r.key] = parseJson(r.value, []);
|
||||
|
||||
return out;
|
||||
}
|
||||
@@ -127,7 +129,7 @@ export async function importDb(payload) {
|
||||
db.run(`DELETE FROM proxyPools`);
|
||||
db.run(`DELETE FROM apiKeys`);
|
||||
db.run(`DELETE FROM combos`);
|
||||
db.run(`DELETE FROM kv WHERE scope IN ('modelAliases', 'customModels', 'mitmAlias', 'pricing')`);
|
||||
db.run(`DELETE FROM kv WHERE scope IN ('modelAliases', 'customModels', 'mitmAlias', 'pricing', 'disabledModels')`);
|
||||
|
||||
// Settings
|
||||
if (payload.settings) {
|
||||
@@ -192,6 +194,14 @@ export async function importDb(payload) {
|
||||
for (const [provider, models] of Object.entries(payload.pricing || {})) {
|
||||
db.run(`INSERT OR REPLACE INTO kv(scope, key, value) VALUES('pricing', ?, ?)`, [provider, stringifyJson(models || {})]);
|
||||
}
|
||||
for (const [providerAlias, modelIds] of Object.entries(payload.disabledModels || {})) {
|
||||
const validModelIds = Array.isArray(modelIds)
|
||||
? modelIds.filter((modelId) => typeof modelId === "string" && modelId)
|
||||
: [];
|
||||
if (providerAlias && validModelIds.length > 0) {
|
||||
db.run(`INSERT OR REPLACE INTO kv(scope, key, value) VALUES('disabledModels', ?, ?)`, [providerAlias, stringifyJson([...new Set(validModelIds)])]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return await exportDb();
|
||||
|
||||
Reference in New Issue
Block a user