Exemple #1
0
        public void Move(
            [FromQuery] string from,
            [FromQuery] string to)
        {
            if (string.IsNullOrWhiteSpace(from))
            {
                from = "";
            }
            if (string.IsNullOrWhiteSpace(to))
            {
                to = "";
            }

            var rootDirectory = DirectoryEntity.FromPath(Startup.Configuration[Startup.RootDirectory]);

            string fromFullPath = System.IO.Path.Combine(Startup.Configuration[Startup.RootDirectory], from);
            string toFullPath   = System.IO.Path.Combine(Startup.Configuration[Startup.RootDirectory], to);

            // get the file attributes for file or directory
            FileAttributes fromAttr = System.IO.File.GetAttributes(fromFullPath);

            if (fromAttr == FileAttributes.Directory)
            {
                DirectoryEntity.FromPath(fromFullPath).Move(toFullPath);
            }
            else
            {
                FileEntity.FromPath(fromFullPath).Move(toFullPath);
            }
        }
Exemple #2
0
        public void Delete([FromBody] IEnumerable <string> paths)
        {
            foreach (var path in paths)
            {
                if (string.IsNullOrWhiteSpace(path))
                {
                    continue; // 根目錄禁止刪除
                }

                string fullPath = System.IO.Path.Combine(Startup.Configuration[Startup.RootDirectory], path);

                FileAttributes attr = System.IO.File.GetAttributes(fullPath);

                if (attr == FileAttributes.Directory)
                {
                    DirectoryEntity.FromPath(fullPath).Delete();
                }
                else
                {
                    FileEntity.FromPath(fullPath).Delete();
                }
            }
        }
Exemple #3
0
        public IActionResult Download(
            [FromQuery] string path,
            [FromQuery] string token)
        {
            DriveToken tokenInfo = VerifyToken(token);

            if (tokenInfo.Payload.Actor != tokenInfo.Payload.Name &&
                tokenInfo.Payload.Actor != path)
            {
                throw new PermissionsException();
            }

            string fullPath = System.IO.Path.Combine(Startup.Configuration[Startup.RootDirectory], path);

            var fileEntity = FileEntity.FromPath(fullPath);

            var file = fileEntity.FileInfo.Open(
                System.IO.FileMode.Open,
                System.IO.FileAccess.Read,
                System.IO.FileShare.Read);

            return(File(file, fileEntity.ContentType, System.IO.Path.GetFileName(path), true));
        }