Skip to content

Commit 10e9cb0

Browse files
committed
优化:代理配置优化
- 修改 config_common value 字段长度 - 修改代理测试超时时间
1 parent 5a16ed3 commit 10e9cb0

File tree

4 files changed

+26
-33
lines changed

4 files changed

+26
-33
lines changed

app/Http/Controllers/ConfigProxyController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Http\Controllers;
44

55
use App\Models\ConfigCommon;
6-
use App\Services\GitHubService;
76
use Illuminate\Http\Request;
87
use Github\Client;
98
use Github\HttpClient\Builder;
@@ -51,7 +50,7 @@ public function test(Request $request)
5150
{
5251
try {
5352
$builder = new Builder(GuzzleClient::createWithConfig([
54-
'timeout' => GitHubService::HTTP_TIMEOUT,
53+
'timeout' => 5,
5554
'proxy' => $request->input('value'),
5655
]));
5756
$client = new Client($builder, 'v3.text-match');

app/Http/Controllers/ConfigWhitelistFileController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ class ConfigWhitelistFileController extends Controller
1515
public function index()
1616
{
1717
try {
18-
return [
19-
'success' => true,
20-
'data' => implode("\n", json_decode(ConfigCommon::getValue(ConfigCommon::KEY_WHITELIST_FILE))),
21-
];
18+
$data = ConfigCommon::getValue(ConfigCommon::KEY_WHITELIST_FILE);
19+
$data = implode("\n", json_decode($data));
20+
return ['success' => true, 'data' => $data];
2221
} catch (\Exception $e) {
2322
return ['success' => false, 'message' => $e->getMessage()];
2423
}

database/migrations/2021_06_01_111745_create_config_common_table.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function up()
1818
Schema::create('config_common', function (Blueprint $table) {
1919
$table->id();
2020
$table->string('key', 255);
21-
$table->string('value', 255);
21+
$table->text('value');
2222
$table->unique(['key']);
2323
});
2424
$this->migrate();
@@ -30,8 +30,9 @@ public function up()
3030
private function migrate()
3131
{
3232
if (Schema::hasTable('config_whitelist_file')) {
33-
$whitelistFile = DB::table('config_whitelist_file')->pluck('value');
34-
ConfigCommon::create(['key' => ConfigCommon::KEY_WHITELIST_FILE, 'value' => json_encode($whitelistFile)]);
33+
$values = DB::table('config_whitelist_file')->pluck('value');
34+
$values = json_encode($values);
35+
ConfigCommon::create(['key' => ConfigCommon::KEY_WHITELIST_FILE, 'value' => $values]);
3536
Schema::dropIfExists('config_whitelist_file');
3637
}
3738
}

resources/views/index/index.blade.php

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,16 @@
9898
href: '/configNotify',
9999
},
100100
{
101-
text: '白名单配置',
101+
text: '代理配置',
102102
align: 'left',
103-
iconCls: 'icon-page-db',
104-
href: '/configWhitelist',
103+
iconCls: 'icon-page-lightning',
104+
handler: winProxy,
105105
},
106106
{
107-
text: '代理配置',
107+
text: '白名单配置',
108108
align: 'left',
109-
iconCls: 'icon-page-wrench',
110-
handler: function () {
111-
winForm([]);
112-
}
109+
iconCls: 'icon-page-db',
110+
href: '/configWhitelist',
113111
}
114112
]
115113
}
@@ -276,16 +274,17 @@
276274
Ext.get('loading').setStyle('display', 'none');
277275
};
278276
279-
function winForm() {
280-
tool.ajax('GET', '/api/configProxy', {}, function (rsp) {
277+
// 代理配置
278+
function winProxy() {
279+
tool.ajax('GET', '/api/configProxy', null, function (rsp) {
281280
if (!rsp.success) {
282-
tool.toast('读取配置错误');
281+
tool.toast('读取代理配置失败');
283282
return false;
284283
}
285284
286-
var winProxy = Ext.create('Ext.window.Window', {
285+
var win = Ext.create('Ext.window.Window', {
287286
title: '代理配置',
288-
iconCls: 'icon-page-wrench',
287+
iconCls: 'icon-page-lightning',
289288
width: 300,
290289
layout: 'fit',
291290
items: [
@@ -298,40 +297,35 @@ function winForm() {
298297
xtype: 'textfield',
299298
name: 'value',
300299
value: rsp.data,
300+
emptyText: '示例:127.0.0.1:1080',
301301
}
302302
],
303303
buttons: [
304304
{
305-
text: '代理测试',
305+
text: '测试',
306306
handler: function () {
307307
var params = this.up('form').getValues();
308308
if (!params['value']) {
309-
tool.toast('代理不能为空', 'error');
309+
tool.toast('请先配置代理', 'error');
310310
return;
311311
}
312312
tool.ajax('POST', '/api/configProxy/test', params, function (rsp) {
313313
if (rsp.success) {
314-
tool.toast('测试成功', 'success');
314+
tool.toast('代理测试可用', 'success');
315315
} else {
316-
tool.toast(rsp.message, 'error');
316+
tool.toast('代理不可用:' + rsp.message, 'error');
317317
}
318318
});
319319
}
320320
},
321-
{
322-
text: '重置',
323-
handler: function () {
324-
this.up('form').getForm().reset();
325-
}
326-
},
327321
{
328322
text: '保存',
329323
formBind: true,
330324
handler: function () {
331325
var params = this.up('form').getValues();
332326
tool.ajax('POST', '/api/configProxy', params, function (rsp) {
333327
if (rsp.success) {
334-
winProxy.close();
328+
win.close();
335329
tool.toast('保存成功!', 'success');
336330
} else {
337331
tool.toast(rsp.message, 'error');

0 commit comments

Comments
 (0)