Files
lingxi-web/src/services/api/channels.ts
T

55 lines
1.8 KiB
TypeScript

import { http } from './client'
import type { ChannelConnection, ChannelSyncLog, ChannelType } from '@/types'
/** GET /api/channels */
export function getChannels() {
return http.get<ChannelConnection[]>('/api/channels')
}
/** POST /api/channels/connect */
export function connectChannel(payload: {
type: ChannelType
account: string
syncRange?: string
defaultOwnerId?: string
autoReply?: boolean
}) {
return http.post<ChannelConnection>('/api/channels/connect', payload)
}
export function startTelegramLogin(phone: string) {
return http.post<ChannelConnection>('/api/channels/telegram/start', { phone })
}
export function submitTelegramCode(channelId: string, code: string) {
return http.post<{ status: string; channel: ChannelConnection }>(`/api/channels/telegram/${channelId}/code`, { code })
}
export function submitTelegramPassword(channelId: string, password: string) {
return http.post<{ status: string; channel: ChannelConnection }>(`/api/channels/telegram/${channelId}/password`, { password })
}
export function syncTelegramChannel(channelId: string) {
return http.post<{ chats: number; messages: number }>(`/api/channels/${channelId}/sync`)
}
/** POST /api/channels/test */
export function testChannel(id: string) {
return http.post<{ success: boolean; latencyMs: number; message: string }>('/api/channels/test', { id })
}
/** PATCH /api/channels/:id */
export function updateChannel(id: string, payload: Partial<ChannelConnection>) {
return http.patch<ChannelConnection>(`/api/channels/${id}`, payload)
}
/** DELETE /api/channels/:id */
export function deleteChannel(id: string) {
return http.del<{ success: boolean }>(`/api/channels/${id}`)
}
/** GET /api/channels/:id/logs */
export function getChannelLogs(id: string) {
return http.get<ChannelSyncLog[]>(`/api/channels/${id}/logs`)
}