Example #1
0
        public object Head()
        {
            Site   site;
            FileId parentId;
            string nameFilter, pathFilter, physicalPath;

            Parse(out parentId, out site, out nameFilter, out pathFilter);

            if (pathFilter != null)
            {
                return(GetByPath(pathFilter == string.Empty ? "/" : pathFilter));
            }

            if (parentId == null || site == null)
            {
                return(NotFound());
            }

            physicalPath = FilesHelper.GetPhysicalPath(site, parentId.Path);
            IFileInfo directory = _fileProvider.GetDirectory(physicalPath);

            if (!directory.Exists)
            {
                return(NotFound());
            }

            var children = GetChildren(site, parentId.Path, directory, nameFilter, false);

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(children.Count());
            this.Context.Response.Headers[HeaderNames.AcceptRanges] = _units;

            return(Ok());
        }
Example #2
0
        public object Get(string id)
        {
            FileId fileId = new FileId(id);
            Site   site   = SiteHelper.GetSite(fileId.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var physicalPath = FilesHelper.GetPhysicalPath(site, fileId.Path);

            if (!_fileProvider.GetFile(physicalPath).Exists&& !_fileProvider.GetDirectory(physicalPath).Exists)
            {
                return(NotFound());
            }

            var fields = Context.Request.GetFields();

            return(_filesHelper.ToJsonModel(site, fileId.Path, fields));
        }
Example #3
0
        private object GetByPath(string path)
        {
            Site site = SiteHelper.ResolveSite();

            if (site == null)
            {
                return(NotFound());
            }

            FileId fileId = new FileId(site.Id, path);

            string physicalPath = FilesHelper.GetPhysicalPath(site, fileId.Path);

            var fields = Context.Request.GetFields();

            if (!_fileProvider.GetFile(physicalPath).Exists&& !_fileProvider.GetDirectory(physicalPath).Exists)
            {
                throw new NotFoundException("path");
            }

            return(_filesHelper.ToJsonModel(site, fileId.Path, fields));
        }
        public object Get()
        {
            Site   site;
            FileId parentId;
            string nameFilter, pathFilter, physicalPath;

            Parse(out parentId, out site, out nameFilter, out pathFilter);

            if (pathFilter != null)
            {
                return(GetByPath(pathFilter == string.Empty ? "/" : pathFilter));
            }

            if (parentId == null || site == null)
            {
                return(NotFound());
            }

            physicalPath = FilesHelper.GetPhysicalPath(site, parentId.Path);

            if (!_fileProvider.DirectoryExists(physicalPath))
            {
                return(NotFound());
            }

            var fields   = Context.Request.GetFields();
            var dirInfo  = _fileProvider.GetDirectory(physicalPath);
            var children = GetChildren(site, parentId.Path, dirInfo, nameFilter, true, fields);

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(children.Count());
            this.Context.Response.Headers[HeaderNames.AcceptRanges] = _units;

            return(new
            {
                files = children
            });
        }