private async Task <AssetFile> CheckAssetFileAsync(IReadOnlyList <IFormFile> file) { if (file.Count != 1) { var error = new ValidationError($"Can only upload one file, found {file.Count} files."); throw new ValidationException("Cannot create asset.", error); } var formFile = file[0]; if (formFile.Length > assetOptions.MaxSize) { var error = new ValidationError($"File cannot be bigger than {assetOptions.MaxSize.ToReadableSize()}."); throw new ValidationException("Cannot create asset.", error); } var plan = appPlansProvider.GetPlanForApp(App); var currentSize = await assetStatsRepository.GetTotalSizeAsync(AppId); if (plan.MaxAssetSize > 0 && plan.MaxAssetSize < currentSize + formFile.Length) { var error = new ValidationError("You have reached your max asset size."); throw new ValidationException("Cannot create asset.", error); } var assetFile = new AssetFile(formFile.FileName, formFile.ContentType, formFile.Length, formFile.OpenReadStream); return(assetFile); }
public async Task <IActionResult> GetCurrentStorageSize(string app) { var size = await assetStatsRepository.GetTotalSizeAsync(AppId); var plan = appPlanProvider.GetPlanForApp(App); var response = new CurrentStorageDto { Size = size, MaxAllowed = plan.MaxAssetSize }; return(Ok(response)); }
private async Task <AssetFile> CheckAssetFileAsync(IFormFile?file) { if (file == null || Request.Form.Files.Count != 1) { var error = T.Get("validation.onlyOneFile"); throw new ValidationException(error); } var(plan, _) = appPlansProvider.GetPlanForApp(App); var currentSize = await assetStatsRepository.GetTotalSizeAsync(AppId); if (plan.MaxAssetSize > 0 && plan.MaxAssetSize < currentSize + file.Length) { var error = new ValidationError(T.Get("assets.maxSizeReached")); throw new ValidationException(error); } return(file.ToAssetFile()); }
private async Task <AssetFile> CheckAssetFileAsync(IFormFile?file) { if (file == null || Request.Form.Files.Count != 1) { var error = new ValidationError($"Can only upload one file, found {Request.Form.Files.Count} files."); throw new ValidationException("Cannot create asset.", error); } var plan = appPlansProvider.GetPlanForApp(App); var currentSize = await assetStatsRepository.GetTotalSizeAsync(AppId); if (plan.MaxAssetSize > 0 && plan.MaxAssetSize < currentSize + file.Length) { var error = new ValidationError("You have reached your max asset size."); throw new ValidationException("Cannot create asset.", error); } return(file.ToAssetFile()); }