/// <summary> /// Handles requests for composite files (non-named bundles) /// </summary> /// <param name="file"></param> /// <returns></returns> public async Task <FileResult> Composite( [FromServices] CompositeFileModel file) { if (!file.ParsedPath.Names.Any()) { //TODO: Throw an exception, this will result in an exception anyways return(null); } var compositeFilePath = new FileInfo(_fileSystemHelper.GetCurrentCompositeFilePath(file.CacheBuster, file.Compression, file.FileKey)); if (compositeFilePath.Exists) { //this is already processed, return it return(File(compositeFilePath.OpenRead(), file.Mime)); } //this bundle context isn't really used since this is not a bundle but just a composite file which doesn't support all of the features of a real bundle using (var bundleContext = BundleContext.CreateEmpty()) { var filePaths = file.ParsedPath.Names.Select(filePath => Path.Combine( _fileSystemHelper.CurrentCacheFolder, filePath + file.Extension)); using (var resultStream = await GetCombinedStreamAsync(filePaths, bundleContext)) { var compressedStream = await Compressor.CompressAsync(file.Compression, resultStream); await CacheCompositeFileAsync(compositeFilePath, compressedStream); return(File(compressedStream, file.Mime)); } } }
/// <summary> /// Handles requests for composite files (non-named bundles) /// </summary> /// <param name="file"></param> /// <returns></returns> public async Task <IActionResult> Composite( [FromServices] CompositeFileModel file) { if (!file.ParsedPath.Names.Any()) { return(NotFound()); } var compositeFilePath = new FileInfo(_fileSystemHelper.GetCurrentCompositeFilePath(file.CacheBuster, file.Compression, file.FileKey)); if (compositeFilePath.Exists) { //this is already processed, return it return(File(compositeFilePath.OpenRead(), file.Mime)); } using (var bundleContext = new BundleContext(file, compositeFilePath)) { var filePaths = file.ParsedPath.Names.Select(filePath => Path.Combine( _fileSystemHelper.CurrentCacheFolder, file.ParsedPath.Version, filePath + file.Extension)); using (var resultStream = await GetCombinedStreamAsync(filePaths, bundleContext)) { var compressedStream = await Compressor.CompressAsync(file.Compression, resultStream); await CacheCompositeFileAsync(compositeFilePath, compressedStream); return(File(compressedStream, file.Mime)); } } }
/// <summary> /// Handles requests for composite files /// </summary> /// <param name="s">The file key to lookup</param> /// <param name="t">The type of file</param> /// <param name="v">The version</param> /// <returns></returns> public async Task <FileResult> Composite( [FromServices] CompositeFileModel file) { if (!file.ParsedPath.Names.Any()) { //TODO: Throw an exception, this will result in an exception anyways return(null); } var filePaths = file.ParsedPath.Names.Select(filePath => Path.Combine( _fileSystemHelper.CurrentCacheFolder, filePath + file.Extension)); using (var resultStream = await GetCombinedStreamAsync(filePaths)) { var compressedStream = await Compressor.CompressAsync(file.Compression, resultStream); var compositeFilePath = await CacheCompositeFileAsync(file.FileKey, compressedStream, file.Compression); return(File(compressedStream, file.Mime)); } }