8000 Feature/新增令牌状态同步更新 by yoonper · Pull Request #117 · 4x99/code6 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feature/新增令牌状态同步更新 #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/Http/Controllers/ConfigTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Models\ConfigToken;
use App\Services\GitHubService;
use Illuminate\Http\Request;

class ConfigTokenController extends Controller
Expand Down Expand Up @@ -37,7 +38,12 @@ public function store(Request $request)
['token' => $request->input('token')],
['description' => $request->input('description') ?? '']
);
if (!$data->wasRecentlyCreated) {
if ($data->wasRecentlyCreated) {
$service = new GitHubService();
$client['token'] = $data->token;
$client['client'] = $service->createClient($client['token']);
$service->updateClient($client);
} else {
throw new \Exception('操作失败,可能已存在此令牌!');
}
return ['success' => true, 'data' => ConfigToken::find($data->id)];
Expand Down
2 changes: 1 addition & 1 deletion app/Services/GitHubService.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function getClient()
* @param $client
* @return bool
*/
private function updateClient(&$client)
public function updateClient(&$client)
{
$code = $resource = null;
try {
Expand Down
2 changes: 1 addition & 1 deletion public/css/configToken.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}

.progress > div {
background: #FFE082;
background: #C2DDF2;
line-height: 20px;
}

Expand Down
22 changes: 15 additions & 7 deletions resources/views/configToken/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
},
}

var urlGenToken = 'https://github.com/settings/tokens/new';
var urlNewToken = 'https://github.com/settings/tokens/new';

var content = '';
content += '<p class="tip-title">1. 令牌是什么?<span></p>';
content += '<p>用来请求 GitHub API 的 Token(即 GitHub personal access token)</p><br/>';
content += '<p class="tip-title">2. 如何申请令牌?</p>';
content += '<p>GitHub - Settings - Developer settings - Personal access tokens - Generate new token';
content += '(<a target="_blank" href="' + urlGenToken + '">直达</a>)</p>';
content += '(<a target="_blank" href="' + urlNewToken + '">直达</a>)</p>';
content += '<p>提示:填写 Note 信息后直接点击 Generate token 按钮生成,无需设置其他选项。</p><br/>';
content += '<p class="tip-title">3. 为何需要配置多个令牌?</p>';
content += '<p>GitHub 限制了 API 的请求速率';
Expand Down Expand Up @@ -120,13 +120,14 @@
text: 'GitHub接口请求配额',
columns: [
{
text: '接口请求量/上限',
text: '已用配额/上限',
width: 200,
renderer: function (value, cellmeta, record) {
var item = [], data = record.data;
item.limit = data.api_limit;
item.used = Math.max(0, item.limit - data.api_remaining);
item.percent = parseFloat(item.used / item.limit * 100);
item.percent = parseFloat((1 - item.used / item.limit) * 100);
item.percent = item.limit > 0 ? item.percent : 0;
return new Ext.XTemplate(
'<div class="progress">',
' <div style="width:{percent}%">',
Expand Down Expand Up @@ -230,13 +231,13 @@ function winForm(data) {
fieldLabel: '令牌',
allowBlank: false,
value: data.token,
emptyText: '点击右边图标申请..',
emptyText: '点击右侧图标申请..',
triggers: {
search: {
cls: 'icon-page-get',
cls: 'icon-page-key',
tooltip: '前往 GitHub 申请令牌',
handler: function () {
tool.winOpen(urlGenToken);
tool.winOpen(urlNewToken);
}
}
}
Expand All @@ -260,6 +261,12 @@ function winForm(data) {
text: '提交',
formBind: true,
handler: function () {
Ext.MessageBox.show({
msg: '令牌状态同步中..',
width: 300,
wait: {interval: 200},
});

var params = this.up('form').getValues();
var method = data.id ? 'PUT' : 'POST';
var url = data.id ? '/api/configToken/' + data.id : '/api/configToken';
Expand All @@ -272,6 +279,7 @@ function winForm(data) {
} else {
tool.toast(rsp.message, 'warning');
}
Ext.MessageBox.hide();
});
}
}
Expand Down
0