Ejemplo n.º 1
0
        public async Task <IActionResult> UploadFileAsync([FromQuery] string path)
        {
            // Assume that `path` uses forward slashes
            var forwardSlashPath = new ForwardSlashFilepath(path);
            var systemPath       = forwardSlashPath.ToSystemFilepath();

            if (!Request.Body.CanRead)
            {
                return(BadRequest());
            }

            await fileContentService.WriteFileContentsAsync(systemPath, Request.Body);

            return(CreatedAtAction(nameof(DownloadFileAsync), routeValues: new { path }, value: path));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DownloadFileAsync([FromQuery] string path)
        {
            // Assume that `path` uses forward slashes
            var forwardSlashPath = new ForwardSlashFilepath(path);
            var systemPath       = forwardSlashPath.ToSystemFilepath();

            if (!System.IO.File.Exists(systemPath.ToString()))
            {
                return(NotFound());
            }

            var stream = await fileContentService.ReadFileContentsAsync(systemPath);

            return(File(stream, MediaTypeNames.Application.Octet));
        }
Ejemplo n.º 3
0
        public IActionResult GetListing([FromQuery] string?path)
        {
            // Note: making `path` non-nullable and using a default value will cause
            // ASP.NET to require the query parameter
            path ??= ".";

            // Assume that `path` uses forward slashes
            var forwardSlashPath = new ForwardSlashFilepath(path);
            var systemPath       = forwardSlashPath.ToSystemFilepath();

            if (!Directory.Exists(systemPath.ToString()))
            {
                return(NotFound());
            }

            return(Ok(directoryListingService.GetListing(systemPath)));
        }
Ejemplo n.º 4
0
        private bool VersionsAreDifferent(ForwardSlashFilepath path)
        {
            var clientFile  = clientFiles[path];
            var serviceFile = serviceFiles[path];

            // In practice, clientFile's SHA should always be empty,
            // but it doesn't hurt to check.
            if (clientFile.Sha1 is null)
            {
                var systemPath = path.ToSystemFilepath();
                clientFile = clientFile with {
                    Sha1 = fileHasher.HashFile(systemPath).ToString()
                };
            }

            return(serviceFile.Sha1 != clientFile.Sha1);
        }
    }