Esempio n. 1
0
        public IActionResult Refresh([FromForm] FsExplorerDTO dto)
        {
            var directory = Path.Combine(GetRootDirectory(dto.RootDirectory), dto.Folder);

            if (!Directory.Exists(directory))
            {
                BadRequest(dto);
            }

            return(Ok(new FsExplorerFolder(directory).Elements));
        }
Esempio n. 2
0
        public IActionResult Delete([FromForm] FsExplorerDTO dto)
        {
            var selectFilePath = Path.Combine(GetRootDirectory(dto.RootDirectory), dto.Folder, dto.Selected);

            if (System.IO.File.Exists(selectFilePath))
            {
                return(BadRequest("Arquivo não existe:" + dto.Selected));
            }

            System.IO.File.Delete(selectFilePath);

            return(Ok(new { message = "Arquivo deletado com sucesso" }));
        }
Esempio n. 3
0
        public IActionResult Copy([FromBody] FsExplorerDTO dto)
        {
            var selectFilePath   = Path.Combine(GetRootDirectory(dto.RootDirectory), dto.Folder, dto.Selected);
            var copyToToFilePath = Path.Combine(GetRootDirectory(dto.RootDirectory), dto.CopyTo, dto.Selected);

            if (!Directory.Exists(selectFilePath))
            {
                return(BadRequest("Diretório de origem não encontrado."));
            }
            if (System.IO.File.Exists(copyToToFilePath))
            {
                return(BadRequest("Já existe um arquivo com esse nome."));
            }

            System.IO.File.Copy(selectFilePath, copyToToFilePath);
            return(Ok());
        }
Esempio n. 4
0
        public async Task <IActionResult> Upload([FromForm] FsExplorerDTO dto)
        {
            try{
                var size = dto.Files.Sum(f => f.Length);
                if (size == 0)
                {
                    return(BadRequest());
                }

                var directory = Path.Combine(GetRootDirectory(dto.RootDirectory), dto.Folder);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                foreach (var file in dto.Files)
                {
                    if (!(file?.Length > 0))
                    {
                        continue;
                    }
                    var index    = 0;
                    var filePath = $"{Path.Combine(directory, dto.FileName)}-{index}{GetExtension(file).ToLower()}";
                    do
                    {
                        index++;
                        filePath = $"{Path.Combine(directory, dto.FileName)}-{index}{GetExtension(file).ToLower()}";
                        Trace.WriteLine(filePath);
                    } while (System.IO.File.Exists(filePath));

                    using (var stream = new FileStream(path: filePath, mode: FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }
                }

                return(Ok());
            } catch (Exception e) {
                Trace.WriteLine(e);
                return(BadRequest());
            }
        }