feat(integrations): добавить ручной sync с CFDM
Docker / build (push) Failing after 22s

Кнопка в настройках запрашивает полную выгрузку bindings из CFDM.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Denozordec
2026-07-31 23:24:04 +07:00
co-authored by Cursor
parent 5bbf0061cf
commit 033557a859
9 changed files with 215 additions and 17 deletions
+50
View File
@@ -0,0 +1,50 @@
import { settingsRepository } from '@cfdm/db/repositories/settings'
function resolveCfdmApiBase(): string | null {
const row = settingsRepository.getBySpace()
if (!row) return null
const explicit = row.cfdmApiUrl?.trim()
if (explicit) return explicit.replace(/\/$/, '')
const cfdm = settingsRepository.getAppSwitcher().apps.find((a) => a.id === 'cfdm')
return cfdm?.url?.trim().replace(/\/$/, '') ?? null
}
export async function requestCfdmFullSync(): Promise<{
ok: boolean
count?: number
error?: string
}> {
const row = settingsRepository.getBySpace()
if (!row?.integrationEnabled) {
return { ok: false, error: 'Включите приём синхронизации' }
}
const token = settingsRepository.getIntegrationToken()
const baseUrl = resolveCfdmApiBase()
if (!baseUrl) return { ok: false, error: 'Укажите URL API CFDM' }
if (!token) return { ok: false, error: 'Укажите integration token' }
try {
const res = await fetch(`${baseUrl}/api/v1/integrations/vps-tracker/sync`, {
method: 'POST',
headers: { Authorization: `Bearer ${token}` },
})
const body = (await res.json().catch(() => ({}))) as {
ok?: boolean
count?: number
error?: string
}
if (!res.ok || body.ok === false) {
return {
ok: false,
error: body.error ?? `HTTP ${res.status}`,
}
}
return { ok: true, count: body.count ?? 0 }
} catch (err) {
return {
ok: false,
error: err instanceof Error ? err.message : 'Ошибка сети',
}
}
}