public Stream GetVideoByPath(string path) { var extension = Path.GetExtension(path); var outStream = extension switch { ".mp4" => _fileDownloader.AsStreamAsync(path), ".mp3" => _fileDownloader.AsStreamAsync(path), ".m4a" => _fileDownloader.AsStreamAsync(path), _ => null }; return(outStream); } }
public ActionResult PermanentDownload(string id) { if (!string.IsNullOrEmpty(id)) { StorageIndexRecord?s = null; try { s = _storageIndexContext.IndexStorage.SingleOrDefault(record => record.Urlhash.Equals(id)); if (s != null) { if (!s.Expires || (s.ExpireDate != DateTime.Now && s.ExpireDate > DateTime.Now)) { var fileBytes = _fileService.AsStreamAsync(s.AbsolutePath); var name = Path.GetFileName(s.AbsolutePath); if (fileBytes != null) { return(File(fileBytes, MimeAssistant.GetMimeType(name), name, true)); } ReturnMessage = "Couldn't read requested resource: " + s.Urlid; Log.Warning(ReturnMessage); return(RedirectToAction(nameof(Browse))); } ReturnMessage = "It seems that this url expired, you need to generate a new one."; return(RedirectToAction(nameof(Browse))); } ReturnMessage = "It seems that given token doesn't exist in the database."; return(RedirectToAction(nameof(Browse))); } catch (InvalidOperationException ex) { ReturnMessage = s != null ? "Couldn't read requested resource: " + s.Urlid : "Database error occured."; Log.Error(ex, string.Concat(ReturnMessage, "StorageController#PermanentDownload")); return(RedirectToAction(nameof(Browse))); } } ReturnMessage = "No id given or database is down."; return(RedirectToAction(nameof(Browse))); }