Пример #1
0
        private void ConfigureCopy()
        {
            var router = Environment.Host.RouteBuilder;
            var hal    = Environment.Hal;

            router.MapWebApiRoute(Defines.CopyResource.Guid, $"{Defines.COPY_PATH}/{{id?}}", new { controller = "copy" });

            // Self
            hal.ProvideLink(Defines.CopyResource.Guid, "self", copy => new { href = MoveHelper.GetLocation(copy.id, true) });

            hal.ProvideLink(Defines.FilesResource.Guid, Defines.CopyResource.Name, file => new { href = $"/{Defines.COPY_PATH}" });
        }
Пример #2
0
        private void ConfigureMove()
        {
            var router = Environment.Host.RouteBuilder;
            var hal    = Environment.Hal;

            router.MapWebApiRoute(Defines.MoveResource.Guid, $"{Defines.MOVE_PATH}/{{id?}}", new { controller = "move" });

            // Self
            hal.ProvideLink(Defines.MoveResource.Guid, "self", move => new { href = MoveHelper.GetLocation(move.id, false) });

            hal.ProvideLink(Defines.FilesResource.Guid, Defines.MoveResource.Name, file => new { href = $"/{Defines.MOVE_PATH}" });
        }
Пример #3
0
        public object Post([FromBody] dynamic model)
        {
            string   name;
            FileType fileType;
            FileId   fileId, parentId;

            _helper.EnsurePostModelValid(model, out name, out fileId, out parentId);

            try {
                fileType = FilesHelper.GetFileType(fileId.PhysicalPath);
            }
            catch (FileNotFoundException) {
                throw new NotFoundException("file");
            }

            if (!_fileService.DirectoryExists(parentId.PhysicalPath))
            {
                throw new NotFoundException("parent");
            }

            var src = fileType == FileType.File ? _fileService.GetFile(fileId.PhysicalPath) : _fileService.GetDirectory(fileId.PhysicalPath);

            string destPath = Path.Combine(parentId.PhysicalPath, name == null ? src.Name : name);

            if (PathUtil.IsAncestor(src.Path, destPath) || src.Path.Equals(destPath, StringComparison.OrdinalIgnoreCase))
            {
                throw new ApiArgumentException("parent", "The destination folder is a subfolder of the source");
            }

            if (fileType == FileType.File && _fileService.DirectoryExists(destPath) || fileType == FileType.Directory && _fileService.FileExists(destPath))
            {
                throw new AlreadyExistsException("name");
            }

            MoveOperation copy = InitiateCopy(src, destPath);

            Context.Response.StatusCode = (int)HttpStatusCode.Accepted;
            Context.Response.Headers.Add("Location", MoveHelper.GetLocation(copy.Id, true));

            return(_helper.ToJsonModel(copy));
        }
Пример #4
0
        public object Post([FromBody] dynamic model)
        {
            string    name;
            IFileInfo src;
            FileId    fileId, parentId;

            _helper.EnsurePostModelValid(model, out name, out fileId, out parentId);
            src = new FilesHelper(_fileService).GetExistingFileInfo(fileId.PhysicalPath);

            if (src == null)
            {
                throw new NotFoundException("file");
            }

            if (!_fileService.GetDirectory(parentId.PhysicalPath).Exists)
            {
                throw new NotFoundException("parent");
            }

            string destPath = Path.Combine(parentId.PhysicalPath, name == null ? src.Name : name);

            if (PathUtil.IsAncestor(src.Path, destPath) || src.Path.Equals(destPath, StringComparison.OrdinalIgnoreCase))
            {
                throw new ApiArgumentException("parent", "The destination folder is a subfolder of the source");
            }

            if (src.Type == FileType.File && _fileService.GetDirectory(destPath).Exists || src.Type == FileType.Directory && _fileService.GetFile(destPath).Exists)
            {
                throw new AlreadyExistsException("name");
            }

            MoveOperation move = InitiateMove(src, destPath);

            Context.Response.StatusCode = (int)HttpStatusCode.Accepted;
            Context.Response.Headers.Add("Location", MoveHelper.GetLocation(move.Id, false));

            return(_helper.ToJsonModel(move));
        }
Пример #5
0
 public CopyController(IFileProvider fileProvider)
 {
     _fileService = fileProvider;
     _helper      = new MoveHelper(_fileService);
 }