Skip to content

Commit 1cbeca1

Browse files
authored
Merge branch 'ling-drag0n:main' into main
2 parents 36d7288 + dd491d4 commit 1cbeca1

File tree

8 files changed

+18
-8
lines changed

8 files changed

+18
-8
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,5 @@ out
106106
.tern-port
107107

108108
# Stores VSCode versions used for testing VSCode extensions
109-
.vscode-test
109+
.vscode-test
110+
.spec-workflow

backend/docker-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ server.use(async (req, res, next) => {
523523
req.env = {
524524
DB: sqliteAdapter,
525525
ENCRYPTION_SECRET: process.env.ENCRYPTION_SECRET || "default-encryption-key",
526+
ADMIN_TOKEN_EXPIRY_DAYS: process.env.ADMIN_TOKEN_EXPIRY_DAYS || "7",
526527
};
527528

528529
next();
@@ -779,7 +780,6 @@ function startMemoryMonitoring(interval = 1200000) {
779780
// 简单读取容器内存使用情况
780781
const getContainerMemory = () => {
781782
try {
782-
const fs = require("fs");
783783
// 尝试读取cgroup内存使用(优先v2,回退v1)
784784
let usage = null,
785785
limit = null;

backend/src/routes/adminRoutes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ adminRoutes.post("/api/admin/login", async (c) => {
1313
const { username, password } = await c.req.json();
1414

1515
try {
16-
const loginResult = await login(db, username, password);
16+
const loginResult = await login(db, username, password, c.env);
1717

1818
return c.json({
1919
code: ApiStatus.SUCCESS,

backend/src/services/adminService.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ export async function validateAdminToken(db, token) {
3838
* @param {D1Database} db - D1数据库实例
3939
* @param {string} username - 用户名
4040
* @param {string} password - 密码
41+
* @param {Object} env - 环境变量对象
4142
* @returns {Promise<Object>} 登录结果,包含token和过期时间
4243
*/
43-
export async function login(db, username, password) {
44+
export async function login(db, username, password, env = {}) {
4445
// 参数验证
4546
if (!username || !password) {
4647
throw new HTTPException(ApiStatus.BAD_REQUEST, { message: "用户名和密码不能为空" });
@@ -88,7 +89,10 @@ export async function login(db, username, password) {
8889
// 生成并存储令牌
8990
const token = generateRandomString(32);
9091
const expiresAt = new Date();
91-
expiresAt.setDate(expiresAt.getDate() + 1); // 1天过期
92+
93+
// 从环境变量读取token过期天数,默认7天
94+
const expiryDays = parseInt(env.ADMIN_TOKEN_EXPIRY_DAYS || "7", 10);
95+
expiresAt.setDate(expiresAt.getDate() + expiryDays);
9296

9397
// 使用 AdminRepository 创建令牌
9498
await adminRepository.createToken(admin.id, token, expiresAt);

backend/src/storage/drivers/s3/S3StorageDriver.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { CAPABILITIES } from "../../interfaces/capabilities/index.js";
88
import { HTTPException } from "hono/http-exception";
99
import { ApiStatus } from "../../../constants/index.js";
1010
import { createS3Client } from "../../../utils/s3Utils.js";
11-
import { normalizeS3SubPath } from "./utils/S3PathUtils.js";
11+
import { normalizeS3SubPath, isCompleteFilePath } from "./utils/S3PathUtils.js";
1212
import { updateMountLastUsed, findMountPointByPath } from "../../fs/utils/MountResolver.js";
1313
import { buildFullProxyUrl, buildSignedProxyUrl } from "../../../constants/proxy.js";
1414
import { ProxySignatureService } from "../../../services/ProxySignatureService.js";
@@ -673,7 +673,6 @@ export class S3StorageDriver extends BaseDriver {
673673
const fileName = customFilename || path.split("/").filter(Boolean).pop() || "unnamed_file";
674674

675675
// 智能检查s3SubPath是否已经包含完整的文件路径
676-
const { isCompleteFilePath } = require("./utils/S3PathUtils.js");
677676
if (s3SubPath && isCompleteFilePath(s3SubPath, fileName)) {
678677
// 添加root_prefix(如果有)
679678
const rootPrefix = this.config.root_prefix ? (this.config.root_prefix.endsWith("/") ? this.config.root_prefix : this.config.root_prefix + "/") : "";

backend/src/storage/drivers/s3/utils/S3PathUtils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* 提供S3存储驱动专用的路径规范化功能
44
*/
55

6+
import path from "path";
7+
68
/**
79
* 规范化S3子路径
810
* @param {string} subPath - 子路径
@@ -42,7 +44,6 @@ export function isCompleteFilePath(s3SubPath, originalFileName) {
4244
if (!s3SubPath || !originalFileName) return false;
4345

4446
// Node.js path 模块解析路径
45-
const path = require("path");
4647
const pathInfo = path.parse(s3SubPath);
4748
const originalInfo = path.parse(originalFileName);
4849

backend/wrangler.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ compatibility_flags = ["nodejs_compat"]
77
[vars]
88
# 用于加密敏感配置的密钥
99
# ENCRYPTION_SECRET = "lzl123456789987654321"
10+
# 管理员Token过期天数,默认7天
11+
# ADMIN_TOKEN_EXPIRY_DAYS = "7"
1012

1113
# 绑定D1数据库
1214
# 需要替换为实际的数据库ID
@@ -20,6 +22,7 @@ database_id = "xxxxxxxxxxxxxxxxx"
2022
# 开发环境变量
2123
[env.dev.vars]
2224
ENCRYPTION_SECRET = "dev-encryption-secret-key"
25+
ADMIN_TOKEN_EXPIRY_DAYS = "7"
2326

2427
[[env.dev.d1_databases]]
2528
binding = "DB"

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ services:
2929
- LOG_LEVEL=2 # 日志级别
3030
# 重要: 请修改为您自己的安全密钥,用于加密数据
3131
- ENCRYPTION_SECRET=xxxxxxx
32+
# 管理员Token过期天数,默认7天
33+
- ADMIN_TOKEN_EXPIRY_DAYS=7
3234
volumes:
3335
- ./sql_data:/data # 将当前目录下的sql_data映射到容器的/data目录
3436
ports:

0 commit comments

Comments
 (0)