예제 #1
0
        public IDirectoryContents GetDirectoryContents(string subpath)
        {
            string url     = $"{_baseAddress}/{subpath.TrimStart('/')}?dir-meta";
            string content = _httpClient.GetStringAsync(url).Result;
            HttpDirectoryContentDescriptor descriptor = JsonConvert.DeserializeObject <HttpDirectoryContentDescriptor>(content);

            return(new HttpDirectoryContents(descriptor, _httpClient));
        }
예제 #2
0
        public async Task InvokeAsync(HttpContext httpcontext)
        {
            if (httpcontext.Request.Query.ContainsKey("dir-meta"))
            {
                var dirContent  = _fileProvider.GetDirectoryContents(httpcontext.Request.Path);
                var dirDiriptor = new HttpDirectoryContentDescriptor(dirContent, CreatePhysicalPathResolver(httpcontext, true));
                await httpcontext.Response.WriteAsync(JsonConvert.SerializeObject(dirDiriptor));
            }

            else if (httpcontext.Request.Query.ContainsKey("file-meta"))
            {
                var fileInfo       = _fileProvider.GetFileInfo(httpcontext.Request.Path);
                var fileDescriptor = new HttpFileDescriptor(fileInfo, CreatePhysicalPathResolver(httpcontext, false));
                await httpcontext.Response.WriteAsync(JsonConvert.SerializeObject(fileDescriptor));
            }
            else
            {
                await httpcontext.Response.SendFileAsync(_fileProvider.GetFileInfo(httpcontext.Request.Path));
            }
        }
 public HttpDirectoryContents(HttpDirectoryContentDescriptor descriptor,
                              HttpClient httpClient)
 {
     this.Exists     = descriptor.Exists;
     this._fileInfos = descriptor.FileDescriptors.Select(file => file.ToFileInfo(httpClient));
 }