Example #1
0
        public override Response NodeAction(IRequest request, Node node, string action)
        {
            var urlNode = node as URLNode;
            if (urlNode == null)
                throw new InvalidOperationException("Node is not an URLNode");

            if (action.Equals("download"))
            {
                using (var info = new UrlInfoParser(urlNode.URL))
                {
                    var dir = Path.Combine(Settings.Default.FileStorage, request.User.Username);
                    Directory.CreateDirectory(dir);
                    var path = Path.Combine(dir, info.FileName);
                    info.SaveContent(path);
                    var fileNode = new FileNode(path);
                    request.UnitOfWork.Files.Save(fileNode);
                    Utilities.CreateLinkForNode(request, urlNode, fileNode, "Downloaded");
                }
                return new RedirectResponse("/url/" + urlNode.Id);
            }

            return base.NodeAction(request, node, action);
        }
Example #2
0
 public static string GetKnownExtension(FileNode node)
 {
     var ext = Path.GetExtension(node.Path);
     return KnownExtensions.Contains(ext) ? ext?.Substring(1) : null;
 }