feat: apply UI/storage/share optimizations and quota improvements

This commit is contained in:
2026-02-12 18:02:57 +08:00
parent 1fcc60b9aa
commit 12859cbb20
13 changed files with 4476 additions and 828 deletions

View File

@@ -2,6 +2,8 @@ const jwt = require('jsonwebtoken');
const crypto = require('crypto');
const { UserDB } = require('./database');
const { decryptSecret } = require('./utils/encryption');
const DEFAULT_LOCAL_STORAGE_QUOTA_BYTES = 1024 * 1024 * 1024; // 1GB
const DEFAULT_OSS_STORAGE_QUOTA_BYTES = 1024 * 1024 * 1024; // 1GB
// JWT密钥必须在环境变量中设置
const JWT_SECRET = process.env.JWT_SECRET || 'your-secret-key-change-in-production';
@@ -169,6 +171,11 @@ function authMiddleware(req, res, next) {
});
}
const rawOssQuota = Number(user.oss_storage_quota);
const effectiveOssQuota = Number.isFinite(rawOssQuota) && rawOssQuota > 0
? rawOssQuota
: DEFAULT_OSS_STORAGE_QUOTA_BYTES;
// 将用户信息附加到请求对象(包含所有存储相关字段)
req.user = {
id: user.id,
@@ -187,8 +194,10 @@ function authMiddleware(req, res, next) {
// 存储相关字段
storage_permission: user.storage_permission || 'oss_only',
current_storage_type: user.current_storage_type || 'oss',
local_storage_quota: user.local_storage_quota || 1073741824,
local_storage_quota: user.local_storage_quota || DEFAULT_LOCAL_STORAGE_QUOTA_BYTES,
local_storage_used: user.local_storage_used || 0,
oss_storage_quota: effectiveOssQuota,
storage_used: user.storage_used || 0,
// 主题偏好
theme_preference: user.theme_preference || null
};