import { ndmClient, userClient, type ImportMsg, type NdmCameraPageQuery, type NdmCameraResultVO, type NdmCameraSaveVO, type NdmCameraUpdateVO, type PageParams, type PageResult, type SnapResult, type Station, } from '@/apis'; import { unwrapResponse } from '@/utils'; export const pageCameraApi = async (pageQuery: PageParams, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : userClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmCamera/page`; const resp = await client.post>(endpoint, pageQuery, { signal }); const data = unwrapResponse(resp); return data; }; export const detailCameraApi = async (id: string, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : userClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmCamera/detail`; const resp = await client.get(endpoint, { params: { id }, signal }); const data = unwrapResponse(resp); return data; }; export const saveCameraApi = async (saveVO: NdmCameraSaveVO, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : userClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmCamera`; const resp = await client.post(endpoint, saveVO, { signal }); const data = unwrapResponse(resp); return data; }; export const updateCameraApi = async (updateVO: NdmCameraUpdateVO, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : userClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmCamera`; const resp = await client.put(endpoint, updateVO, { signal }); const data = unwrapResponse(resp); return data; }; export const deleteCameraApi = async (ids: string[], options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : userClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmCamera`; const resp = await client.delete(endpoint, ids, { signal }); const data = unwrapResponse(resp); return data; }; export const exportCameraApi = async (pageQuery: PageParams, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : userClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmCamera/defaultExportByTemplate`; const resp = await client.post(endpoint, pageQuery, { responseType: 'blob', retRaw: true, signal }); const data = unwrapResponse(resp); return data; }; export const importCameraApi = async (file: File, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : userClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmCamera/importReturnMsg`; const formData = new FormData(); formData.append('file', file); const resp = await client.post(endpoint, formData, { signal, upload: true }); const data = unwrapResponse(resp); return data; }; export const getCameraSnapApi = async (deviceId: string, options?: { signal?: AbortSignal }) => { const { signal } = options ?? {}; const endpoint = `/api/ndm/ndmCamera/getSnapByDeviceId`; const resp = await ndmClient.get(endpoint, { params: { deviceId }, signal }); const data = unwrapResponse(resp); return data; }; export const syncCameraApi = async (options?: { stationCode?: string; signal?: AbortSignal }) => { const { stationCode, signal } = options ?? {}; const client = stationCode ? ndmClient : userClient; const prefix = stationCode ? `/${stationCode}` : ''; const endpoint = `${prefix}/api/ndm/ndmCamera/syncCamera`; const resp = await client.get(endpoint, { signal }); const data = unwrapResponse(resp); return data; };