51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
import {
|
|
detailCameraApi,
|
|
detailDecoderApi,
|
|
detailKeyboardApi,
|
|
detailMediaServerApi,
|
|
detailNvrApi,
|
|
detailSecurityBoxApi,
|
|
detailSwitchApi,
|
|
detailVideoServerApi,
|
|
type NdmDeviceResultVO,
|
|
type Station,
|
|
} from '@/apis';
|
|
import { DEVICE_TYPE_LITERALS, tryGetDeviceType } from '@/enums';
|
|
import { detailAlarmHostApi } from '../alarm/ndm-alarm-host';
|
|
|
|
export const detailDeviceApi = async (device: NdmDeviceResultVO, options?: { stationCode?: Station['code']; signal?: AbortSignal }): Promise<NdmDeviceResultVO | undefined> => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const { id, deviceType: deviceTypeCode } = device;
|
|
if (!id || !deviceTypeCode) throw new Error('未知的设备');
|
|
const deviceType = tryGetDeviceType(deviceTypeCode);
|
|
if (!deviceType) throw new Error('未知的设备');
|
|
if (deviceType === DEVICE_TYPE_LITERALS.ndmAlarmHost) {
|
|
return await detailAlarmHostApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceType === DEVICE_TYPE_LITERALS.ndmCamera) {
|
|
return await detailCameraApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceType === DEVICE_TYPE_LITERALS.ndmDecoder) {
|
|
return await detailDecoderApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceType === DEVICE_TYPE_LITERALS.ndmKeyboard) {
|
|
return await detailKeyboardApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceType === DEVICE_TYPE_LITERALS.ndmMediaServer) {
|
|
return await detailMediaServerApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceType === DEVICE_TYPE_LITERALS.ndmNvr) {
|
|
return await detailNvrApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceType === DEVICE_TYPE_LITERALS.ndmSecurityBox) {
|
|
return await detailSecurityBoxApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceType === DEVICE_TYPE_LITERALS.ndmSwitch) {
|
|
return await detailSwitchApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceType === DEVICE_TYPE_LITERALS.ndmVideoServer) {
|
|
return await detailVideoServerApi(id, { stationCode, signal });
|
|
}
|
|
return undefined;
|
|
};
|