forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
150 lines (135 loc) · 4.49 KB
/
Copy pathapi.ts
File metadata and controls
150 lines (135 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
import {API_BASE} from 'Constants';
import request from 'Utils/request';
import {Result} from '@src/interfaces/http.interface';
//login
export function login<T>(data: any): Promise<Result<T>> {
return request('/rest/v1/login', {
method: 'POST',
headers: {Authorization: data.password ? `Basic ${btoa(data.username + ':' + data.password)}` : `Basic ${btoa(data.username + ':')}`},
});
}
//logout
export function logOut<T>(): Promise<Result<T>> {
return request(`/rest/v1/logout`, {
method: 'POST',
});
}
//home
export function getHardwareInfo<T>(): Promise<Result<T>> {
return request(`/rest/v1/hardware_info/fe/`, {
method: 'GET',
});
}
//system
export function getSystem<T>(data: any): Promise<Result<T>> {
return request(`/rest/v1/system${data.path}`, {
method: 'GET',
...data
});
}
//log
export function getLog<T>(data: any): Promise<Result<T>> {
let localUrl = '/rest/v1/log';
if (data.add_verbose) {
localUrl = `/rest/v1/log?add_verbose=${data.add_verbose}`;
}
if (data.del_verbose) {
localUrl = `/rest/v1/log?del_verbose=${data.del_verbose}`;
}
// if (data.add_verbose && data.del_verbose) {
// localUrl += `/rest/v1/log?add_verbose=${data.add_verbose}&&del_verbose=${data.del_verbose}`;
// }
return request(localUrl, {
method: (data.add_verbose || data.del_verbose) ? 'POST' : 'GET',
...data
});
}
//query_profile
export function queryProfile<T>(data: any): Promise<Result<T>> {
let LocalUrl = '/rest/v1/query_profile/';
if (data.path) {
LocalUrl = `/rest/v1/query_profile/${data.path}`;
}
return request(LocalUrl, data);
}
//session
export function getSession<T>(data: any): Promise<Result<T>> {
return request('/rest/v1/session', data);
}
//config
export function getConfig<T>(data: any): Promise<Result<T>> {
return request('/rest/v1/config/fe/', data);
}
//query begin
export function getDatabaseList<T>(data?: any): Promise<Result<T>> {
let reURL = `${API_BASE}default_cluster/databases`;
if (data) {
if (data.db_name) {
reURL += `/${data.db_name}/tables`;
}
if (data.db_name && data.tbl_name) {
reURL += `/${data.tbl_name}/schema`;
}
}
return request(reURL, data);
}
export function doQuery<T>(data: any): Promise<Result<T>> {
return request(`/api/query/internal/${data.db_name}`, {
method: 'POST', ...data,
});
}
export function doUp<T>(data: any): Promise<Result<T>> {
let localHeader = {
label: data.label,
columns: data.columns,
column_separator: data.column_separator
}
if (!localHeader.columns) {
delete localHeader.columns
}
return request(`/api/default_cluster/${data.db_name}/${data.tbl_name}/upload?file_id=${data.file_id}&file_uuid=${data.file_uuid}`, {
method: 'PUT', headers: localHeader,
});
}
export function getUploadData<T>(data: any): Promise<Result<T>> {
let localUrl = `/api/default_cluster/${data.db_name}/${data.tbl_name}/upload`
if (data.preview) {
localUrl = `/api/default_cluster/${data.db_name}/${data.tbl_name}/upload?file_id=${data.file_id}&file_uuid=${data.file_uuid}&preview=true`
}
return request(localUrl, {
method: 'GET',
});
}
export function deleteUploadData<T>(data: any): Promise<Result<T>> {
return request(`/api/default_cluster/${data.db_name}/${data.tbl_name}/upload?file_id=${data.file_id}&file_uuid=${data.file_uuid}`, {
method: 'DELETE',
});
}
//query end
export const AdHocAPI = {
getDatabaseList,
doQuery,
doUp,
getLog,
queryProfile,
logOut,
getHardwareInfo,
getUploadData,
deleteUploadData,
};