Skip to content

Commit

Permalink
优化:代理配置优化
Browse files Browse the repository at this point in the history
- 修改 config_common value 字段长度
- 修改代理测试超时时间
  • Loading branch information
yoonper committed Jun 3, 2021
1 parent 5a16ed3 commit 10e9cb0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
3 changes: 1 addition & 2 deletions app/Http/Controllers/ConfigProxyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers;

use App\Models\ConfigCommon;
use App\Services\GitHubService;
use Illuminate\Http\Request;
use Github\Client;
use Github\HttpClient\Builder;
Expand Down Expand Up @@ -51,7 +50,7 @@ public function test(Request $request)
{
try {
$builder = new Builder(GuzzleClient::createWithConfig([
'timeout' => GitHubService::HTTP_TIMEOUT,
'timeout' => 5,
'proxy' => $request->input('value'),
]));
$client = new Client($builder, 'v3.text-match');
Expand Down
7 changes: 3 additions & 4 deletions app/Http/Controllers/ConfigWhitelistFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ class ConfigWhitelistFileController extends Controller
public function index()
{
try {
return [
'success' => true,
'data' => implode("\n", json_decode(ConfigCommon::getValue(ConfigCommon::KEY_WHITELIST_FILE))),
];
$data = ConfigCommon::getValue(ConfigCommon::KEY_WHITELIST_FILE);
$data = implode("\n", json_decode($data));
return ['success' => true, 'data' => $data];
} catch (\Exception $e) {
return ['success' => false, 'message' => $e->getMessage()];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function up()
Schema::create('config_common', function (Blueprint $table) {
$table->id();
$table->string('key', 255);
$table->string('value', 255);
$table->text('value');
$table->unique(['key']);
});
$this->migrate();
Expand All @@ -30,8 +30,9 @@ public function up()
private function migrate()
{
if (Schema::hasTable('config_whitelist_file')) {
$whitelistFile = DB::table('config_whitelist_file')->pluck('value');
ConfigCommon::create(['key' => ConfigCommon::KEY_WHITELIST_FILE, 'value' => json_encode($whitelistFile)]);
$values = DB::table('config_whitelist_file')->pluck('value');
$values = json_encode($values);
ConfigCommon::create(['key' => ConfigCommon::KEY_WHITELIST_FILE, 'value' => $values]);
Schema::dropIfExists('config_whitelist_file');
}
}
Expand Down
42 changes: 18 additions & 24 deletions resources/views/index/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,16 @@
href: '/configNotify',
},
{
text: '白名单配置',
text: '代理配置',
align: 'left',
iconCls: 'icon-page-db',
href: '/configWhitelist',
iconCls: 'icon-page-lightning',
handler: winProxy,
},
{
text: '代理配置',
text: '白名单配置',
align: 'left',
iconCls: 'icon-page-wrench',
handler: function () {
winForm([]);
}
iconCls: 'icon-page-db',
href: '/configWhitelist',
}
]
}
Expand Down Expand Up @@ -276,16 +274,17 @@
Ext.get('loading').setStyle('display', 'none');
};
function winForm() {
tool.ajax('GET', '/api/configProxy', {}, function (rsp) {
// 代理配置
function winProxy() {
tool.ajax('GET', '/api/configProxy', null, function (rsp) {
if (!rsp.success) {
tool.toast('读取配置错误');
tool.toast('读取代理配置失败');
return false;
}
var winProxy = Ext.create('Ext.window.Window', {
var win = Ext.create('Ext.window.Window', {
title: '代理配置',
iconCls: 'icon-page-wrench',
iconCls: 'icon-page-lightning',
width: 300,
layout: 'fit',
items: [
Expand All @@ -298,40 +297,35 @@ function winForm() {
xtype: 'textfield',
name: 'value',
value: rsp.data,
emptyText: '示例:127.0.0.1:1080',
}
],
buttons: [
{
text: '代理测试',
text: '测试',
handler: function () {
var params = this.up('form').getValues();
if (!params['value']) {
tool.toast('代理不能为空', 'error');
tool.toast('请先配置代理', 'error');
return;
}
tool.ajax('POST', '/api/configProxy/test', params, function (rsp) {
if (rsp.success) {
tool.toast('测试成功', 'success');
tool.toast('代理测试可用', 'success');
} else {
tool.toast(rsp.message, 'error');
tool.toast('代理不可用:' + rsp.message, 'error');
}
});
}
},
{
text: '重置',
handler: function () {
this.up('form').getForm().reset();
}
},
{
text: '保存',
formBind: true,
handler: function () {
var params = this.up('form').getValues();
tool.ajax('POST', '/api/configProxy', params, function (rsp) {
if (rsp.success) {
winProxy.close();
win.close();
tool.toast('保存成功!', 'success');
} else {
tool.toast(rsp.message, 'error');
Expand Down

0 comments on commit 10e9cb0

Please sign in to comment.