using Microsoft.Extensions.Options; namespace DramaLing.Api.Models.Configuration; public class GoogleCloudStorageOptions { public const string SectionName = "GoogleCloudStorage"; /// /// Google Cloud 專案 ID /// public string ProjectId { get; set; } = string.Empty; /// /// Storage Bucket 名稱 /// public string BucketName { get; set; } = string.Empty; /// /// Service Account JSON 金鑰檔案路徑 /// public string CredentialsPath { get; set; } = string.Empty; /// /// Service Account JSON 金鑰內容 (用於環境變數) /// public string CredentialsJson { get; set; } = string.Empty; /// /// 自訂域名 (用於 CDN) /// public string CustomDomain { get; set; } = string.Empty; /// /// 是否使用自訂域名 /// public bool UseCustomDomain { get; set; } = false; /// /// 圖片路徑前綴 /// public string PathPrefix { get; set; } = "examples"; /// /// 傳統 API Key (如果使用) /// public string ApiKey { get; set; } = string.Empty; } public class GoogleCloudStorageOptionsValidator : IValidateOptions { public ValidateOptionsResult Validate(string? name, GoogleCloudStorageOptions options) { var failures = new List(); if (string.IsNullOrEmpty(options.ProjectId)) failures.Add("GoogleCloudStorage:ProjectId is required"); if (string.IsNullOrEmpty(options.BucketName)) failures.Add("GoogleCloudStorage:BucketName is required"); // 認證方式是可選的 - 可以使用 Application Default Credentials // 不強制要求明確的認證設定 return failures.Count > 0 ? ValidateOptionsResult.Fail(failures) : ValidateOptionsResult.Success; } }