Кнопка в настройках запрашивает полную выгрузку bindings из CFDM. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -125,7 +125,10 @@ export const vpsDomainsRepository = {
|
||||
return { updated }
|
||||
},
|
||||
|
||||
syncBindings(items: CfdmBindingSyncItem[]): {
|
||||
syncBindings(
|
||||
items: CfdmBindingSyncItem[],
|
||||
opts?: { fullSync?: boolean },
|
||||
): {
|
||||
matched: number
|
||||
unmatched: number
|
||||
deleted: number
|
||||
@@ -139,6 +142,7 @@ export const vpsDomainsRepository = {
|
||||
let unmatched = 0
|
||||
let deleted = 0
|
||||
let upserted = 0
|
||||
const keptBindingIds = new Set<number>()
|
||||
|
||||
for (const item of items) {
|
||||
if (item.deleted) {
|
||||
@@ -146,6 +150,8 @@ export const vpsDomainsRepository = {
|
||||
continue
|
||||
}
|
||||
|
||||
keptBindingIds.add(item.bindingId)
|
||||
|
||||
const vpsId = findVpsIdByIps(allVps, item.ips)
|
||||
const matchStatus = resolveMatchStatus(vpsId)
|
||||
if (matchStatus === 'matched') matched++
|
||||
@@ -176,6 +182,25 @@ export const vpsDomainsRepository = {
|
||||
upserted++
|
||||
}
|
||||
|
||||
if (opts?.fullSync) {
|
||||
const rows = db
|
||||
.select()
|
||||
.from(schema.vpsDomains)
|
||||
.where(
|
||||
and(
|
||||
eq(schema.vpsDomains.spaceId, spaceId),
|
||||
eq(schema.vpsDomains.source, 'cfdm'),
|
||||
),
|
||||
)
|
||||
.all()
|
||||
for (const row of rows) {
|
||||
if (!keptBindingIds.has(row.cfdmBindingId)) {
|
||||
db.delete(schema.vpsDomains).where(eq(schema.vpsDomains.id, row.id)).run()
|
||||
deleted++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { matched, unmatched, deleted, upserted }
|
||||
},
|
||||
|
||||
|
||||
@@ -13,7 +13,12 @@ export const cfdmBindingSyncItemSchema = z.object({
|
||||
})
|
||||
|
||||
export const cfdmSyncBindingsBodySchema = z.object({
|
||||
bindings: z.array(cfdmBindingSyncItemSchema).min(1),
|
||||
bindings: z.array(cfdmBindingSyncItemSchema),
|
||||
/** Полная пересинхронизация: удалить CFDM-домены, которых нет в payload. */
|
||||
fullSync: z.boolean().optional(),
|
||||
}).refine((data) => data.fullSync === true || data.bindings.length >= 1, {
|
||||
message: 'bindings обязателен, если fullSync не задан',
|
||||
path: ['bindings'],
|
||||
})
|
||||
|
||||
export type CfdmBindingSyncItem = z.infer<typeof cfdmBindingSyncItemSchema>
|
||||
|
||||
Reference in New Issue
Block a user