/// <summary> /// 创建存储库 /// </summary> /// <param name="bucket"></param> /// <returns></returns> public async Task <Bucket430> CreateAsync(string bucketName, string note) { if (!await CanCreateAsync()) { throw new Abp.UI.UserFriendlyException("存储库已达到上限,不能再创建。"); } bucketName = SettingManager.GetSettingValue(AppSettingNames.OSS.BucketPrefix) + bucketName; if (await _bucketRepository.GetAll().AnyAsync(x => x.Name == bucketName)) { throw new Abp.UI.UserFriendlyException("存储库已存在。"); } var bucket = new Bucket430() { Name = bucketName, Note = note }; await _bucketRepository.InsertAndGetIdAsync(bucket); try { Client.CreateBucket(bucket.Name, bucket.StorageClass); } catch (Exception) { throw new Abp.UI.UserFriendlyException($"创建存储库失败,存储库名称{bucket.Name}无效。 ", "存储库命名规则:\r\n 只能包含小写字母、数字或短划线( - ); \r\n 以小写字母或数字开头和结尾; \r\n 长度必须介于3到63之间 "); } ApplySettingToBucket(bucket); return(bucket); }
private void UpdateBucketSetting(Bucket430 bucket) { Client.SetBucketAcl(bucket.Name, bucket.CannedAccessControl); var bucketCorsRequest = bucket.ToCORSRules(); var bucketRefererRequest = new SetBucketRefererRequest(bucket.Name, bucket.RefererList, bucket.AllowEmptyReferer); Client.SetBucketCors(bucketCorsRequest); Client.SetBucketReferer(bucketRefererRequest); }
private void ApplySettingToBucket(Bucket430 bucket) { var allowedOrigins = SettingManager.GetSettingValue(AppSettingNames.OSS.AllowedOrigins); var allowedMethods = SettingManager.GetSettingValue(AppSettingNames.OSS.AllowedMethods); var allowedHeaders = SettingManager.GetSettingValue(AppSettingNames.OSS.AllowedHeaders); var exposedHeaders = SettingManager.GetSettingValue(AppSettingNames.OSS.ExposedHeaders); var maxAgeSeconds = SettingManager.GetSettingValue <int>(AppSettingNames.OSS.MaxAgeSeconds); var allowEmptyReferer = SettingManager.GetSettingValue <bool>(AppSettingNames.OSS.AllowEmptyReferer); var referer = SettingManager.GetSettingValue(AppSettingNames.OSS.Referer); bucket._AllowedOrigins = allowedOrigins; bucket._AllowedMethods = allowedMethods; bucket._AllowedHeaders = allowedHeaders; bucket._ExposedHeaders = exposedHeaders; bucket.MaxAgeSeconds = maxAgeSeconds; bucket.AllowEmptyReferer = allowEmptyReferer; bucket._RefererList = referer; UpdateBucketSetting(bucket); }