Skip to content

Commit 12c5e1f

Browse files
committed
Update workflow names to Chinese and enhance AuthService with data persistence features, including directory and file creation for authentication data. Modify terminal.js to comment out socketPath configuration.
1 parent f8502bf commit 12c5e1f

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

.github/workflows/build-runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Docker Build and Push
1+
name: 构建 Runner 镜像
22

33
on:
44
push:

.github/workflows/docker-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Docker Build and Push
1+
name: 构建 CodeRun 控制端镜像
22

33
on:
44
push:

services/auth.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,73 @@
11
const axios = require("axios");
22
const jwt = require("jsonwebtoken");
33
const configStore = require("./config-store");
4+
const fs = require("fs");
5+
const path = require("path");
46

57
class AuthService {
68
constructor() {
79
this.runnerConfig = null;
810
this.runnerToken = null;
911
this.deviceId = null;
1012
this.lastUpdated = new Date();
13+
// 修改存储路径到 data 文件夹
14+
this.dataDir = path.join(__dirname, "../data");
15+
this.authFile = path.join(this.dataDir, "auth.json");
16+
this.ensureDataDirectory();
17+
this.loadAuthData();
18+
}
19+
20+
// 确保数据目录和文件存在
21+
ensureDataDirectory() {
22+
try {
23+
if (!fs.existsSync(this.dataDir)) {
24+
fs.mkdirSync(this.dataDir, { recursive: true });
25+
console.log("[AuthService] ✅ 成功创建数据目录");
26+
}
27+
28+
if (!fs.existsSync(this.authFile)) {
29+
fs.writeFileSync(this.authFile, JSON.stringify({}, null, 2));
30+
console.log("[AuthService] ✅ 成功创建认证数据文件");
31+
}
32+
} catch (error) {
33+
console.error("[AuthService] ❌ 创建数据目录或文件失败:", error.message);
34+
}
35+
}
36+
37+
loadAuthData() {
38+
try {
39+
if (fs.existsSync(this.authFile)) {
40+
const data = JSON.parse(fs.readFileSync(this.authFile, 'utf8'));
41+
this.runnerConfig = data.runnerConfig;
42+
this.runnerToken = data.runnerToken;
43+
this.deviceId = data.deviceId;
44+
this.lastUpdated = new Date(data.lastUpdated);
45+
46+
// Update JWT secret from loaded config if available
47+
if (this.runnerConfig && this.runnerConfig.jwtSecret) {
48+
configStore.set("jwt.secret", this.runnerConfig.jwtSecret);
49+
}
50+
51+
console.log("[AuthService] ✅ 成功从文件加载认证数据");
52+
}
53+
} catch (error) {
54+
console.error("[AuthService] ❌ 加载认证数据失败:", error.message);
55+
}
56+
}
57+
58+
saveAuthData() {
59+
try {
60+
const data = {
61+
runnerConfig: this.runnerConfig,
62+
runnerToken: this.runnerToken,
63+
deviceId: this.deviceId,
64+
lastUpdated: this.lastUpdated.toISOString()
65+
};
66+
fs.writeFileSync(this.authFile, JSON.stringify(data, null, 2));
67+
console.log("[AuthService] ✅ 成功保存认证数据到文件");
68+
} catch (error) {
69+
console.error("[AuthService] ❌ 保存认证数据失败:", error.message);
70+
}
1171
}
1272

1373
async getRunnerConfig() {
@@ -41,6 +101,9 @@ class AuthService {
41101
configStore.set("jwt.secret", response.data.jwtSecret);
42102
}
43103

104+
// Save the new auth data to file
105+
this.saveAuthData();
106+
44107
console.log("[AuthService] ✅ Runner配置获取成功");
45108
return this.runnerConfig;
46109
} catch (error) {
@@ -68,6 +131,7 @@ class AuthService {
68131

69132
async updateLastUpdated() {
70133
this.lastUpdated = new Date();
134+
this.saveAuthData(); // Save when last updated changes
71135
}
72136

73137
verifyToken(token) {

services/terminal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require('path');
55

66
// 配置Docker连接
77
const docker = new Docker({
8-
socketPath: process.env.DOCKER_SOCKET || '/var/run/docker.sock',
8+
//socketPath: process.env.DOCKER_SOCKET || '/var/run/docker.sock',
99
// 如果使用TCP连接(可选)
1010
// host: process.env.DOCKER_HOST || 'localhost',
1111
// port: process.env.DOCKER_PORT || 2375,

0 commit comments

Comments
 (0)