40 lines
1.6 KiB
TypeScript
40 lines
1.6 KiB
TypeScript
import { detailCameraApi, detailDevoderApi, detailKeyboardAPi, detailMediaServerApi, detailNvr, detailSecurityBoxApi, detailSwitchApi, detailVideoServerApi, type NdmDeviceResultVO } from '@/apis';
|
|
import { DeviceType, tryGetDeviceTypeVal } from '@/enums';
|
|
|
|
export const detailDeviceApi = async (device: NdmDeviceResultVO, options?: { stationCode?: string; signal?: AbortSignal }): Promise<NdmDeviceResultVO | undefined> => {
|
|
const { stationCode, signal } = options ?? {};
|
|
const { id, deviceType: deviceTypeCode } = device;
|
|
if (!id || !deviceTypeCode) {
|
|
throw new Error('未知的设备');
|
|
}
|
|
const deviceTypeVal = tryGetDeviceTypeVal(deviceTypeCode);
|
|
if (!deviceTypeVal) {
|
|
throw new Error('未知的设备类型');
|
|
}
|
|
if (deviceTypeVal === DeviceType.Camera) {
|
|
return await detailCameraApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceTypeVal === DeviceType.Decoder) {
|
|
return await detailDevoderApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceTypeVal === DeviceType.Keyboard) {
|
|
return await detailKeyboardAPi(id, { stationCode, signal });
|
|
}
|
|
if (deviceTypeVal === DeviceType.MediaServer) {
|
|
return await detailMediaServerApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceTypeVal === DeviceType.Nvr) {
|
|
return await detailNvr(id, { stationCode, signal });
|
|
}
|
|
if (deviceTypeVal === DeviceType.SecurityBox) {
|
|
return await detailSecurityBoxApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceTypeVal === DeviceType.Switch) {
|
|
return await detailSwitchApi(id, { stationCode, signal });
|
|
}
|
|
if (deviceTypeVal === DeviceType.VideoServer) {
|
|
return await detailVideoServerApi(id, { stationCode, signal });
|
|
}
|
|
return undefined;
|
|
};
|