ZhaoShanGeng
commited on
Commit
·
c0eeb39
1
Parent(s):
77a26e9
fix: 修复构建脚本、Dockerfile、添加token刷新端点和手动刷新按钮
Browse files- Dockerfile.binary +4 -6
- public/js/tokens.js +10 -0
- scripts/build.js +28 -10
- src/routes/admin.js +21 -0
Dockerfile.binary
CHANGED
|
@@ -20,17 +20,15 @@ COPY dist/antigravity-linux-* /app/antigravity
|
|
| 20 |
COPY dist/public /app/public
|
| 21 |
COPY dist/bin /app/bin
|
| 22 |
COPY dist/config.json /app/config.json
|
| 23 |
-
COPY dist/.env.example /app/.env.example
|
| 24 |
|
| 25 |
# 设置执行权限
|
| 26 |
RUN chmod +x /app/antigravity && \
|
| 27 |
(chmod +x /app/bin/* 2>/dev/null || true)
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
RUN mkdir -p /app/data /app/public/images
|
| 31 |
-
|
| 32 |
-
#
|
| 33 |
-
RUN cp /app/.env.example /app/.env
|
| 34 |
|
| 35 |
# 创建启动脚本:同步环境变量到 .env 文件
|
| 36 |
RUN cat > /app/entrypoint.sh << 'EOF'
|
|
|
|
| 20 |
COPY dist/public /app/public
|
| 21 |
COPY dist/bin /app/bin
|
| 22 |
COPY dist/config.json /app/config.json
|
|
|
|
| 23 |
|
| 24 |
# 设置执行权限
|
| 25 |
RUN chmod +x /app/antigravity && \
|
| 26 |
(chmod +x /app/bin/* 2>/dev/null || true)
|
| 27 |
|
| 28 |
+
# 创建数据和图片目录,以及空白 .env 文件
|
| 29 |
+
RUN mkdir -p /app/data /app/public/images && \
|
| 30 |
+
echo "# 环境变量配置文件" > /app/.env && \
|
| 31 |
+
echo "# 如果不配置凭据,系统会自动生成随机凭据" >> /app/.env
|
|
|
|
| 32 |
|
| 33 |
# 创建启动脚本:同步环境变量到 .env 文件
|
| 34 |
RUN cat > /app/entrypoint.sh << 'EOF'
|
public/js/tokens.js
CHANGED
|
@@ -104,6 +104,7 @@ function renderTokens(tokens) {
|
|
| 104 |
</div>
|
| 105 |
<div class="token-actions">
|
| 106 |
<button class="btn btn-info btn-xs" onclick="showQuotaModal('${safeRefreshToken}')" title="查看额度">📊 详情</button>
|
|
|
|
| 107 |
<button class="btn ${token.enable ? 'btn-warning' : 'btn-success'} btn-xs" onclick="toggleToken('${safeRefreshToken}', ${!token.enable})" title="${token.enable ? '禁用' : '启用'}">
|
| 108 |
${token.enable ? '⏸️ 禁用' : '▶️ 启用'}
|
| 109 |
</button>
|
|
@@ -126,6 +127,15 @@ function renderTokens(tokens) {
|
|
| 126 |
}
|
| 127 |
}
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
// 自动刷新过期 Token
|
| 130 |
async function autoRefreshToken(refreshToken) {
|
| 131 |
if (refreshingTokens.has(refreshToken)) return;
|
|
|
|
| 104 |
</div>
|
| 105 |
<div class="token-actions">
|
| 106 |
<button class="btn btn-info btn-xs" onclick="showQuotaModal('${safeRefreshToken}')" title="查看额度">📊 详情</button>
|
| 107 |
+
<button class="btn btn-primary btn-xs" onclick="manualRefreshToken('${safeRefreshToken}')" title="刷新Token" ${isRefreshing ? 'disabled' : ''}>🔄 刷新</button>
|
| 108 |
<button class="btn ${token.enable ? 'btn-warning' : 'btn-success'} btn-xs" onclick="toggleToken('${safeRefreshToken}', ${!token.enable})" title="${token.enable ? '禁用' : '启用'}">
|
| 109 |
${token.enable ? '⏸️ 禁用' : '▶️ 启用'}
|
| 110 |
</button>
|
|
|
|
| 127 |
}
|
| 128 |
}
|
| 129 |
|
| 130 |
+
// 手动刷新 Token
|
| 131 |
+
async function manualRefreshToken(refreshToken) {
|
| 132 |
+
if (refreshingTokens.has(refreshToken)) {
|
| 133 |
+
showToast('该 Token 正在刷新中', 'warning');
|
| 134 |
+
return;
|
| 135 |
+
}
|
| 136 |
+
await autoRefreshToken(refreshToken);
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
// 自动刷新过期 Token
|
| 140 |
async function autoRefreshToken(refreshToken) {
|
| 141 |
if (refreshingTokens.has(refreshToken)) return;
|
scripts/build.js
CHANGED
|
@@ -187,18 +187,36 @@ try {
|
|
| 187 |
// 复制 public 目录(排除 images)
|
| 188 |
const publicSrcDir = path.join(rootDir, 'public');
|
| 189 |
const publicDestDir = path.join(distDir, 'public');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
if (fs.existsSync(publicSrcDir)) {
|
| 191 |
-
|
| 192 |
-
fs.
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
}
|
| 201 |
-
|
|
|
|
| 202 |
}
|
| 203 |
|
| 204 |
// 复制 bin 目录(只复制对应平台的文件)
|
|
|
|
| 187 |
// 复制 public 目录(排除 images)
|
| 188 |
const publicSrcDir = path.join(rootDir, 'public');
|
| 189 |
const publicDestDir = path.join(distDir, 'public');
|
| 190 |
+
console.log(` Source: ${publicSrcDir}`);
|
| 191 |
+
console.log(` Dest: ${publicDestDir}`);
|
| 192 |
+
console.log(` Source exists: ${fs.existsSync(publicSrcDir)}`);
|
| 193 |
+
|
| 194 |
if (fs.existsSync(publicSrcDir)) {
|
| 195 |
+
try {
|
| 196 |
+
if (fs.existsSync(publicDestDir)) {
|
| 197 |
+
console.log(' Removing existing public directory...');
|
| 198 |
+
fs.rmSync(publicDestDir, { recursive: true, force: true });
|
| 199 |
+
}
|
| 200 |
+
// 使用系统命令复制目录(更可靠)
|
| 201 |
+
console.log(' Copying public directory...');
|
| 202 |
+
if (process.platform === 'win32') {
|
| 203 |
+
execSync(`xcopy /E /I /Y /Q "${publicSrcDir}" "${publicDestDir}"`, { stdio: 'pipe', shell: true });
|
| 204 |
+
} else {
|
| 205 |
+
fs.mkdirSync(publicDestDir, { recursive: true });
|
| 206 |
+
execSync(`cp -r "${publicSrcDir}"/* "${publicDestDir}/"`, { stdio: 'pipe', shell: true });
|
| 207 |
+
}
|
| 208 |
+
// 删除 images 目录(运行时生成,不需要打包)
|
| 209 |
+
const imagesDir = path.join(publicDestDir, 'images');
|
| 210 |
+
if (fs.existsSync(imagesDir)) {
|
| 211 |
+
fs.rmSync(imagesDir, { recursive: true, force: true });
|
| 212 |
+
}
|
| 213 |
+
console.log(' ✓ Copied public directory');
|
| 214 |
+
} catch (err) {
|
| 215 |
+
console.error(' ❌ Failed to copy public directory:', err.message);
|
| 216 |
+
throw err;
|
| 217 |
}
|
| 218 |
+
} else {
|
| 219 |
+
console.error(' ❌ Source public directory not found!');
|
| 220 |
}
|
| 221 |
|
| 222 |
// 复制 bin 目录(只复制对应平台的文件)
|
src/routes/admin.js
CHANGED
|
@@ -178,6 +178,27 @@ router.post('/tokens/reload', authMiddleware, async (req, res) => {
|
|
| 178 |
}
|
| 179 |
});
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
router.post('/oauth/exchange', authMiddleware, async (req, res) => {
|
| 182 |
const { code, port } = req.body;
|
| 183 |
if (!code || !port) {
|
|
|
|
| 178 |
}
|
| 179 |
});
|
| 180 |
|
| 181 |
+
// 刷新指定Token的access_token
|
| 182 |
+
router.post('/tokens/:refreshToken/refresh', authMiddleware, async (req, res) => {
|
| 183 |
+
const { refreshToken } = req.params;
|
| 184 |
+
try {
|
| 185 |
+
logger.info('正在刷新token...');
|
| 186 |
+
const tokens = await tokenManager.getTokenList();
|
| 187 |
+
const tokenData = tokens.find(t => t.refresh_token === refreshToken);
|
| 188 |
+
|
| 189 |
+
if (!tokenData) {
|
| 190 |
+
return res.status(404).json({ success: false, message: 'Token不存在' });
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
// 调用 tokenManager 的刷新方法
|
| 194 |
+
const refreshedToken = await tokenManager.refreshToken(tokenData);
|
| 195 |
+
res.json({ success: true, message: 'Token刷新成功', data: { expires_in: refreshedToken.expires_in, timestamp: refreshedToken.timestamp } });
|
| 196 |
+
} catch (error) {
|
| 197 |
+
logger.error('刷新Token失败:', error.message);
|
| 198 |
+
res.status(500).json({ success: false, message: error.message });
|
| 199 |
+
}
|
| 200 |
+
});
|
| 201 |
+
|
| 202 |
router.post('/oauth/exchange', authMiddleware, async (req, res) => {
|
| 203 |
const { code, port } = req.body;
|
| 204 |
if (!code || !port) {
|