feat(quota): add downloadable traffic quota with local/OSS/share metering
This commit is contained in:
@@ -175,6 +175,17 @@ function authMiddleware(req, res, next) {
|
||||
const effectiveOssQuota = Number.isFinite(rawOssQuota) && rawOssQuota > 0
|
||||
? rawOssQuota
|
||||
: DEFAULT_OSS_STORAGE_QUOTA_BYTES;
|
||||
const rawDownloadTrafficQuota = Number(user.download_traffic_quota);
|
||||
const effectiveDownloadTrafficQuota = Number.isFinite(rawDownloadTrafficQuota) && rawDownloadTrafficQuota > 0
|
||||
? Math.floor(rawDownloadTrafficQuota)
|
||||
: 0; // 0 表示不限流量
|
||||
const rawDownloadTrafficUsed = Number(user.download_traffic_used);
|
||||
const normalizedDownloadTrafficUsed = Number.isFinite(rawDownloadTrafficUsed) && rawDownloadTrafficUsed > 0
|
||||
? Math.floor(rawDownloadTrafficUsed)
|
||||
: 0;
|
||||
const cappedDownloadTrafficUsed = effectiveDownloadTrafficQuota > 0
|
||||
? Math.min(normalizedDownloadTrafficUsed, effectiveDownloadTrafficQuota)
|
||||
: normalizedDownloadTrafficUsed;
|
||||
|
||||
// 将用户信息附加到请求对象(包含所有存储相关字段)
|
||||
req.user = {
|
||||
@@ -198,6 +209,8 @@ function authMiddleware(req, res, next) {
|
||||
local_storage_used: user.local_storage_used || 0,
|
||||
oss_storage_quota: effectiveOssQuota,
|
||||
storage_used: user.storage_used || 0,
|
||||
download_traffic_quota: effectiveDownloadTrafficQuota,
|
||||
download_traffic_used: cappedDownloadTrafficUsed,
|
||||
// 主题偏好
|
||||
theme_preference: user.theme_preference || null
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user