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 > assetsConfig.MaxSize) { var error = new ValidationError($"File size cannot be longer than {assetsConfig.MaxSize.ToReadableSize()}."); throw new ValidationException("Cannot create asset.", error); } var plan = appPlanProvider.GetPlanForApp(App); var currentSize = await assetStatsRepository.GetTotalSizeAsync(App.Id); 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(App.Id); var plan = appPlanProvider.GetPlanForApp(App); return(Ok(new CurrentStorageDto { Size = size, MaxAllowed = plan.MaxAssetSize })); }