This commit is contained in:
史悦
2025-08-13 19:03:20 +08:00
commit d62a2e9ed9
73 changed files with 7296 additions and 0 deletions

236
static/public/code.html Normal file
View File

@@ -0,0 +1,236 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录 Github Copilot</title>
<style>
:root {
--primary-color: #0066CC;
--hover-color: #0256A8;
--background-light: #ffffff;
--text-color: #1d1d1f;
--input-background: #fbfbfd;
--input-border: #d2d2d7;
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
body, html {
height: 100%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
background-color: var(--background-light);
color: var(--text-color);
}
.login-container {
background-color: var(--background-light);
padding: 3em 4em;
border-radius: 20px;
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
text-align: center;
width: 90%;
max-width: 440px;
transition: var(--transition);
}
h1 {
font-size: 24px;
font-weight: 500;
margin-bottom: 1.5em;
color: var(--text-color);
}
form {
display: flex;
flex-direction: column;
align-items: center;
}
.input-wrapper {
width: 100%;
display: flex;
justify-content: center;
margin-bottom: 16px;
}
input {
width: 100%;
max-width: 300px;
padding: 12px 16px;
margin: 6px 0;
border: 1px solid var(--input-border);
border-radius: 12px;
background-color: var(--input-background);
font-size: 15px;
transition: var(--transition);
outline: none;
}
input:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 4px rgba(0, 102, 204, 0.1);
}
button {
width: 100%;
max-width: 300px;
padding: 12px;
margin-top: 24px;
border: none;
border-radius: 12px;
background-color: var(--primary-color);
color: white;
font-size: 15px;
font-weight: 500;
cursor: pointer;
transition: var(--transition);
}
button:hover {
background-color: var(--hover-color);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
.footer {
margin-top: 32px;
font-size: 13px;
color: #86868b;
}
.footer a {
color: var(--primary-color);
text-decoration: none;
transition: var(--transition);
}
.footer a:hover {
text-decoration: underline;
}
/* Dark mode */
@media (prefers-color-scheme: dark) {
:root {
--background-light: #1d1d1f;
--text-color: #f5f5f7;
--input-background: #2c2c2e;
--input-border: #3a3a3c;
}
.login-container {
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}
}
#password {
display: none;
}
</style>
</head>
<body>
<div class="login-container">
<h1>登录 Github Copilot</h1>
<form onsubmit="submitForm()">
<div class="input-wrapper">
<input type="text" id="password"
placeholder="请输入访问密码">
</div>
<div class="input-wrapper">
<input type="text" id="authorization"
placeholder="请输入授权码" autofocus>
</div>
<div class="input-wrapper">
<input type="text" id="displayUserName"
placeholder="GitHub 用户名(可选)">
</div>
<button type="submit">登录</button>
</form>
<div class="footer">
© 2024 Open Source Contributors
</div>
</div>
<script>
async function getLoginConfig() {
const result = await fetch('/login/config');
const resultJson = await result.json();
if (resultJson.is_login_password) {
document.getElementById('password').style.display = 'block';
}
}
getLoginConfig();
function getQueryParam(param) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
}
function setCodeInputValue(){
const code = getQueryParam('user_code');
if (code !== null) {
document.getElementById('authorization').value = code;
}
}
setCodeInputValue();
async function submitForm() {
event.preventDefault();
const authorization = document.getElementById('authorization').value;
const password = document.getElementById('password').value;
const displayUserName = document.getElementById('displayUserName').value;
const code = getQueryParam('user_code');
if (code === null) {
alert('链接打开方式不正确,请重新打开');
return false;
}
if (authorization === '') {
alert('请输入授权码');
return false;
}
try {
const response = await fetch('/login/device', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
code,
authorization,
password,
displayUserName
})
})
if (!response.ok) {
alert('HTTP error! status: ' + response.status);
return false;
}
const result = await response.json();
if (result?.error !== 0) {
alert(result.message);
return false;
}
alert('登录成功, 请返回IDE查看并使用');
window.close();
} catch (e) {
alert('提交表单时出错,请稍后再试');
}
}
</script>
</body>
</html>

278
static/public/help.html Normal file
View File

@@ -0,0 +1,278 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Copilot 配置指南</title>
<style>
:root {
--primary-color: #0066CC;
--background-light: #ffffff;
--text-color: #1d1d1f;
--code-background: #f5f7fa;
--border-color: #d2d2d7;
--warning-background: #fff7ed;
--warning-border: #fec589;
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', sans-serif;
line-height: 1.6;
color: var(--text-color);
max-width: 800px;
margin: 0 auto;
padding: 2rem;
background-color: var(--background-light);
}
h1 {
font-size: 2.5rem;
font-weight: 600;
margin-bottom: 2rem;
color: var(--text-color);
}
h2 {
font-size: 1.5rem;
font-weight: 600;
margin-top: 3rem;
margin-bottom: 1rem;
color: var(--text-color);
}
.step {
margin-bottom: 1rem;
padding-left: 1.5rem;
position: relative;
}
.step::before {
content: "";
position: absolute;
left: 0;
top: 0.5rem;
width: 6px;
height: 6px;
border-radius: 50%;
background-color: var(--primary-color);
}
.step a {
color: var(--primary-color);
text-decoration: none;
transition: var(--transition);
}
pre {
background-color: var(--code-background);
border-radius: 12px;
padding: 1.5rem;
overflow-x: auto;
margin: 1.5rem 0;
font-family: 'SF Mono', Monaco, Consolas, monospace;
font-size: 0.9rem;
line-height: 1.5;
}
code {
font-family: 'SF Mono', Monaco, Consolas, monospace;
background-color: var(--code-background);
padding: 0.2rem 0.4rem;
border-radius: 4px;
font-size: 0.9em;
}
.warning {
background-color: var(--warning-background);
border: 1px solid var(--warning-border);
border-radius: 12px;
padding: 1rem 1.5rem;
margin: 1.5rem 0;
font-size: 0.95rem;
}
.warning::before {
content: "🚨";
margin-right: 0.5rem;
}
.note {
background-color: var(--code-background);
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 1rem 1.5rem;
margin: 1.5rem 0;
font-size: 0.95rem;
}
.note::before {
content: "🚧";
margin-right: 0.5rem;
}
@media (prefers-color-scheme: dark) {
:root {
--background-light: #1d1d1f;
--text-color: #f5f5f7;
--code-background: #2c2c2e;
--border-color: #3a3a3c;
--warning-background: #3a3123;
--warning-border: #8b5e34;
}
}
@media (max-width: 768px) {
body {
padding: 1rem;
}
h1 {
font-size: 2rem;
}
pre {
padding: 1rem;
}
}
.config-wrapper {
position: relative;
}
.copy-button {
position: absolute;
top: 1rem;
right: 1rem;
padding: 0.5rem 1rem;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: 6px;
font-size: 0.9rem;
cursor: pointer;
transition: var(--transition);
}
.copy-button:hover {
background-color: var(--hover-color);
}
.dynamic-domain {
color: var(--primary-color);
font-weight: 500;
}
#show-hb {
display: none;
}
#hidden-hb {
display: block;
}
.footer {
display: flex;
justify-content: center;
align-items: center;
margin-top: 32px;
font-size: 13px;
color: #86868b;
}
.footer a {
color: var(--primary-color);
text-decoration: none;
transition: var(--transition);
}
.footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>Copilot 配置指南</h1>
<h2>VSCode</h2>
<div class="step">安装插件: <code>GitHub Copilot</code></div>
<div class="step">修改 VSCode 的 settings.json 文件, 添加以下配置:</div>
<div class="config-wrapper">
<pre id="configCode">{
"github.copilot.advanced": {
"authProvider": "github-enterprise",
"debug.overrideCAPIUrl": "https://api.<span class="dynamic-domain">loading...</span>",
"debug.overrideProxyUrl": "https://copilot-proxy.<span class="dynamic-domain">loading...</span>",
"debug.chatOverrideProxyUrl": "https://api.<span class="dynamic-domain">loading...</span>/chat/completions",
"debug.overrideFastRewriteEngine": "v1/engines/copilot-centralus-h100",
"debug.overrideFastRewriteUrl": "https://api.<span class="dynamic-domain">loading...</span>"
},
"github-enterprise.uri": "https://<span class="dynamic-domain">loading...</span>"
}</pre>
<button id="copyBtn" class="copy-button">复制配置</button>
</div>
<h2>Jetbrains IDE系列</h2>
<div class="step">找到<code>设置</code> > <code>语言与框架</code> > <code>GitHub Copilot</code> > <code>Authentication
Provider</code></div>
<div class="step">填写的值为: <code><span class="dynamic-domain">loading...</span></code></div>
<h2>Visual Studio 2022</h2>
<div class="step">更新到最新版本(内置 Copilot 版本)至少是 <code>17.10.x</code> 以上</div>
<div class="step">首先, 开启 Github Enterprise 账户支持:工具->环境->账户->勾选 <code>包含 Github Enterprise 服务器账户</code></div>
<div class="step">然后, 重启你的 <code>Visual Studio 2022</code> 编辑器</div>
<div class="step">最后, 点击添加 Github 账户,切换到 Github Enterprise 选项卡,输入 <code>https://<span
class="dynamic-domain">loading...</span></code> 即可。
</div>
<h2>HBuilderX</h2>
<div id="show-hb">
<div class="step">点击下载 <code><a href="https://pan.quark.cn/s/70e6849970e5" target="_blank">copilot-for-hbuilderx-v1.zip</a></code>
插件到本地
</div>
<div class="step">将插件安装到 plugin目录下, 具体教程参考: <code><a
href="https://hx.dcloud.net.cn/Tutorial/OfflineInstall" target="_blank">离线插件安装指南</a></code></div>
<div class="step">重启 Hbuilder X 后点击登录 <code>GitHub Copilot</code> 即可.</div>
</div>
<div id="hidden-hb" class="warning">
当前部署方式不支持 HBuilderX
</div>
<div class="footer">
© 2024 Open Source Contributors
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
// 获取当前域名和端口
const currentHost = window.location.host; // 这将获取 "domain:port" 格式
// 只要是默认本地部署的域名,就显示 HBuilderX 的安装步骤
if (currentHost.includes('copilot.supercopilot.top')) {
document.getElementById('show-hb').style.display = 'block';
document.getElementById('hidden-hb').style.display = 'none';
} else {
document.getElementById('show-hb').style.display = 'none';
document.getElementById('hidden-hb').style.display = 'block';
}
// 更新所有需要替换的地方
const domainElements = document.querySelectorAll('.dynamic-domain');
domainElements.forEach(element => {
element.textContent = currentHost;
});
});
document.getElementById('copyBtn').addEventListener('click', function () {
const configText = document.getElementById('configCode').textContent;
navigator.clipboard.writeText(configText).then(() => {
const originalText = this.textContent;
this.textContent = '已复制!';
setTimeout(() => {
this.textContent = originalText;
}, 2000);
});
});
</script>
</body>
</html>

265
static/public/login.html Normal file
View File

@@ -0,0 +1,265 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>获取 GitHub GHU</title>
<style>
:root {
--primary-color: #0066CC;
--hover-color: #0256A8;
--background-light: #ffffff;
--text-color: #1d1d1f;
--input-background: #fbfbfd;
--input-border: #d2d2d7;
--transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
body, html {
height: 100%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', sans-serif;
background-color: var(--background-light);
color: var(--text-color);
}
.login-container {
background-color: var(--background-light);
padding: 3.5em 4em;
border-radius: 20px;
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
text-align: center;
width: 90%;
max-width: 440px;
transition: var(--transition);
}
h1 {
font-size: 24px;
font-weight: 500;
margin-bottom: 1.5em;
color: var(--text-color);
}
.form-box {
display: flex;
flex-direction: column;
align-items: center;
}
input {
width: 100%;
padding: 12px 16px;
margin: 6px 0;
border: 1px solid var(--input-border);
border-radius: 12px;
background-color: var(--input-background);
font-size: 15px;
transition: var(--transition);
outline: none;
box-sizing: border-box;
}
input:focus {
border-color: var(--primary-color);
box-shadow: 0 0 0 4px rgba(0, 102, 204, 0.1);
}
.submit-button {
width: 90%;
padding: 12px;
margin-top: 24px;
border: none;
border-radius: 12px;
background-color: var(--primary-color);
color: white;
font-size: 15px;
font-weight: 500;
cursor: pointer;
transition: var(--transition);
text-align: center;
}
.submit-button:hover {
background-color: var(--hover-color);
transform: translateY(-1px);
}
.submit-button:active {
transform: translateY(0);
}
.footer {
margin-top: 32px;
font-size: 13px;
color: #86868b;
}
.footer a {
color: var(--primary-color);
text-decoration: none;
transition: var(--transition);
}
.footer a:hover {
text-decoration: underline;
}
.code-content {
display: flex;
justify-content: center;
align-items: center;
height: 60px;
margin: 20px 0;
}
#code {
font-size: 32px;
letter-spacing: 8px;
font-weight: 600;
color: var(--primary-color);
font-family: SF Mono, monospace;
}
.measure-time {
background-color: transparent;
border: 1px solid var(--primary-color);
color: var(--primary-color);
}
#token-box {
display: none;
animation: fadeIn 0.3s ease-in-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
/* Dark mode */
@media (prefers-color-scheme: dark) {
:root {
--background-light: #1d1d1f;
--text-color: #f5f5f7;
--input-background: #2c2c2e;
--input-border: #3a3a3c;
}
.login-container {
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}
input::placeholder {
color: #86868b;
}
}
</style>
</head>
<body>
<div class="login-container">
<h1>获取 GitHub GHU</h1>
<div class="form-box">
<div id="token-box">
<div class="code-content">
<div id="code"></div>
</div>
<input type="text" id="token" placeholder="正在获取ghu_" readonly/>
<div id="timeing" class="submit-button measure-time">剩余时间: 900 秒</div>
</div>
<div id="submit-btn" class="submit-button" onclick="onSubmit()">登录 GitHub 获取授权码</div>
</div>
<div class="footer">
© 2024 Open Source Contributors
</div>
</div>
<script type="text/javascript">
let device_code = null;
let timer = null;
function countDown(time = 900) {
const timeing = document.getElementById('timeing');
timer = setInterval(() => {
time -= 1;
timeing.innerText = `剩余时间: ${time}`;
if (time <= 0) {
clearInterval(timer);
document.getElementById('submit-btn').style.display = 'block';
timeing.style.display = 'none';
alert("授权码已过期,请重新获取");
window.location.reload();
}
}, 1000);
}
async function onSubmit() {
const response = await fetch('/github/login/device/code', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
})
if (response.status !== 200) {
alert('获取授权码失败')
window.location.reload()
return
}
const resultJson = await response.json()
confirm(`打开浏览器访问: ${resultJson.verification_uri}, 并输入授权码: ${resultJson.user_code}`)
copyCode(resultJson.user_code)
device_code = resultJson.device_code
document.getElementById('submit-btn').style.display = 'none';
document.getElementById('token-box').style.display = 'block';
document.getElementById("code").innerText = resultJson.user_code;
countDown(resultJson.expires_in);
window.open(resultJson.verification_uri);
// 根据user_code获取ghu_token
await getGhuToken();
}
function copyCode(user_code) {
const input = document.createElement('input');
input.value = user_code;
document.body.appendChild(input);
input.select();
document.execCommand('copy');
document.body.removeChild(input);
}
async function getGhuToken() {
await new Promise(resolve => setTimeout(resolve, 5000))
const response = await fetch('/github/login/ghu-token', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({device_code})
})
if (response.status !== 200) {
alert('获取ghu_token失败')
window.location.reload()
return false;
}
const resultJson = await response.json()
if (resultJson.error === "slow_down" && resultJson.error_description === "Too many requests have been made in the same timeframe.") {
await new Promise(resolve => setTimeout(resolve, resultJson.interval * 1000))
}
const access_token = resultJson?.access_token || null
if (access_token !== null) {
document.getElementById('token').value = access_token
clearInterval(timer);
document.getElementById("timeing").style.display = 'none';
document.getElementById("code").style.display = 'none';
return false;
}
await getGhuToken()
}
</script>
</body>
</html>

8
static/static.go Normal file
View File

@@ -0,0 +1,8 @@
package static
import "embed"
var (
//go:embed public
Public embed.FS
)