ow
This commit is contained in:
1 parent
9b01c4a57a
commit
6417562c4f
37 files changed
+2767
-202
No files matched your search
@@ -24,6 +24,36 @@ namespace CloudBuilder.Security.Policy
|
||||
public const string FfmpegPictrue = "Ffmpeg:Pictrue";
|
||||
public const string FfmpegArguments = "Ffmpeg:Arguments";
|
||||
|
||||
// 网盘额度(appsettings.json:NetDiskQuota),按 user_type 码取档
|
||||
public const string NetDiskQuotaSection = "NetDiskQuota";
|
||||
|
||||
/// <summary>
|
||||
/// 取当前用户类型的网盘额度(KB)。类型码缺失/未知回退按未认证(U)最小权限档;
|
||||
/// 未配置或解析不出数值时返回 0(调用方据 0 判定"不限额"还是"不可用")。
|
||||
/// </summary>
|
||||
public static long GetNetDiskQuotaKB(IApplicationService service, string userType)
|
||||
{
|
||||
var code = string.IsNullOrWhiteSpace(userType) ? SecurityUserTypePolicy.UNAUTHENTICATED_USERS : userType.Trim().ToUpperInvariant();
|
||||
var raw = service.Configuration[$"{NetDiskQuotaSection}:{code}"];
|
||||
// 未知类型码回退未认证档,避免历史脏码绕过限额
|
||||
if (string.IsNullOrWhiteSpace(raw))
|
||||
raw = service.Configuration[$"{NetDiskQuotaSection}:{SecurityUserTypePolicy.UNAUTHENTICATED_USERS}"];
|
||||
return ParseSizeToKB(raw);
|
||||
}
|
||||
|
||||
/// <summary>解析 "2G"/"100G"/"500G"/"1T"/"512M"/"2048K"(大小写兼容,缺省按 KB)为 KB。</summary>
|
||||
private static long ParseSizeToKB(string raw)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(raw)) return 0;
|
||||
raw = raw.Trim().ToUpperInvariant();
|
||||
long unit = 1; // KB
|
||||
if (raw.EndsWith("T")) { unit = 1024L * 1024 * 1024; raw = raw.Substring(0, raw.Length - 1); }
|
||||
else if (raw.EndsWith("G")) { unit = 1024L * 1024; raw = raw.Substring(0, raw.Length - 1); }
|
||||
else if (raw.EndsWith("M")) { unit = 1024L; raw = raw.Substring(0, raw.Length - 1); }
|
||||
else if (raw.EndsWith("K")) { unit = 1; raw = raw.Substring(0, raw.Length - 1); }
|
||||
return long.TryParse(raw.Trim(), out var n) && n > 0 ? n * unit : 0;
|
||||
}
|
||||
|
||||
// 身份证 OCR 识别服务(server-to-server 调用,地址来自 appsettings.json,避免写死)
|
||||
public const string IdCardOcrApiUrl = "IdCardOcr:ApiUrl";
|
||||
public const string IdCardOcrApiKey = "IdCardOcr:ApiKey";
|
||||
|
||||
Reference in new issue
Block a user