github-actions[bot] commited on
Commit
bdbf92c
·
1 Parent(s): 86b6928

Update from GitHub Actions

Browse files
Files changed (3) hide show
  1. Dockerfile +10 -9
  2. src/utils/common-utils.js +16 -0
  3. src/web-server.js +50 -4
Dockerfile CHANGED
@@ -30,6 +30,12 @@ ENV PLAYWRIGHT_SKIP_BROWSER_VALIDATION=1
30
  # 复制 package.json 和 package-lock.json
31
  COPY package*.json ./
32
 
 
 
 
 
 
 
33
  # 安装 Node.js 依赖
34
  RUN npm ci --only=production
35
 
@@ -37,17 +43,12 @@ RUN npm ci --only=production
37
  RUN addgroup -g 1001 -S nodejs && \
38
  adduser -S nodejs -u 1001
39
 
40
- # 复制应用程序文件
41
- COPY src/ ./src/
42
-
43
- # 复制 cookies.json 文件(如果存在)
44
- COPY cookies.json* ./
45
-
46
  # 创建 screenshots 和 logs 目录,并设置正确的权限
47
- RUN mkdir -p screenshots logs && \
 
48
  chown -R nodejs:nodejs /app && \
49
- chmod -R 775 /app/screenshots && \
50
- chmod -R 775 /app/logs
51
 
52
  # 切换到非 root 用户
53
  USER nodejs
 
30
  # 复制 package.json 和 package-lock.json
31
  COPY package*.json ./
32
 
33
+ # 复制应用程序文件
34
+ COPY src/ ./src/
35
+
36
+ # 复制 cookies.json 文件(如果存在)
37
+ COPY cookies.json* ./
38
+
39
  # 安装 Node.js 依赖
40
  RUN npm ci --only=production
41
 
 
43
  RUN addgroup -g 1001 -S nodejs && \
44
  adduser -S nodejs -u 1001
45
 
 
 
 
 
 
 
46
  # 创建 screenshots 和 logs 目录,并设置正确的权限
47
+ RUN mkdir -p /app/screenshots && \
48
+ mkdir -p /app/logs && \
49
  chown -R nodejs:nodejs /app && \
50
+ chmod -R 777 /app/screenshots && \
51
+ chmod -R 777 /app/logs
52
 
53
  # 切换到非 root 用户
54
  USER nodejs
src/utils/common-utils.js CHANGED
@@ -79,6 +79,22 @@ export function getRecentLogs(lines = 100) {
79
  }
80
  }
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  /**
83
  * 创建人类可读的时间戳
84
  * @returns {string} 格式化的时间戳 YYYY-MM-DD_HH-MM-SS
 
79
  }
80
  }
81
 
82
+ /**
83
+ * 清空日志文件
84
+ * @returns {boolean} 是否成功清空
85
+ */
86
+ export function clearLogFile() {
87
+ try {
88
+ ensureLogDirectory();
89
+ fs.writeFileSync(LOG_FILE, '');
90
+ console.log('日志文件已清空');
91
+ return true;
92
+ } catch (error) {
93
+ console.error('清空日志文件失败:', error);
94
+ return false;
95
+ }
96
+ }
97
+
98
  /**
99
  * 创建人类可读的时间戳
100
  * @returns {string} 格式化的时间戳 YYYY-MM-DD_HH-MM-SS
src/web-server.js CHANGED
@@ -1,6 +1,6 @@
1
  import { Hono } from 'hono';
2
  import { serve } from '@hono/node-server';
3
- import { getRecentLogs, log, logError } from './utils/common-utils.js';
4
  import config from './config.js';
5
 
6
  const app = new Hono();
@@ -242,9 +242,28 @@ const indexHTML = `
242
  }
243
  }
244
 
245
- function clearLogs() {
246
- document.getElementById('logContainer').innerHTML = '<div class="empty">日志显示已清空</div>';
247
- updateStatus('显示已清空');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  }
249
 
250
  // 页面加载时获取日志
@@ -280,6 +299,33 @@ app.get('/api/logs', (c) => {
280
  }
281
  });
282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  // API 路由 - 系统状态
284
  app.get('/api/status', (c) => {
285
  return c.json({
 
1
  import { Hono } from 'hono';
2
  import { serve } from '@hono/node-server';
3
+ import { getRecentLogs, log, logError, clearLogFile } from './utils/common-utils.js';
4
  import config from './config.js';
5
 
6
  const app = new Hono();
 
242
  }
243
  }
244
 
245
+ async function clearLogs() {
246
+ try {
247
+ updateStatus('正在清空日志...');
248
+
249
+ const response = await fetch('/api/clear-logs', {
250
+ method: 'POST',
251
+ headers: {
252
+ 'Content-Type': 'application/json'
253
+ }
254
+ });
255
+
256
+ const data = await response.json();
257
+
258
+ if (data.success) {
259
+ document.getElementById('logContainer').innerHTML = '<div class="empty">日志已清空</div>';
260
+ updateStatus('日志文件已清空 - ' + new Date().toLocaleString());
261
+ } else {
262
+ updateStatus('清空日志失败: ' + data.error);
263
+ }
264
+ } catch (error) {
265
+ updateStatus('清空日志时发生网络错误: ' + error.message);
266
+ }
267
  }
268
 
269
  // 页面加载时获取日志
 
299
  }
300
  });
301
 
302
+ // API 路由 - 清空日志
303
+ app.post('/api/clear-logs', (c) => {
304
+ try {
305
+ const success = clearLogFile();
306
+
307
+ if (success) {
308
+ log('日志文件已通过Web界面清空');
309
+ return c.json({
310
+ success: true,
311
+ message: '日志文件已清空',
312
+ timestamp: new Date().toISOString()
313
+ });
314
+ } else {
315
+ return c.json({
316
+ success: false,
317
+ error: '清空日志文件失败'
318
+ }, 500);
319
+ }
320
+ } catch (error) {
321
+ logError('清空日志API错误:', error);
322
+ return c.json({
323
+ success: false,
324
+ error: error.message
325
+ }, 500);
326
+ }
327
+ });
328
+
329
  // API 路由 - 系统状态
330
  app.get('/api/status', (c) => {
331
  return c.json({