feat: 改进api生成方式

This commit is contained in:
2025-07-11 14:32:26 +08:00
parent bdffba7576
commit d88c710606
4 changed files with 720 additions and 99 deletions

View File

@@ -327,7 +327,7 @@ export class BsdlParserClient {
* [TODO:description]
* @return [TODO:return]
*/
getBoundaryLogicalPorts(): Promise<FileResponse> {
getBoundaryLogicalPorts(): Promise<FileResponse | null> {
let url_ = this.baseUrl + "/api/BsdlParser/GetBoundaryLogicalPorts";
url_ = url_.replace(/[?&]$/, "");
@@ -343,7 +343,7 @@ export class BsdlParserClient {
});
}
protected processGetBoundaryLogicalPorts(response: Response): Promise<FileResponse> {
protected processGetBoundaryLogicalPorts(response: Response): Promise<FileResponse | null> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200 || status === 206) {
@@ -362,7 +362,7 @@ export class BsdlParserClient {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<FileResponse>(null as any);
return Promise.resolve<FileResponse | null>(null as any);
}
}
@@ -377,11 +377,21 @@ export class DataClient {
}
/**
* 创建数据库表
* @return 插入的记录数
* [TODO:description]
* @param name (optional) [TODO:parameter]
* @param password (optional) [TODO:parameter]
* @return [TODO:return]
*/
createTables(): Promise<FileResponse> {
let url_ = this.baseUrl + "/api/Data/CreateTable";
login(name: string | undefined, password: string | undefined): Promise<FileResponse | null> {
let url_ = this.baseUrl + "/api/Data/login?";
if (name === null)
throw new Error("The parameter 'name' cannot be null.");
else if (name !== undefined)
url_ += "name=" + encodeURIComponent("" + name) + "&";
if (password === null)
throw new Error("The parameter 'password' cannot be null.");
else if (password !== undefined)
url_ += "password=" + encodeURIComponent("" + password) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
@@ -392,11 +402,11 @@ export class DataClient {
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processCreateTables(_response);
return this.processLogin(_response);
});
}
protected processCreateTables(response: Response): Promise<FileResponse> {
protected processLogin(response: Response): Promise<FileResponse | null> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200 || status === 206) {
@@ -415,57 +425,15 @@ export class DataClient {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<FileResponse>(null as any);
return Promise.resolve<FileResponse | null>(null as any);
}
/**
* 删除数据库表
* @return 插入的记录数
* [TODO:description]
* @return [TODO:return]
*/
dropTables(): Promise<FileResponse> {
let url_ = this.baseUrl + "/api/Data/DropTables";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "DELETE",
headers: {
"Accept": "application/octet-stream"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processDropTables(_response);
});
}
protected processDropTables(response: Response): Promise<FileResponse> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200 || status === 206) {
const contentDisposition = response.headers ? response.headers.get("content-disposition") : undefined;
let fileNameMatch = contentDisposition ? /filename\*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/g.exec(contentDisposition) : undefined;
let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;
if (fileName) {
fileName = decodeURIComponent(fileName);
} else {
fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
}
return response.blob().then(blob => { return { fileName: fileName, data: blob, status: status, headers: _headers }; });
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<FileResponse>(null as any);
}
/**
* 获取所有用户
* @return 用户列表
*/
allUsers(): Promise<FileResponse> {
let url_ = this.baseUrl + "/api/Data/AllUsers";
testAuth(): Promise<FileResponse | null> {
let url_ = this.baseUrl + "/api/Data/TestAuth";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
@@ -476,11 +444,11 @@ export class DataClient {
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processAllUsers(_response);
return this.processTestAuth(_response);
});
}
protected processAllUsers(response: Response): Promise<FileResponse> {
protected processTestAuth(response: Response): Promise<FileResponse | null> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200 || status === 206) {
@@ -499,20 +467,30 @@ export class DataClient {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<FileResponse>(null as any);
return Promise.resolve<FileResponse | null>(null as any);
}
/**
* 注册新用户
* @param name (optional) 用户名
* @param email (optional) [TODO:parameter]
* @param password (optional) [TODO:parameter]
* @return 操作结果
*/
signUpUser(name: string | undefined): Promise<FileResponse> {
signUpUser(name: string | undefined, email: string | undefined, password: string | undefined): Promise<FileResponse | null> {
let url_ = this.baseUrl + "/api/Data/SignUpUser?";
if (name === null)
throw new Error("The parameter 'name' cannot be null.");
else if (name !== undefined)
url_ += "name=" + encodeURIComponent("" + name) + "&";
if (email === null)
throw new Error("The parameter 'email' cannot be null.");
else if (email !== undefined)
url_ += "email=" + encodeURIComponent("" + email) + "&";
if (password === null)
throw new Error("The parameter 'password' cannot be null.");
else if (password !== undefined)
url_ += "password=" + encodeURIComponent("" + password) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
@@ -527,7 +505,7 @@ export class DataClient {
});
}
protected processSignUpUser(response: Response): Promise<FileResponse> {
protected processSignUpUser(response: Response): Promise<FileResponse | null> {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200 || status === 206) {
@@ -546,7 +524,7 @@ export class DataClient {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve<FileResponse>(null as any);
return Promise.resolve<FileResponse | null>(null as any);
}
}
@@ -943,9 +921,9 @@ export class JtagClient {
/**
* 上传比特流文件
* @param address (optional) 设备地址
* @param file (optional)
* @param file (optional) 比特流文件
*/
uploadBitstream(address: string | undefined, file: FileParameter | null | undefined): Promise<boolean> {
uploadBitstream(address: string | undefined, file: FileParameter | undefined): Promise<boolean> {
let url_ = this.baseUrl + "/api/Jtag/UploadBitstream?";
if (address === null)
throw new Error("The parameter 'address' cannot be null.");
@@ -954,7 +932,9 @@ export class JtagClient {
url_ = url_.replace(/[?&]$/, "");
const content_ = new FormData();
if (file !== null && file !== undefined)
if (file === null || file === undefined)
throw new Error("The parameter 'file' cannot be null.");
else
content_.append("file", file.data, file.fileName ? file.fileName : "file");
let options_: RequestInit = {
@@ -1519,10 +1499,10 @@ export class RemoteUpdateClient {
/**
* 上传远程更新比特流文件
* @param address (optional) 设备地址
* @param goldenBitream (optional)
* @param bitstream1 (optional)
* @param bitstream2 (optional)
* @param bitstream3 (optional)
* @param goldenBitream (optional) 黄金比特流文件
* @param bitstream1 (optional) 比特流文件1
* @param bitstream2 (optional) 比特流文件2
* @param bitstream3 (optional) 比特流文件3
* @return 上传结果
*/
uploadBitstreams(address: string | undefined, goldenBitream: FileParameter | null | undefined, bitstream1: FileParameter | null | undefined, bitstream2: FileParameter | null | undefined, bitstream3: FileParameter | null | undefined): Promise<boolean> {
@@ -2156,7 +2136,7 @@ export class UDPClient {
/**
* 获取指定IP地址接收的数据列表
* @param address (optional) IP地址
* @param taskID (optional)
* @param taskID (optional) 任务ID
*/
getRecvDataArray(address: string | undefined, taskID: number | undefined): Promise<UDPData[]> {
let url_ = this.baseUrl + "/api/UDP/GetRecvDataArray?";
@@ -2213,7 +2193,7 @@ export class UDPClient {
}
export class Exception implements IException {
message?: string;
message!: string;
innerException?: Exception | undefined;
source?: string | undefined;
stackTrace?: string | undefined;
@@ -2254,7 +2234,7 @@ export class Exception implements IException {
}
export interface IException {
message?: string;
message: string;
innerException?: Exception | undefined;
source?: string | undefined;
stackTrace?: string | undefined;
@@ -2262,7 +2242,9 @@ export interface IException {
/** 摄像头配置请求模型 */
export class CameraConfigRequest implements ICameraConfigRequest {
/** 摄像头地址 */
address!: string;
/** 摄像头端口 */
port!: number;
constructor(data?: ICameraConfigRequest) {
@@ -2298,7 +2280,9 @@ export class CameraConfigRequest implements ICameraConfigRequest {
/** 摄像头配置请求模型 */
export interface ICameraConfigRequest {
/** 摄像头地址 */
address: string;
/** 摄像头端口 */
port: number;
}
@@ -2330,6 +2314,7 @@ export interface ISystemException extends IException {
}
export class ArgumentException extends SystemException implements IArgumentException {
declare message: string;
paramName?: string | undefined;
constructor(data?: IArgumentException) {
@@ -2361,22 +2346,22 @@ export class ArgumentException extends SystemException implements IArgumentExcep
}
export interface IArgumentException extends ISystemException {
message?: string;
message: string;
paramName?: string | undefined;
}
/** Package options which to send address to read or write */
export class SendAddrPackOptions implements ISendAddrPackOptions {
/** 突发类型 */
burstType?: BurstType;
burstType!: BurstType;
/** 任务ID */
commandID?: number;
commandID!: number;
/** 标识写入还是读取 */
isWrite?: boolean;
isWrite!: boolean;
/** 突发长度0是32bits255是32bits x 256 */
burstLength?: number;
burstLength!: number;
/** 目标地址 */
address?: number;
address!: number;
constructor(data?: ISendAddrPackOptions) {
if (data) {
@@ -2418,15 +2403,15 @@ export class SendAddrPackOptions implements ISendAddrPackOptions {
/** Package options which to send address to read or write */
export interface ISendAddrPackOptions {
/** 突发类型 */
burstType?: BurstType;
burstType: BurstType;
/** 任务ID */
commandID?: number;
commandID: number;
/** 标识写入还是读取 */
isWrite?: boolean;
isWrite: boolean;
/** 突发长度0是32bits255是32bits x 256 */
burstLength?: number;
burstLength: number;
/** 目标地址 */
address?: number;
address: number;
}
/** Package Burst Type */
@@ -2438,17 +2423,17 @@ export enum BurstType {
/** UDP接受数据包格式 */
export class UDPData implements IUDPData {
/** 接受到的时间 */
dateTime?: Date;
dateTime!: Date;
/** 发送来源的IP地址 */
address?: string;
address!: string;
/** 发送来源的端口号 */
port?: number;
port!: number;
/** 任务ID */
taskID?: number;
taskID!: number;
/** 接受到的数据 */
data?: string;
data!: string;
/** 是否被读取过 */
hasRead?: boolean;
hasRead!: boolean;
constructor(data?: IUDPData) {
if (data) {
@@ -2492,17 +2477,17 @@ export class UDPData implements IUDPData {
/** UDP接受数据包格式 */
export interface IUDPData {
/** 接受到的时间 */
dateTime?: Date;
dateTime: Date;
/** 发送来源的IP地址 */
address?: string;
address: string;
/** 发送来源的端口号 */
port?: number;
port: number;
/** 任务ID */
taskID?: number;
taskID: number;
/** 接受到的数据 */
data?: string;
data: string;
/** 是否被读取过 */
hasRead?: boolean;
hasRead: boolean;
}
export interface FileParameter {
@@ -2546,4 +2531,4 @@ function throwException(message: string, status: number, response: string, heade
throw result;
else
throw new ApiException(message, status, response, headers, null);
}
}