DCFronted/src/api/record.js

64 lines
1.7 KiB
JavaScript

import axiosInstance from './axiosConfig';
/**
* 上传处理后的录像文件
* 路由: /record/upload
* 方法: POST
* 需要admin权限
* @param {file} file - 表单负载"file"上传
* @returns {id<int>} - HTTP_202_ACCEPTED 录像id
*/
export const uploadRecord = async (file) => {
try {
const formData = new FormData();
formData.append('file', file);
const response = await axiosInstance.post('/record/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
return response.data;
} catch (error) {
console.error(error);
throw error;
}
};
/**
* 获取录像解析状态
* 路由: /record/{id}
* 方法: GET
* 需要登录
* @param {int} id - 录像id
* @returns {id<int>} id - 录像id
* @returns {status<string>} status - 状态processing 处理中success 处理成功fail 处理失败
* @returns {data<json>} data - 录像数据仅当处理成功时有值
*/
export const getRecordStatus = async (id) => {
try {
const response = await axiosInstance.get(`/record/${id}`);
return response.data;
} catch (error) {
console.error(error);
throw error;
}
}
/**
* 获取单位信息
* 路由: /unit
* 方法: GET
* 三个参数仅使用一个即可,如果传入多个优先选择上面的
* @param {Object} params - 参数 { id, code, name }
* @returns {id<string>} id
* @returns {code<string>} code
* @returns {name<string>} name
*/
export const unitInfo = async (params = {}) => {
try {
const response = await axiosInstance.get('/unit', { params });
return response.data;
} catch (error) {
console.error(error);
throw error;
}
}