fix: hide stale AtlasCloud catalog entries

This commit is contained in:
134 2026-07-22 10:34:45 +08:00
parent 13ad80d0a4
commit b05d82963f

View File

@ -1,4 +1,4 @@
import { and, eq } from "drizzle-orm";
import { and, eq, inArray } from "drizzle-orm";
import { fetchAtlasCloudImagePresets } from "../lib/ai/atlascloud-models";
import { db } from "../lib/db";
import { aiModel, aiProvider } from "../lib/db/schema";
@ -22,6 +22,9 @@ async function main() {
}
const summaries = [];
const catalogModelIds = new Set(
catalog.presets.map((preset) => preset.modelId)
);
for (const provider of providers) {
let added = 0;
let updated = 0;
@ -65,11 +68,34 @@ async function main() {
added += 1;
}
}
const providerModels = await db
.select({ modelId: aiModel.modelId })
.from(aiModel)
.where(eq(aiModel.providerId, provider.id));
const staleModelIds = providerModels
.map((model) => model.modelId)
.filter((modelId) => !catalogModelIds.has(modelId));
if (staleModelIds.length > 0) {
await db
.update(aiModel)
.set({
isEnabled: false,
isHidden: true,
updatedAt: new Date(),
})
.where(
and(
eq(aiModel.providerId, provider.id),
inArray(aiModel.modelId, staleModelIds)
)
);
}
summaries.push({
providerId: provider.id,
providerName: provider.name,
added,
updated,
disabledStale: staleModelIds.length,
});
}