wireway 202012161641 → 202101191029
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/wireway/restful_controller.rb +26 -3
- data/app/views/layouts/wireway/application.html.erb +13 -1
- data/app/views/wireway/restful/ui.html.erb +413 -0
- data/config/routes.rb +4 -1
- data/{app/models/wireway/business_logic/restful.rb → lib/wireway/core/request.rb} +38 -7
- data/{app/models/wireway → lib/wireway/core}/standard.rb +0 -0
- data/lib/wireway/engine.rb +2 -0
- data/{app/models → lib}/wireway/spark.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09bb1a699b7c5117129b68d40c7697dadba11e6cc9cba425d83d28cdc6bfbd04'
|
4
|
+
data.tar.gz: fa07b6ec87843f8ea6d9057d03b95c5d110da340acf0b721dc646a4773eff707
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e9c4061d44c8f66773787c3946d0a4adcac4b48f9e7aac13662d8e11d271698f789631558fed26812ce114a4023b7c697cbe2864430118bfb02689090bf6c0e
|
7
|
+
data.tar.gz: 4fd0a7be8f36f7833b309ab0a7d1df3dedd1fc0122f93a5d8416370ed3d876f30ddd747ea5bf16238123483049b602a8f6e794ee83e77914e08ff0192c5b6258
|
@@ -1,13 +1,36 @@
|
|
1
1
|
module Wireway
|
2
2
|
class RestfulController < ApplicationController
|
3
|
-
|
3
|
+
|
4
|
+
def exposed_api
|
5
|
+
res = Wireway::Core::Request::platforms_exposed_api
|
6
|
+
render json: res[1]
|
7
|
+
end
|
8
|
+
|
9
|
+
def request_api_params
|
10
|
+
return render json: {success: false, result: '平台标识(platform_code)不能为空'} unless params[:platform_code]
|
11
|
+
return render json: {success: false, result: '接口标识(api_code)不能为空'} unless params[:api_code]
|
12
|
+
|
13
|
+
res = Wireway::Core::Request::request_api_params(platform_code: params[:platform_code], api_code: params[:api_code])
|
14
|
+
return render json: {success: false, result: res[1]} unless res[0]
|
15
|
+
|
16
|
+
res[1][:request_params] << {key: 'platform_code', name: '平台标识', explain: '接口所属平台标识', example: params[:platform_code], default: nil, value_type: 'string', necessary: true}
|
17
|
+
render json: res[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def request_api_result
|
4
21
|
# TODO 初步了解为rails5的安全机制 去除存在风险 暂时先这样
|
5
22
|
args = params.permit!.to_hash.reject!{|key| ["action", "controller"].include?(key)}.deep_symbolize_keys
|
6
23
|
|
7
|
-
res = Wireway::Spark.send(args[:
|
8
|
-
|
24
|
+
res = Wireway::Spark.send(args[:platform_code], args)
|
25
|
+
return (render html: res[1]) if res[1].is_a?(String)
|
26
|
+
tmp = {success: res[0]}
|
27
|
+
tmp.merge!(res[1])
|
9
28
|
(tmp.merge!(res[2]) rescue nil) if res[2].present?
|
10
29
|
render json: tmp.merge!(tmp)
|
11
30
|
end
|
31
|
+
|
32
|
+
def ui
|
33
|
+
end
|
34
|
+
|
12
35
|
end
|
13
36
|
end
|
@@ -4,13 +4,25 @@
|
|
4
4
|
<title>Wireway</title>
|
5
5
|
<%= csrf_meta_tags %>
|
6
6
|
<%= csp_meta_tag %>
|
7
|
+
<%=
|
8
|
+
res = Wireway::Spark.dashboard(api_code: :publish_other_request_assets, rely_assets: ["bootstrap_4", "chart_js", "jQuery_3_5_1", "amcharts_4", "google_charts", "highcharts", "space", "ff4c00"])
|
9
|
+
res[1].html_safe if res[0]
|
10
|
+
%>
|
7
11
|
|
8
12
|
<%= stylesheet_link_tag "wireway/application", media: "all" %>
|
9
13
|
<%= javascript_include_tag "wireway/application" %>
|
10
14
|
</head>
|
11
15
|
<body>
|
16
|
+
<div class="container pt-3 main_title" id="space">
|
12
17
|
|
13
|
-
|
18
|
+
<% flash.each do |state, message| %>
|
19
|
+
<div class="alert <%= (state == 'error') ? 'alert-danger' : 'alert-success' %> alert-dismissable fade show">
|
20
|
+
<button type="button" class="close" data-dismiss="alert">×</button>
|
21
|
+
<%= message %>
|
22
|
+
</div>
|
23
|
+
<% end %>
|
14
24
|
|
25
|
+
<%= yield %>
|
26
|
+
</div>
|
15
27
|
</body>
|
16
28
|
</html>
|
@@ -0,0 +1,413 @@
|
|
1
|
+
<div id='exposed_api'>
|
2
|
+
<div id='exposed_api_tag_cloud'></div>
|
3
|
+
<div id='exposed_api_jumbotron'></div>
|
4
|
+
</div>
|
5
|
+
|
6
|
+
<div id='current_api' class='input-group mb-3'>
|
7
|
+
<select id="current_api_select" class="form-control" onchange='ui.current_api.change()'>
|
8
|
+
<option value=''>请选择具体api</option>
|
9
|
+
</select>
|
10
|
+
|
11
|
+
<div class="input-group-append">
|
12
|
+
<button class="btn btn-danger" type="button" onclick="ui.api_forms.reset_params_value()" id='current_api_reset_params_value' disabled=true>重置</button>
|
13
|
+
<button class="btn btn-primary" type="button" onclick="ui.api_forms.submit();" id='current_api_submit_button' disabled=true>提交</button>
|
14
|
+
</div>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div id='api_forms'></div>
|
18
|
+
|
19
|
+
<div id='api_results'></div>
|
20
|
+
|
21
|
+
<div id='readme' class='text-center'>
|
22
|
+
<hr>
|
23
|
+
<p>页面所涉及操作均可通过restful请求(详细信息参考README或F12),该页面仅为接口数据展示/交互.</p>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<script type="text/javascript">
|
27
|
+
ui = new Object()
|
28
|
+
exposed_api_ = []
|
29
|
+
// ====== 开放接口相关开始 ======
|
30
|
+
ui.exposed_api = $('#exposed_api')
|
31
|
+
ui.exposed_api.all = function () {
|
32
|
+
return exposed_api_
|
33
|
+
}
|
34
|
+
ui.exposed_api.add = function (item) {
|
35
|
+
exposed_api_.push(item);
|
36
|
+
}
|
37
|
+
|
38
|
+
ui.exposed_api.jumbotron = $('#exposed_api_jumbotron')
|
39
|
+
ui.exposed_api.jumbotron.add = function (platform_code, platform) {
|
40
|
+
jumbotron = document.createElement('div')
|
41
|
+
jumbotron.setAttribute('class', 'jumbotron')
|
42
|
+
|
43
|
+
h1 = document.createElement('h3')
|
44
|
+
h1.innerHTML = platform.name
|
45
|
+
jumbotron.appendChild(h1)
|
46
|
+
|
47
|
+
p = document.createElement('p')
|
48
|
+
p.innerHTML = platform.explain
|
49
|
+
jumbotron.appendChild(p)
|
50
|
+
|
51
|
+
apiButtons = document.createElement('div')
|
52
|
+
apiButtons.setAttribute('id', 'api_buttons_'+platform_code)
|
53
|
+
buttonColors = ['btn-primary','btn-success','btn-info','btn-warning','btn-danger','btn-secondary','btn-dark','btn-light']
|
54
|
+
|
55
|
+
jQuery.each(platform.exposed_api, function(key, info) {
|
56
|
+
button = document.createElement('button')
|
57
|
+
button.setAttribute('type', 'button')
|
58
|
+
buttonColor = buttonColors[Math.floor((Math.random()*buttonColors.length))]
|
59
|
+
button.setAttribute('class', 'btn ml-2 mb-2 '+buttonColor)
|
60
|
+
button.setAttribute('onclick', "ui.current_api.change('"+platform_code+"', '"+key+"')")
|
61
|
+
button.innerHTML = info.name
|
62
|
+
apiButtons.appendChild(button)
|
63
|
+
})
|
64
|
+
|
65
|
+
jumbotron.appendChild(apiButtons)
|
66
|
+
this[0].appendChild(jumbotron)
|
67
|
+
}
|
68
|
+
|
69
|
+
ui.exposed_api.tag_cloud = $('#exposed_api_tag_cloud')
|
70
|
+
ui.exposed_api.tag_cloud.load = function () {
|
71
|
+
if (!ui.exposed_api.all()[0]) return;
|
72
|
+
|
73
|
+
tag_datas = {}
|
74
|
+
jQuery.each(ui.exposed_api.all(), function(index, item) {
|
75
|
+
zh_ratio = (Math.round(Math.random() * (20 - 10)) + 8)
|
76
|
+
tag_datas[item.name] = {key_word: '['+item.platform_code+']'+item.api_code, weight: zh_ratio}
|
77
|
+
// en_ratio = (Math.round(Math.random() * (10 - 5)) + 1)
|
78
|
+
// tag_datas[item.api_code] = {key_word: '['+item.platform_code+']'+item.api_code, weight: en_ratio}
|
79
|
+
})
|
80
|
+
|
81
|
+
params = {
|
82
|
+
tag_datas: tag_datas,
|
83
|
+
tag_url: "javascript:ui.current_api.change('{key_word}');",
|
84
|
+
url_target:"_self",
|
85
|
+
chart_style: "width: 100%; height: 35%;",
|
86
|
+
platform_code: 'dashboard',
|
87
|
+
api_code: 'chart_other_tag_cloud'
|
88
|
+
}
|
89
|
+
|
90
|
+
url = "<%= request_api_result_restful_index_path() %>"
|
91
|
+
space.network.ajax({type: 'Post', "url": url, "params" : params}, function (result) {
|
92
|
+
if (!result[0]) return;
|
93
|
+
ui.exposed_api.tag_cloud.html($('<div>').html(result[1]).text())
|
94
|
+
})
|
95
|
+
}
|
96
|
+
|
97
|
+
ui.exposed_api.package = function (platform_code, platform) {
|
98
|
+
jQuery.each(platform.exposed_api, function(key, info) {
|
99
|
+
ui.exposed_api.add({name: info.name, platform_code: platform_code, api_code: key, explain: info.explain})
|
100
|
+
})
|
101
|
+
|
102
|
+
ui.current_api.select.add(platform_code, platform)
|
103
|
+
ui.exposed_api.jumbotron.add(platform_code, platform)
|
104
|
+
}
|
105
|
+
|
106
|
+
ui.exposed_api.load = function () {
|
107
|
+
url = "<%= exposed_api_restful_index_path() %>"
|
108
|
+
space.network.ajax({"url": url}, function (result) {
|
109
|
+
if (!result[0]) return;
|
110
|
+
jQuery.each(result[1], function(platform_code, platform) {
|
111
|
+
ui.exposed_api.package(platform_code, platform)
|
112
|
+
})
|
113
|
+
})
|
114
|
+
}
|
115
|
+
// ====== 开放接口相关结束 ======
|
116
|
+
|
117
|
+
// ====== 当前选择api相关开始 ======
|
118
|
+
ui.current_api = $('#current_api')
|
119
|
+
|
120
|
+
ui.currentApi = function () {
|
121
|
+
option = $("#current_api_select option:selected")
|
122
|
+
if (!option.attr('platform_code')) return [false, '当前尚未选中api'];
|
123
|
+
return [true, {platform_code: option.attr('platform_code'), api_code: option.attr('api_code')}]
|
124
|
+
}
|
125
|
+
|
126
|
+
ui.current_api.change = function (platform_code, api_code) {
|
127
|
+
if (platform_code && api_code) {
|
128
|
+
$('#current_api_select').val('['+platform_code+']'+api_code)
|
129
|
+
}else if ((platform_code || '').indexOf("[") == 0) {
|
130
|
+
// tmp = platform_code.split('[')[1].split(']')
|
131
|
+
// return this.change(tmp[0], tmp[1])
|
132
|
+
$('#current_api_select').val(platform_code)
|
133
|
+
}
|
134
|
+
|
135
|
+
res = ui.currentApi()
|
136
|
+
if (!res[0]) {
|
137
|
+
$('#current_api_submit_button').attr("disabled","true");
|
138
|
+
$('#current_api_reset_params_value').attr("disabled","true");
|
139
|
+
return
|
140
|
+
}
|
141
|
+
$("#current_api_submit_button").removeAttr("disabled");
|
142
|
+
$("#current_api_reset_params_value").removeAttr("disabled");
|
143
|
+
ui.api_results.hide()
|
144
|
+
ui.api_forms.load({auto_load_result: true})
|
145
|
+
}
|
146
|
+
|
147
|
+
ui.current_api.select = $('#current_api_select')
|
148
|
+
ui.current_api.select.add = function (platform_code, platform) {
|
149
|
+
jQuery.each(platform.exposed_api, function(key, info) {
|
150
|
+
option = document.createElement('option')
|
151
|
+
option.setAttribute('value', '['+platform_code+']'+key)
|
152
|
+
option.setAttribute('platform_code', platform_code)
|
153
|
+
option.setAttribute('api_code', key)
|
154
|
+
option.innerHTML = '['+platform_code+'] '+info.name+'---'+info.explain
|
155
|
+
ui.current_api.select[0].appendChild(option)
|
156
|
+
})
|
157
|
+
}
|
158
|
+
// ====== 当前选择api相关结束 ======
|
159
|
+
|
160
|
+
// ====== api调用参数相关开始 ======
|
161
|
+
ui.api_forms = $('#api_forms')
|
162
|
+
|
163
|
+
ui.api_forms.current = function (params) {
|
164
|
+
|
165
|
+
res = ui.currentApi()
|
166
|
+
if (!res[0]) return [false, '当前尚未选择具体api接口'];
|
167
|
+
|
168
|
+
defaultValues = {auto_load: false}
|
169
|
+
params = $.extend({}, defaultValues, params)
|
170
|
+
|
171
|
+
target_id = 'api_forms_'+res[1].platform_code+'_'+res[1].api_code
|
172
|
+
target_object = $('#'+target_id)
|
173
|
+
if (params.auto_load && (!target_object[0])) this.load();
|
174
|
+
return [!!target_object[0], {id: target_id, object: target_object}]
|
175
|
+
}
|
176
|
+
|
177
|
+
ui.api_forms.hide = function () {
|
178
|
+
$("form[class='api_forms_item']").each(function(){ $(this).addClass('d-none')});
|
179
|
+
}
|
180
|
+
|
181
|
+
ui.api_forms.package = function (target_id, target_info) {
|
182
|
+
form = document.createElement('form')
|
183
|
+
form.setAttribute('class', 'api_forms_item')
|
184
|
+
form.setAttribute('id', target_id)
|
185
|
+
form.setAttribute('accept-charset', 'UTF-8')
|
186
|
+
|
187
|
+
table = document.createElement('table')
|
188
|
+
table.setAttribute('class', 'table table-bordered table-striped table-hover')
|
189
|
+
|
190
|
+
tr = document.createElement('tr')
|
191
|
+
tds = [
|
192
|
+
{class: 'text-center', name: '名称'},
|
193
|
+
{class: 'text-center', name: '参数键'},
|
194
|
+
{class: 'text-center w-25', name: '示例值'},
|
195
|
+
{class: 'text-center w-25', name: '说明'},
|
196
|
+
{class: 'text-center', name: '默认值'},
|
197
|
+
{class: 'text-center', name: '参数类型'},
|
198
|
+
{class: 'text-center', name: '是否必填'},
|
199
|
+
]
|
200
|
+
jQuery.each(tds, function(index, detail) {
|
201
|
+
td = document.createElement('td')
|
202
|
+
td.setAttribute('class', detail.class)
|
203
|
+
td.innerHTML = detail.name
|
204
|
+
tr.appendChild(td)
|
205
|
+
})
|
206
|
+
table.appendChild(tr)
|
207
|
+
|
208
|
+
jQuery.each(target_info.request_params, function(index, detail) {
|
209
|
+
tr = document.createElement('tr')
|
210
|
+
|
211
|
+
jQuery.each(['name', 'key'], function(index, key){
|
212
|
+
td = document.createElement('td')
|
213
|
+
td.setAttribute('class', 'text-center')
|
214
|
+
td.innerHTML = (detail[key] || '无')
|
215
|
+
tr.appendChild(td)
|
216
|
+
})
|
217
|
+
|
218
|
+
|
219
|
+
td = document.createElement('td')
|
220
|
+
input = document.createElement('input')
|
221
|
+
input.setAttribute('class', 'form-control')
|
222
|
+
input.setAttribute('name', detail.key)
|
223
|
+
if ((detail.example || '').constructor == Array){
|
224
|
+
input.setAttribute('value', JSON.stringify(detail.example))
|
225
|
+
}else{
|
226
|
+
input.setAttribute('value', detail.example || '')
|
227
|
+
}
|
228
|
+
td.appendChild(input)
|
229
|
+
tr.appendChild(td)
|
230
|
+
|
231
|
+
jQuery.each(['explain', 'default', 'value_type'], function(index, key){
|
232
|
+
td = document.createElement('td')
|
233
|
+
if (index == 2) td.setAttribute('class', 'text-center');
|
234
|
+
|
235
|
+
if ((detail[key] || '').constructor == Array){
|
236
|
+
td.innerHTML = JSON.stringify(detail[key])
|
237
|
+
}else{
|
238
|
+
td.innerHTML = (detail[key] || '无')
|
239
|
+
}
|
240
|
+
|
241
|
+
tr.appendChild(td)
|
242
|
+
})
|
243
|
+
|
244
|
+
td = document.createElement('td')
|
245
|
+
td.setAttribute('class', 'text-center')
|
246
|
+
td.innerHTML = detail.necessary ? '是' : '否'
|
247
|
+
tr.appendChild(td)
|
248
|
+
|
249
|
+
table.appendChild(tr)
|
250
|
+
})
|
251
|
+
|
252
|
+
form.appendChild(table)
|
253
|
+
this[0].appendChild(form)
|
254
|
+
}
|
255
|
+
|
256
|
+
ui.api_forms.load = async function (params) {
|
257
|
+
res = ui.currentApi()
|
258
|
+
if (!res[0]) return;
|
259
|
+
this.hide()
|
260
|
+
|
261
|
+
defaultValues = {auto_load_result: false}
|
262
|
+
params = $.extend({}, defaultValues, params)
|
263
|
+
|
264
|
+
target_id = 'api_forms_'+res[1].platform_code+'_'+res[1].api_code
|
265
|
+
target_object = $('#'+target_id)
|
266
|
+
if (target_object[0]){
|
267
|
+
target_object.removeClass('d-none')
|
268
|
+
res = ui.api_results.current({reload: false})
|
269
|
+
if (res[0]) if (res[1].object[0]) res[1].object.removeClass('d-none')
|
270
|
+
return
|
271
|
+
}
|
272
|
+
|
273
|
+
url = "<%= request_api_params_restful_index_path() %>"
|
274
|
+
space.network.ajax({"url": url, params: {platform_code: res[1].platform_code, api_code: res[1].api_code}}, function (result) {
|
275
|
+
if (!result[0]) return;
|
276
|
+
ui.api_forms.package(target_id, result[1])
|
277
|
+
})
|
278
|
+
|
279
|
+
if (params.auto_load_result) {
|
280
|
+
if (!ui.api_forms.current()[0]) {
|
281
|
+
for (let i = 0; i < 1000; i++) {
|
282
|
+
await space.other.sleep(1)
|
283
|
+
if (ui.api_forms.current()[0]) i=1000;
|
284
|
+
}
|
285
|
+
}
|
286
|
+
this.submit()
|
287
|
+
}
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
ui.api_forms.reset_params_value = function () {
|
292
|
+
res = this.current()
|
293
|
+
if (!res[0]) return res;
|
294
|
+
res[1].object[0].reset()
|
295
|
+
return [true, '']
|
296
|
+
}
|
297
|
+
|
298
|
+
ui.api_forms.submit = function () {
|
299
|
+
res = this.current()
|
300
|
+
if (!res[0]) return res;
|
301
|
+
|
302
|
+
url = "<%= request_api_result_restful_index_path() %>"
|
303
|
+
params = res[1].object.closest('form').serialize()
|
304
|
+
space.network.ajax({type: 'Post', "url": url, "params" : params}, function (result) {
|
305
|
+
if (!result[0]) return;
|
306
|
+
if (result[1].constructor === Object) {
|
307
|
+
ui.api_results.handle_object(result[1])
|
308
|
+
}else {
|
309
|
+
ui.api_results.handle_html(result[1])
|
310
|
+
}
|
311
|
+
|
312
|
+
})
|
313
|
+
}
|
314
|
+
|
315
|
+
// ====== api调用参数相关结束 ======
|
316
|
+
|
317
|
+
// ====== api返回结果相关开始 ======
|
318
|
+
ui.api_results = $('#api_results')
|
319
|
+
|
320
|
+
ui.api_results.current = function (params) {
|
321
|
+
defaultValues = {present: false, reload: true}
|
322
|
+
params = $.extend({}, defaultValues, params)
|
323
|
+
res = ui.currentApi()
|
324
|
+
if (!res[0]) return [false, '当前尚未选择具体api接口'];
|
325
|
+
target_id = 'api_results_'+res[1].platform_code+'_'+res[1].api_code
|
326
|
+
if (params.present) if (!$('#'+target_id)[0]) ui.api_forms.load();
|
327
|
+
if (params.reload) if ($('#'+target_id)[0]) $('#'+target_id).remove()
|
328
|
+
return [true, {id: target_id, object: $('#'+target_id)}]
|
329
|
+
}
|
330
|
+
|
331
|
+
ui.api_results.hide = function () {
|
332
|
+
$("div[class='api_results_item']").each(function(){ $(this).addClass('d-none')});
|
333
|
+
}
|
334
|
+
|
335
|
+
ui.api_results.handle_object = function (object) {
|
336
|
+
res = this.current()
|
337
|
+
if (!res[0]) return res;
|
338
|
+
this.hide()
|
339
|
+
|
340
|
+
div = document.createElement('div')
|
341
|
+
div.setAttribute('class', 'api_results_item')
|
342
|
+
div.setAttribute('id', res[1].id)
|
343
|
+
|
344
|
+
table = document.createElement('table')
|
345
|
+
table.setAttribute('class', 'table table-bordered table-striped table-hover')
|
346
|
+
|
347
|
+
tr = document.createElement('tr')
|
348
|
+
tds = [
|
349
|
+
{class: 'text-center', style: 'width: 15%;', name: '返回键'},
|
350
|
+
{class: 'text-center', style: '', name: '返回值'}
|
351
|
+
]
|
352
|
+
jQuery.each(tds, function(index, detail) {
|
353
|
+
td = document.createElement('td')
|
354
|
+
td.setAttribute('class', detail.class)
|
355
|
+
td.setAttribute('style', detail.style)
|
356
|
+
td.innerHTML = detail.name
|
357
|
+
tr.appendChild(td)
|
358
|
+
})
|
359
|
+
table.appendChild(tr)
|
360
|
+
|
361
|
+
jQuery.each(object, function(key, value) {
|
362
|
+
tr = document.createElement('tr')
|
363
|
+
|
364
|
+
td = document.createElement('td')
|
365
|
+
td.setAttribute('class', 'text-right')
|
366
|
+
td.innerHTML = key
|
367
|
+
tr.appendChild(td)
|
368
|
+
|
369
|
+
td = document.createElement('td')
|
370
|
+
td.setAttribute('class', 'text-left')
|
371
|
+
td.setAttribute('style', 'max-width: 500px')
|
372
|
+
td.innerHTML = '<pre><code>'+JSON.stringify(value, undefined, 2)+'</code></pre>'
|
373
|
+
tr.appendChild(td)
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
table.appendChild(tr)
|
378
|
+
})
|
379
|
+
|
380
|
+
div.appendChild(table)
|
381
|
+
this[0].appendChild(div)
|
382
|
+
}
|
383
|
+
|
384
|
+
ui.api_results.handle_html = function (html) {
|
385
|
+
res = this.current()
|
386
|
+
if (!res[0]) return res;
|
387
|
+
this.hide()
|
388
|
+
|
389
|
+
div = document.createElement('div')
|
390
|
+
div.setAttribute('class', 'api_results_item')
|
391
|
+
div.setAttribute('id', res[1].id)
|
392
|
+
// div.innerHTML = html
|
393
|
+
this[0].appendChild(div)
|
394
|
+
|
395
|
+
$('#'+res[1].id).html($('#'+res[1].id).html(html).text())
|
396
|
+
}
|
397
|
+
// ====== api返回结果相关结束 ======
|
398
|
+
|
399
|
+
async function main () {
|
400
|
+
ui.exposed_api.load()
|
401
|
+
|
402
|
+
if (!ui.exposed_api.all()[0]) {
|
403
|
+
for (let i = 0; i < 1000; i++) {
|
404
|
+
await space.other.sleep(10)
|
405
|
+
if (ui.exposed_api.all()[0]) i=1000;
|
406
|
+
}
|
407
|
+
}
|
408
|
+
ui.exposed_api.tag_cloud.load()
|
409
|
+
}
|
410
|
+
|
411
|
+
main()
|
412
|
+
|
413
|
+
</script>
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Wireway
|
2
|
-
module
|
3
|
-
module
|
2
|
+
module Core
|
3
|
+
module Request
|
4
4
|
extend self
|
5
5
|
|
6
6
|
$wireway_node_addresses = 404
|
@@ -23,6 +23,36 @@ module Wireway
|
|
23
23
|
$wireway_node_addresses = [true, nodes]
|
24
24
|
end
|
25
25
|
|
26
|
+
def platforms_exposed_api
|
27
|
+
res = node_addresses
|
28
|
+
return res unless res[0]
|
29
|
+
exposed_api = {}
|
30
|
+
|
31
|
+
platforms = {:satcom => ["123.57.155.17:3113"], :dashboard => ['123.57.155.17:3111'], :black_box => ['123.57.155.17:3116']}
|
32
|
+
platforms.each do |platform_code, addresses|
|
33
|
+
route = "/#{platform_code}/restful/exposed_api"
|
34
|
+
res = get(addresses: addresses, route: route) do |result|
|
35
|
+
hash = JSON.parse(result[1][:body]).deep_symbolize_keys
|
36
|
+
exposed_api.merge!(hash) if hash.is_a?(Hash)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
[true, exposed_api]
|
41
|
+
end
|
42
|
+
|
43
|
+
def request_api_params(platform_code:, api_code:)
|
44
|
+
res = node_addresses
|
45
|
+
return res unless res[0]
|
46
|
+
addresses = res[1][platform_code.to_sym]
|
47
|
+
route = "/#{platform_code}/restful/request_api_params"
|
48
|
+
|
49
|
+
get(addresses: addresses, route: route, params: {api_code: api_code}) do |result|
|
50
|
+
hash = JSON.parse(result[1][:body]).deep_symbolize_keys
|
51
|
+
[true, hash]
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
26
56
|
def dashboard(**args)
|
27
57
|
params = {
|
28
58
|
response_type: 'json',
|
@@ -31,11 +61,11 @@ module Wireway
|
|
31
61
|
res = node_addresses
|
32
62
|
return res unless res[0]
|
33
63
|
post(addresses: res[1][:dashboard], route: route, params: params) do |result|
|
34
|
-
return result if (params[:response_type] != 'json')
|
64
|
+
return [true, result[1][:body]] if (params[:response_type] != 'json')
|
35
65
|
body = JSON.parse(result[1][:body]).deep_symbolize_keys
|
36
66
|
return [false, body[:result]] unless body[:success]
|
37
|
-
[true, body[:
|
38
|
-
end
|
67
|
+
[true, body[:result]]
|
68
|
+
end
|
39
69
|
end
|
40
70
|
|
41
71
|
def satcom(**args)
|
@@ -46,7 +76,8 @@ module Wireway
|
|
46
76
|
post(addresses: res[1][:satcom], route: route, params: params) do |result|
|
47
77
|
body = JSON.parse(result[1][:body]).deep_symbolize_keys
|
48
78
|
return [false, body[:result], body[:errors]].compact unless body[:success]
|
49
|
-
[true, body[:result]]
|
79
|
+
# [true, body[:result]]
|
80
|
+
[true, body]
|
50
81
|
end
|
51
82
|
end
|
52
83
|
|
@@ -54,7 +85,7 @@ module Wireway
|
|
54
85
|
params = {
|
55
86
|
local: false
|
56
87
|
}.merge!(args)
|
57
|
-
route = '/wireway/restful/
|
88
|
+
route = '/wireway/restful/request_api_result'
|
58
89
|
res = node_addresses
|
59
90
|
return res unless res[0]
|
60
91
|
post(addresses: res[1][:wireway], route: route, params: params) do |result|
|
File without changes
|
data/lib/wireway/engine.rb
CHANGED
@@ -2,7 +2,7 @@ module Wireway
|
|
2
2
|
module Spark
|
3
3
|
def self.method_missing(method_name, local: true, **args)
|
4
4
|
begin
|
5
|
-
target = Wireway::
|
5
|
+
target = Wireway::Core::Request
|
6
6
|
unless [true, 'true', 1, '1', 'yes'].include?(local)
|
7
7
|
return [false, "未找到名称为:#{method_name}的方法定义."] unless target.respond_to?(method_name)
|
8
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wireway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '202101191029'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ff4c00
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -91,14 +91,15 @@ files:
|
|
91
91
|
- app/jobs/wireway/application_job.rb
|
92
92
|
- app/mailers/wireway/application_mailer.rb
|
93
93
|
- app/models/wireway/application_record.rb
|
94
|
-
- app/models/wireway/business_logic/restful.rb
|
95
|
-
- app/models/wireway/spark.rb
|
96
|
-
- app/models/wireway/standard.rb
|
97
94
|
- app/views/layouts/wireway/application.html.erb
|
95
|
+
- app/views/wireway/restful/ui.html.erb
|
98
96
|
- config/routes.rb
|
99
97
|
- lib/tasks/wireway_tasks.rake
|
100
98
|
- lib/wireway.rb
|
99
|
+
- lib/wireway/core/request.rb
|
100
|
+
- lib/wireway/core/standard.rb
|
101
101
|
- lib/wireway/engine.rb
|
102
|
+
- lib/wireway/spark.rb
|
102
103
|
- lib/wireway/version.rb
|
103
104
|
homepage: https://gitlab.com/ff4c00/space/-/tree/master/%E7%9F%A5%E8%AF%86%E4%BD%93%E7%B3%BB/%E5%BA%94%E7%94%A8%E7%A7%91%E5%AD%A6/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6/%E8%BD%AF%E4%BB%B6%E5%B7%A5%E7%A8%8B/Rails/C919/wireway
|
104
105
|
licenses:
|