feat: 统一资源管理
This commit is contained in:
832
src/APIClient.ts
832
src/APIClient.ts
@@ -2942,277 +2942,6 @@ export class ExamClient {
|
||||
}
|
||||
return Promise.resolve<ExamInfo>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加实验资源
|
||||
* @param examId 实验ID
|
||||
* @param resourceType 资源类型
|
||||
* @param file (optional) 资源文件
|
||||
* @return 添加结果
|
||||
*/
|
||||
addExamResource(examId: string, resourceType: string, file: FileParameter | undefined, cancelToken?: CancelToken): Promise<ResourceInfo> {
|
||||
let url_ = this.baseUrl + "/api/Exam/{examId}/resources/{resourceType}";
|
||||
if (examId === undefined || examId === null)
|
||||
throw new Error("The parameter 'examId' must be defined.");
|
||||
url_ = url_.replace("{examId}", encodeURIComponent("" + examId));
|
||||
if (resourceType === undefined || resourceType === null)
|
||||
throw new Error("The parameter 'resourceType' must be defined.");
|
||||
url_ = url_.replace("{resourceType}", encodeURIComponent("" + resourceType));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
const content_ = new FormData();
|
||||
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_: AxiosRequestConfig = {
|
||||
data: content_,
|
||||
method: "POST",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processAddExamResource(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processAddExamResource(response: AxiosResponse): Promise<ResourceInfo> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 201) {
|
||||
const _responseText = response.data;
|
||||
let result201: any = null;
|
||||
let resultData201 = _responseText;
|
||||
result201 = ResourceInfo.fromJS(resultData201);
|
||||
return Promise.resolve<ResourceInfo>(result201);
|
||||
|
||||
} else if (status === 400) {
|
||||
const _responseText = response.data;
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText;
|
||||
result400 = ProblemDetails.fromJS(resultData400);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
|
||||
} else if (status === 401) {
|
||||
const _responseText = response.data;
|
||||
let result401: any = null;
|
||||
let resultData401 = _responseText;
|
||||
result401 = ProblemDetails.fromJS(resultData401);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
|
||||
|
||||
} else if (status === 403) {
|
||||
const _responseText = response.data;
|
||||
let result403: any = null;
|
||||
let resultData403 = _responseText;
|
||||
result403 = ProblemDetails.fromJS(resultData403);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result403);
|
||||
|
||||
} else if (status === 404) {
|
||||
const _responseText = response.data;
|
||||
let result404: any = null;
|
||||
let resultData404 = _responseText;
|
||||
result404 = ProblemDetails.fromJS(resultData404);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
|
||||
|
||||
} else if (status === 409) {
|
||||
const _responseText = response.data;
|
||||
let result409: any = null;
|
||||
let resultData409 = _responseText;
|
||||
result409 = ProblemDetails.fromJS(resultData409);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result409);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<ResourceInfo>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定实验ID的指定资源类型的所有资源的ID和名称
|
||||
* @param examId 实验ID
|
||||
* @param resourceType 资源类型
|
||||
* @return 资源列表
|
||||
*/
|
||||
getExamResourceList(examId: string, resourceType: string, cancelToken?: CancelToken): Promise<ResourceInfo[]> {
|
||||
let url_ = this.baseUrl + "/api/Exam/{examId}/resources/{resourceType}";
|
||||
if (examId === undefined || examId === null)
|
||||
throw new Error("The parameter 'examId' must be defined.");
|
||||
url_ = url_.replace("{examId}", encodeURIComponent("" + examId));
|
||||
if (resourceType === undefined || resourceType === null)
|
||||
throw new Error("The parameter 'resourceType' must be defined.");
|
||||
url_ = url_.replace("{resourceType}", encodeURIComponent("" + resourceType));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
method: "GET",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processGetExamResourceList(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetExamResourceList(response: AxiosResponse): Promise<ResourceInfo[]> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200) {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
if (Array.isArray(resultData200)) {
|
||||
result200 = [] as any;
|
||||
for (let item of resultData200)
|
||||
result200!.push(ResourceInfo.fromJS(item));
|
||||
}
|
||||
else {
|
||||
result200 = <any>null;
|
||||
}
|
||||
return Promise.resolve<ResourceInfo[]>(result200);
|
||||
|
||||
} else if (status === 400) {
|
||||
const _responseText = response.data;
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText;
|
||||
result400 = ProblemDetails.fromJS(resultData400);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
|
||||
} else if (status === 401) {
|
||||
const _responseText = response.data;
|
||||
let result401: any = null;
|
||||
let resultData401 = _responseText;
|
||||
result401 = ProblemDetails.fromJS(resultData401);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<ResourceInfo[]>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据资源ID下载资源
|
||||
* @param resourceId 资源ID
|
||||
* @return 资源文件
|
||||
*/
|
||||
getExamResourceById(resourceId: number, cancelToken?: CancelToken): Promise<FileResponse> {
|
||||
let url_ = this.baseUrl + "/api/Exam/resources/{resourceId}";
|
||||
if (resourceId === undefined || resourceId === null)
|
||||
throw new Error("The parameter 'resourceId' must be defined.");
|
||||
url_ = url_.replace("{resourceId}", encodeURIComponent("" + resourceId));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
responseType: "blob",
|
||||
method: "GET",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processGetExamResourceById(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetExamResourceById(response: AxiosResponse): Promise<FileResponse> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200 || status === 206) {
|
||||
const contentDisposition = response.headers ? response.headers["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 Promise.resolve({ fileName: fileName, status: status, data: new Blob([response.data], { type: response.headers["content-type"] }), headers: _headers });
|
||||
} else if (status === 400) {
|
||||
const _responseText = response.data;
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText;
|
||||
result400 = ProblemDetails.fromJS(resultData400);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
|
||||
} else if (status === 404) {
|
||||
const _responseText = response.data;
|
||||
let result404: any = null;
|
||||
let resultData404 = _responseText;
|
||||
result404 = ProblemDetails.fromJS(resultData404);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<FileResponse>(null as any);
|
||||
}
|
||||
}
|
||||
|
||||
export class JtagClient {
|
||||
@@ -3427,98 +3156,14 @@ export class JtagClient {
|
||||
return Promise.resolve<void>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传比特流文件到服务器
|
||||
* @param address (optional) 目标设备地址
|
||||
* @param file (optional) 比特流文件
|
||||
* @return 上传结果
|
||||
*/
|
||||
uploadBitstream(address: string | undefined, file: FileParameter | undefined, cancelToken?: CancelToken): Promise<boolean> {
|
||||
let url_ = this.baseUrl + "/api/Jtag/UploadBitstream?";
|
||||
if (address === null)
|
||||
throw new Error("The parameter 'address' cannot be null.");
|
||||
else if (address !== undefined)
|
||||
url_ += "address=" + encodeURIComponent("" + address) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
const content_ = new FormData();
|
||||
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_: AxiosRequestConfig = {
|
||||
data: content_,
|
||||
method: "POST",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processUploadBitstream(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processUploadBitstream(response: AxiosResponse): Promise<boolean> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200) {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
result200 = resultData200 !== undefined ? resultData200 : <any>null;
|
||||
|
||||
return Promise.resolve<boolean>(result200);
|
||||
|
||||
} else if (status === 400) {
|
||||
const _responseText = response.data;
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText;
|
||||
result400 = resultData400 !== undefined ? resultData400 : <any>null;
|
||||
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
|
||||
} else if (status === 401) {
|
||||
const _responseText = response.data;
|
||||
let result401: any = null;
|
||||
let resultData401 = _responseText;
|
||||
result401 = ProblemDetails.fromJS(resultData401);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<boolean>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过 JTAG 下载比特流文件到 FPGA 设备
|
||||
* @param address (optional) JTAG 设备地址
|
||||
* @param port (optional) JTAG 设备端口
|
||||
* @param bitstreamId (optional) 比特流ID
|
||||
* @return 下载结果
|
||||
*/
|
||||
downloadBitstream(address: string | undefined, port: number | undefined, cancelToken?: CancelToken): Promise<boolean> {
|
||||
downloadBitstream(address: string | undefined, port: number | undefined, bitstreamId: number | undefined, cancelToken?: CancelToken): Promise<boolean> {
|
||||
let url_ = this.baseUrl + "/api/Jtag/DownloadBitstream?";
|
||||
if (address === null)
|
||||
throw new Error("The parameter 'address' cannot be null.");
|
||||
@@ -3528,6 +3173,10 @@ export class JtagClient {
|
||||
throw new Error("The parameter 'port' cannot be null.");
|
||||
else if (port !== undefined)
|
||||
url_ += "port=" + encodeURIComponent("" + port) + "&";
|
||||
if (bitstreamId === null)
|
||||
throw new Error("The parameter 'bitstreamId' cannot be null.");
|
||||
else if (bitstreamId !== undefined)
|
||||
url_ += "bitstreamId=" + encodeURIComponent("" + bitstreamId) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
@@ -6565,6 +6214,353 @@ export class RemoteUpdateClient {
|
||||
}
|
||||
}
|
||||
|
||||
export class ResourceClient {
|
||||
protected instance: AxiosInstance;
|
||||
protected baseUrl: string;
|
||||
protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;
|
||||
|
||||
constructor(baseUrl?: string, instance?: AxiosInstance) {
|
||||
|
||||
this.instance = instance || axios.create();
|
||||
|
||||
this.baseUrl = baseUrl ?? "http://127.0.0.1:5000";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加资源(文件上传)
|
||||
* @param resourceType (optional) 资源类型
|
||||
* @param resourcePurpose (optional) 资源用途(template/user)
|
||||
* @param examID (optional) 所属实验ID(可选)
|
||||
* @param file (optional) 资源文件
|
||||
* @return 添加结果
|
||||
*/
|
||||
addResource(resourceType: string | undefined, resourcePurpose: string | undefined, examID: string | null | undefined, file: FileParameter | undefined, cancelToken?: CancelToken): Promise<ResourceInfo> {
|
||||
let url_ = this.baseUrl + "/api/Resource";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
const content_ = new FormData();
|
||||
if (resourceType === null || resourceType === undefined)
|
||||
throw new Error("The parameter 'resourceType' cannot be null.");
|
||||
else
|
||||
content_.append("ResourceType", resourceType.toString());
|
||||
if (resourcePurpose === null || resourcePurpose === undefined)
|
||||
throw new Error("The parameter 'resourcePurpose' cannot be null.");
|
||||
else
|
||||
content_.append("ResourcePurpose", resourcePurpose.toString());
|
||||
if (examID !== null && examID !== undefined)
|
||||
content_.append("ExamID", examID.toString());
|
||||
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_: AxiosRequestConfig = {
|
||||
data: content_,
|
||||
method: "POST",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processAddResource(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processAddResource(response: AxiosResponse): Promise<ResourceInfo> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 201) {
|
||||
const _responseText = response.data;
|
||||
let result201: any = null;
|
||||
let resultData201 = _responseText;
|
||||
result201 = ResourceInfo.fromJS(resultData201);
|
||||
return Promise.resolve<ResourceInfo>(result201);
|
||||
|
||||
} else if (status === 400) {
|
||||
const _responseText = response.data;
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText;
|
||||
result400 = ProblemDetails.fromJS(resultData400);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
|
||||
} else if (status === 401) {
|
||||
const _responseText = response.data;
|
||||
let result401: any = null;
|
||||
let resultData401 = _responseText;
|
||||
result401 = ProblemDetails.fromJS(resultData401);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
|
||||
|
||||
} else if (status === 404) {
|
||||
const _responseText = response.data;
|
||||
let result404: any = null;
|
||||
let resultData404 = _responseText;
|
||||
result404 = ProblemDetails.fromJS(resultData404);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<ResourceInfo>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资源列表
|
||||
* @param examId (optional) 实验ID(可选)
|
||||
* @param resourceType (optional) 资源类型(可选)
|
||||
* @param resourcePurpose (optional) 资源用途(可选)
|
||||
* @return 资源列表
|
||||
*/
|
||||
getResourceList(examId: string | null | undefined, resourceType: string | null | undefined, resourcePurpose: string | null | undefined, cancelToken?: CancelToken): Promise<ResourceInfo[]> {
|
||||
let url_ = this.baseUrl + "/api/Resource?";
|
||||
if (examId !== undefined && examId !== null)
|
||||
url_ += "examId=" + encodeURIComponent("" + examId) + "&";
|
||||
if (resourceType !== undefined && resourceType !== null)
|
||||
url_ += "resourceType=" + encodeURIComponent("" + resourceType) + "&";
|
||||
if (resourcePurpose !== undefined && resourcePurpose !== null)
|
||||
url_ += "resourcePurpose=" + encodeURIComponent("" + resourcePurpose) + "&";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
method: "GET",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processGetResourceList(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetResourceList(response: AxiosResponse): Promise<ResourceInfo[]> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200) {
|
||||
const _responseText = response.data;
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText;
|
||||
if (Array.isArray(resultData200)) {
|
||||
result200 = [] as any;
|
||||
for (let item of resultData200)
|
||||
result200!.push(ResourceInfo.fromJS(item));
|
||||
}
|
||||
else {
|
||||
result200 = <any>null;
|
||||
}
|
||||
return Promise.resolve<ResourceInfo[]>(result200);
|
||||
|
||||
} else if (status === 401) {
|
||||
const _responseText = response.data;
|
||||
let result401: any = null;
|
||||
let resultData401 = _responseText;
|
||||
result401 = ProblemDetails.fromJS(resultData401);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<ResourceInfo[]>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据资源ID下载资源
|
||||
* @param resourceId 资源ID
|
||||
* @return 资源文件
|
||||
*/
|
||||
getResourceById(resourceId: number, cancelToken?: CancelToken): Promise<FileResponse> {
|
||||
let url_ = this.baseUrl + "/api/Resource/{resourceId}";
|
||||
if (resourceId === undefined || resourceId === null)
|
||||
throw new Error("The parameter 'resourceId' must be defined.");
|
||||
url_ = url_.replace("{resourceId}", encodeURIComponent("" + resourceId));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
responseType: "blob",
|
||||
method: "GET",
|
||||
url: url_,
|
||||
headers: {
|
||||
"Accept": "application/json"
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processGetResourceById(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetResourceById(response: AxiosResponse): Promise<FileResponse> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 200 || status === 206) {
|
||||
const contentDisposition = response.headers ? response.headers["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 Promise.resolve({ fileName: fileName, status: status, data: new Blob([response.data], { type: response.headers["content-type"] }), headers: _headers });
|
||||
} else if (status === 400) {
|
||||
const _responseText = response.data;
|
||||
let result400: any = null;
|
||||
let resultData400 = _responseText;
|
||||
result400 = ProblemDetails.fromJS(resultData400);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
|
||||
|
||||
} else if (status === 404) {
|
||||
const _responseText = response.data;
|
||||
let result404: any = null;
|
||||
let resultData404 = _responseText;
|
||||
result404 = ProblemDetails.fromJS(resultData404);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<FileResponse>(null as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除资源
|
||||
* @param resourceId 资源ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
deleteResource(resourceId: number, cancelToken?: CancelToken): Promise<void> {
|
||||
let url_ = this.baseUrl + "/api/Resource/{resourceId}";
|
||||
if (resourceId === undefined || resourceId === null)
|
||||
throw new Error("The parameter 'resourceId' must be defined.");
|
||||
url_ = url_.replace("{resourceId}", encodeURIComponent("" + resourceId));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_: AxiosRequestConfig = {
|
||||
method: "DELETE",
|
||||
url: url_,
|
||||
headers: {
|
||||
},
|
||||
cancelToken
|
||||
};
|
||||
|
||||
return this.instance.request(options_).catch((_error: any) => {
|
||||
if (isAxiosError(_error) && _error.response) {
|
||||
return _error.response;
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}).then((_response: AxiosResponse) => {
|
||||
return this.processDeleteResource(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processDeleteResource(response: AxiosResponse): Promise<void> {
|
||||
const status = response.status;
|
||||
let _headers: any = {};
|
||||
if (response.headers && typeof response.headers === "object") {
|
||||
for (const k in response.headers) {
|
||||
if (response.headers.hasOwnProperty(k)) {
|
||||
_headers[k] = response.headers[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status === 204) {
|
||||
const _responseText = response.data;
|
||||
return Promise.resolve<void>(null as any);
|
||||
|
||||
} else if (status === 401) {
|
||||
const _responseText = response.data;
|
||||
let result401: any = null;
|
||||
let resultData401 = _responseText;
|
||||
result401 = ProblemDetails.fromJS(resultData401);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result401);
|
||||
|
||||
} else if (status === 403) {
|
||||
const _responseText = response.data;
|
||||
let result403: any = null;
|
||||
let resultData403 = _responseText;
|
||||
result403 = ProblemDetails.fromJS(resultData403);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result403);
|
||||
|
||||
} else if (status === 404) {
|
||||
const _responseText = response.data;
|
||||
let result404: any = null;
|
||||
let resultData404 = _responseText;
|
||||
result404 = ProblemDetails.fromJS(resultData404);
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
|
||||
|
||||
} else if (status === 500) {
|
||||
const _responseText = response.data;
|
||||
return throwException("A server side error occurred.", status, _responseText, _headers);
|
||||
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
const _responseText = response.data;
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
}
|
||||
return Promise.resolve<void>(null as any);
|
||||
}
|
||||
}
|
||||
|
||||
export class TutorialClient {
|
||||
protected instance: AxiosInstance;
|
||||
protected baseUrl: string;
|
||||
@@ -8023,52 +8019,6 @@ export interface ICreateExamRequest {
|
||||
isVisibleToUsers: boolean;
|
||||
}
|
||||
|
||||
/** 资源信息类 */
|
||||
export class ResourceInfo implements IResourceInfo {
|
||||
/** 资源ID */
|
||||
id!: number;
|
||||
/** 资源名称 */
|
||||
name!: string;
|
||||
|
||||
constructor(data?: IResourceInfo) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
(<any>this)[property] = (<any>data)[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.id = _data["id"];
|
||||
this.name = _data["name"];
|
||||
}
|
||||
}
|
||||
|
||||
static fromJS(data: any): ResourceInfo {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
let result = new ResourceInfo();
|
||||
result.init(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["id"] = this.id;
|
||||
data["name"] = this.name;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/** 资源信息类 */
|
||||
export interface IResourceInfo {
|
||||
/** 资源ID */
|
||||
id: number;
|
||||
/** 资源名称 */
|
||||
name: string;
|
||||
}
|
||||
|
||||
/** 逻辑分析仪运行状态枚举 */
|
||||
export enum CaptureStatus {
|
||||
None = 0,
|
||||
@@ -8518,6 +8468,82 @@ export interface IOscilloscopeDataResponse {
|
||||
waveformData: string;
|
||||
}
|
||||
|
||||
/** 资源信息类 */
|
||||
export class ResourceInfo implements IResourceInfo {
|
||||
/** 资源ID */
|
||||
id!: number;
|
||||
/** 资源名称 */
|
||||
name!: string;
|
||||
/** 资源类型 */
|
||||
type!: string;
|
||||
/** 资源用途(template/user) */
|
||||
purpose!: string;
|
||||
/** 上传时间 */
|
||||
uploadTime!: Date;
|
||||
/** 所属实验ID(可选) */
|
||||
examID?: string | undefined;
|
||||
/** MIME类型 */
|
||||
mimeType?: string | undefined;
|
||||
|
||||
constructor(data?: IResourceInfo) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
(<any>this)[property] = (<any>data)[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.id = _data["id"];
|
||||
this.name = _data["name"];
|
||||
this.type = _data["type"];
|
||||
this.purpose = _data["purpose"];
|
||||
this.uploadTime = _data["uploadTime"] ? new Date(_data["uploadTime"].toString()) : <any>undefined;
|
||||
this.examID = _data["examID"];
|
||||
this.mimeType = _data["mimeType"];
|
||||
}
|
||||
}
|
||||
|
||||
static fromJS(data: any): ResourceInfo {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
let result = new ResourceInfo();
|
||||
result.init(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["id"] = this.id;
|
||||
data["name"] = this.name;
|
||||
data["type"] = this.type;
|
||||
data["purpose"] = this.purpose;
|
||||
data["uploadTime"] = this.uploadTime ? this.uploadTime.toISOString() : <any>undefined;
|
||||
data["examID"] = this.examID;
|
||||
data["mimeType"] = this.mimeType;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/** 资源信息类 */
|
||||
export interface IResourceInfo {
|
||||
/** 资源ID */
|
||||
id: number;
|
||||
/** 资源名称 */
|
||||
name: string;
|
||||
/** 资源类型 */
|
||||
type: string;
|
||||
/** 资源用途(template/user) */
|
||||
purpose: string;
|
||||
/** 上传时间 */
|
||||
uploadTime: Date;
|
||||
/** 所属实验ID(可选) */
|
||||
examID?: string | undefined;
|
||||
/** MIME类型 */
|
||||
mimeType?: string | undefined;
|
||||
}
|
||||
|
||||
/** Package options which to send address to read or write */
|
||||
export class SendAddrPackOptions implements ISendAddrPackOptions {
|
||||
/** 突发类型 */
|
||||
|
||||
Reference in New Issue
Block a user