Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions FileSystemCommon/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using FileSystemCommon.Models.FileSystem;
using FileSystemCommon.Models.Configuration;
using System.Threading.Tasks;
using System.Reflection;

namespace FileSystemCommon
{
Expand Down Expand Up @@ -133,6 +134,11 @@ public static string GetContentType(string extension)
return "application/octet-stream";
}

public static string GetFileType(string extension)
{
return GetContentType(extension).Split('/')[0];
}

public static string GetNamePath(this IEnumerable<PathPart> parts, char separator)
{
return parts != null ? string.Join(separator.ToString(), parts.Select(p => p.Name)) : string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default function ({path, theme, onFileInfoLoaded, hideOpenFileLinkAction,
}

return (
<div className="text-center'">
<div className="text-center">
<h3 className={`font-italic file-viewer-info-text ${theme}`}>
No preview for this file available
</h3>
Expand Down
73 changes: 73 additions & 0 deletions FileSystemWeb/Controllers/API/BigFileController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using FileSystemCommon;
using FileSystemWeb.Data;
using FileSystemWeb.Exceptions;
using FileSystemWeb.Extensions.Http;
using FileSystemWeb.Helpers;
using FileSystemWeb.Models;
using FileSystemWeb.Models.RequestBodies;
using FileSystemWeb.Services.File;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.IO;
using System.Security.Claims;
using System.Threading.Tasks;

namespace FileSystemWeb.Controllers.API
{
[Route("api/[controller]")]
[Authorize]
public class BigFileController : Controller
{
private readonly BigFileService bigFileService;

public BigFileController(BigFileService bigFileService)
{
this.bigFileService = bigFileService;
}

[HttpPost("start")]
[HttpPost("{encodedVirtualPath}/start")]
public async Task<ActionResult<string>> StartUpload(string encodedVirtualPath, [FromQuery] string path)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
Guid uuid = await bigFileService.StartUpload(userId, virtualPath);

return uuid.ToString();
}


[HttpPost("{uuid}/append")]
public async Task<ActionResult> AppendUpload(Guid uuid, [FromForm] AppendBigFileBody form)
{
if (form.PartialFile == null) return BadRequest("No data or file");

string userId = HttpContext.GetUserId();
await bigFileService.AppendUpload(userId, uuid, form.PartialFile);

return Ok();
}


[HttpPut("{uuid}/finish")]
public async Task<ActionResult> FinishUpload(Guid uuid)
{
string userId = HttpContext.GetUserId();
await bigFileService.FinishUpload(userId, uuid);

return Ok();
}


[HttpDelete("{uuid}")]
public async Task<ActionResult> CancelUpload(Guid uuid)
{
string userId = HttpContext.GetUserId();
await bigFileService.CancelUpload(userId, uuid);

return Ok();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using FileSystemWeb.Helpers;
using Microsoft.AspNetCore.Mvc;

namespace FileSystemWeb.Controllers
namespace FileSystemWeb.Controllers.API
{
[Route("api/[controller]")]
public class ConfigController : ControllerBase
Expand Down
129 changes: 129 additions & 0 deletions FileSystemWeb/Controllers/API/FilesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using System.IO;
using System.Security.Claims;
using System.Threading.Tasks;
using FileSystemCommon;
using FileSystemCommon.Models.FileSystem.Files;
using FileSystemWeb.Extensions.Http;
using FileSystemWeb.Helpers;
using FileSystemWeb.Models;
using FileSystemWeb.Models.RequestBodies;
using FileSystemWeb.Services.File;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;

namespace FileSystemWeb.Controllers.API
{
[Route("api/[controller]")]
public class FilesController : ControllerBase
{
private readonly FileService fileService;

public FilesController(FileService fileService)
{
this.fileService = fileService;
}

[HttpGet("")]
[HttpGet("{encodedVirtualPath}")]
public async Task<ActionResult> Get(string encodedVirtualPath, [FromQuery] string path)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
InternalFile file = await fileService.Get(userId, virtualPath);

string fileName = Utils.ReplaceNonAscii(file.Name);
Response.Headers.Add(HeaderNames.ContentDisposition, $"inline; filename=\"{fileName}\"");
string contentType = Utils.GetContentType(Path.GetExtension(file.Name));
return PhysicalFile(file.PhysicalPath, contentType, true);
}

[HttpGet("download")]
[HttpGet("{encodedVirtualPath}/download")]
public async Task<ActionResult> Download(string encodedVirtualPath, [FromQuery] string path)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
InternalFile file = await fileService.Get(userId, virtualPath);

string contentType = Utils.GetContentType(Path.GetExtension(file.Name));
return PhysicalFile(file.PhysicalPath, contentType, file.Name);
}

[HttpGet("exists")]
[HttpGet("{encodedVirtualPath}/exists")]
public async Task<ActionResult<bool>> Exists(string encodedVirtualPath, [FromQuery] string path)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
return await fileService.Exists(userId, virtualPath);
}

[HttpGet("info")]
[HttpGet("{encodedVirtualPath}/info")]
public async Task<ActionResult<FileItemInfo>> GetInfo(string encodedVirtualPath, [FromQuery] string path)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
return await fileService.GetInfo(userId, virtualPath);
}

[HttpGet("hash")]
[HttpGet("{encodedVirtualPath}/hash")]
public async Task<ActionResult<string>> GetHash(string encodedVirtualPath, [FromQuery] string path, [FromQuery] int partialSize)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
return await fileService.GetHash(userId, virtualPath, partialSize);
}

[HttpPost("copy")]
[HttpPost("{encodedVirtualSrcPath}/{encodedVirtualDestPath}/copy")]
public async Task<ActionResult> Copy(string encodedVirtualSrcPath, string encodedVirtualDestPath, [FromQuery] string srcPath, [FromQuery] string destPath)
{
string userId = HttpContext.GetUserId();
string virtualSrcPath = PathHelper.DecodeAndValidatePath(encodedVirtualSrcPath ?? srcPath);
string virtualDestPath = PathHelper.DecodeAndValidatePath(encodedVirtualDestPath ?? destPath);
await fileService.Copy(userId, virtualSrcPath, virtualDestPath);

return Ok();
}

[HttpPost("move")]
[HttpPost("{encodedVirtualSrcPath}/{encodedVirtualDestPath}/move")]
public async Task<ActionResult> Move(string encodedVirtualSrcPath, string encodedVirtualDestPath, [FromQuery] string srcPath, [FromQuery] string destPath)
{
string userId = HttpContext.GetUserId();
string virtualSrcPath = PathHelper.DecodeAndValidatePath(encodedVirtualSrcPath ?? srcPath);
string virtualDestPath = PathHelper.DecodeAndValidatePath(encodedVirtualDestPath ?? destPath);
await fileService.Move(userId, virtualSrcPath, virtualDestPath);

return Ok();
}

[DisableRequestSizeLimit]
[HttpPost]
[HttpPost("{encodedVirtualPath}")]
public async Task<ActionResult> Write(string encodedVirtualPath, [FromQuery] string path, [FromForm] WriteFileBody form)
{
if (form?.FileContent == null) return BadRequest("Missing file content");

string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
await fileService.Write(userId, virtualPath, form.FileContent);

return Ok();
}

[HttpDelete("")]
[HttpDelete("{encodedVirtualPath}")]
public async Task<ActionResult> Delete(string encodedVirtualPath, [FromQuery] string path)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
await fileService.Delete(userId, virtualPath);

return Ok();
}
}
}
80 changes: 80 additions & 0 deletions FileSystemWeb/Controllers/API/FoldersController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Security.Claims;
using System.Threading.Tasks;
using FileSystemCommon.Models.FileSystem.Content;
using FileSystemCommon.Models.FileSystem.Folders;
using FileSystemWeb.Extensions.Http;
using FileSystemWeb.Helpers;
using FileSystemWeb.Services.Folder;
using Microsoft.AspNetCore.Mvc;

namespace FileSystemWeb.Controllers.API
{
[Route("api/[controller]")]
public class FoldersController : ControllerBase
{
private readonly FolderService folderService;

public FoldersController(FolderService folderService)
{
this.folderService = folderService;
}

[HttpGet("exists")]
[HttpGet("{encodedVirtualPath}/exists")]
public async Task<ActionResult<bool>> Exists(string encodedVirtualPath, [FromQuery] string path)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
return await folderService.Exists(userId, virtualPath);
}

[HttpGet("content")]
[HttpGet("content/{encodedVirtualPath}")]
public async Task<ActionResult<FolderContent>> ListFolders(string encodedVirtualPath, [FromQuery] string path,
[FromQuery] FileSystemItemSortType sortType = FileSystemItemSortType.Name,
[FromQuery] FileSystemItemSortDirection sortDirection = FileSystemItemSortDirection.ASC)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
return await folderService.GetContent(userId, virtualPath, sortType, sortDirection);
}

[HttpGet("info")]
[HttpGet("{encodedVirtualPath}/info")]
public async Task<ActionResult<FolderItemInfo>> GetInfo(string encodedVirtualPath, [FromQuery] string path)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
return await folderService.GetInfo(userId, virtualPath);
}

[HttpGet("infoWithSize")]
[HttpGet("{encodedVirtualPath}/infoWithSize")]
public async Task<ActionResult<FolderItemInfoWithSize>> GetInfoWithSize(string encodedVirtualPath, [FromQuery] string path)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
return await folderService.GetInfoWithSize(userId, virtualPath);
}

[HttpPost("")]
[HttpPost("{encodedVirtualPath}")]
public async Task<ActionResult<FolderItemInfo>> Create(string encodedVirtualPath, [FromQuery] string path)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
return await folderService.Create(userId, virtualPath);
}

[HttpDelete("")]
[HttpDelete("{encodedVirtualPath}")]
public async Task<ActionResult> Delete(string encodedVirtualPath, [FromQuery] string path, [FromQuery] bool recursive)
{
string userId = HttpContext.GetUserId();
string virtualPath = PathHelper.DecodeAndValidatePath(encodedVirtualPath ?? path);
await folderService.Delete(userId, virtualPath, recursive);

return Ok();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace FileSystemWeb.Controllers
namespace FileSystemWeb.Controllers.API
{
[Route("api/[controller]")]
public class PingController : ControllerBase
Expand Down
Loading