121 lines
5.5 KiB
C#
121 lines
5.5 KiB
C#
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace CloudBuilder.Security.Policy
|
|
{
|
|
public class ServiceSettingsPolicy
|
|
{
|
|
public const string PhysicalFileDirectory = "FileServiceSettings:PhysicalFileDirectory";
|
|
public const string ScaleFileDirectory = "FileServiceSettings:ScaleFileDirectory";
|
|
public const string BackupFileDirectory = "FileServiceSettings:BackupFileDirectory";
|
|
public const string UploadFileDirectory = "FileServiceSettings:UploadFileDirectory";
|
|
|
|
public const string DmsFileDirectory = "FileServiceSettings:DmsFileDirectory";
|
|
|
|
public const string RequestPath = "FileServiceSettings:RequestPath";
|
|
public const string ExcelOutputDirectory = "FileServiceSettings:ExcelOutputDirectory";
|
|
|
|
public const string FfmpegPath = "Ffmpeg:Path";
|
|
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";
|
|
public const string IdCardOcrSide = "IdCardOcr:Side";
|
|
public const string IdCardOcrTimeoutSeconds = "IdCardOcr:TimeoutSeconds";
|
|
|
|
public static string GetIdCardOcrApiUrl(IApplicationService service)
|
|
{
|
|
return service.Configuration[IdCardOcrApiUrl];
|
|
}
|
|
|
|
// OCR 服务已启用 Bearer Token 鉴权(API_TOKENS 中 win-service 专用 Token),未配置时返回空串表示不带认证头
|
|
public static string GetIdCardOcrApiKey(IApplicationService service)
|
|
{
|
|
return service.Configuration[IdCardOcrApiKey];
|
|
}
|
|
|
|
public static string GetIdCardOcrSide(IApplicationService service)
|
|
{
|
|
var side = service.Configuration[IdCardOcrSide];
|
|
return string.IsNullOrWhiteSpace(side) ? "auto" : side;
|
|
}
|
|
|
|
public static int GetIdCardOcrTimeoutSeconds(IApplicationService service)
|
|
{
|
|
var raw = service.Configuration[IdCardOcrTimeoutSeconds];
|
|
return int.TryParse(raw, out var seconds) && seconds > 0 ? seconds : 30;
|
|
}
|
|
|
|
public static string GetPhysicalFileDirectory(IApplicationService service)
|
|
{
|
|
return service.Configuration[PhysicalFileDirectory];
|
|
}
|
|
public static string GetUploadFileDirectory(IApplicationService service)
|
|
{
|
|
return service.Configuration[UploadFileDirectory];
|
|
}
|
|
|
|
public static string GetBackupFileDirectory(IApplicationService service)
|
|
{
|
|
return service.Configuration[BackupFileDirectory];
|
|
}
|
|
|
|
public static string GetScaleFileDirectory(IApplicationService service)
|
|
{
|
|
return service.Configuration[ScaleFileDirectory];
|
|
}
|
|
|
|
public static string GetDmsFileScaleDirectory(IApplicationService service)
|
|
{
|
|
return Path.Combine(service.Configuration[ScaleFileDirectory], service.Configuration[DmsFileDirectory]);
|
|
}
|
|
|
|
public static string GetDmsFileBackupDirectory(IApplicationService service)
|
|
{
|
|
return Path.Combine(service.Configuration[BackupFileDirectory], service.Configuration[DmsFileDirectory]);
|
|
}
|
|
|
|
public static string GetDmsFileUploadDirectory(IApplicationService service)
|
|
{
|
|
return Path.Combine(service.Configuration[UploadFileDirectory], service.Configuration[DmsFileDirectory]);
|
|
}
|
|
}
|
|
}
|