Compare commits
2 Commits
fa1a40c637
...
faa375042a
| Author | SHA1 | Date | |
|---|---|---|---|
|
faa375042a
|
|||
|
65b6f3a606
|
@@ -24,9 +24,16 @@ public class FileIndexController(
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The path to browse (defaults to root "/")</param>
|
/// <param name="path">The path to browse (defaults to root "/")</param>
|
||||||
/// <param name="query">Optional query to filter files by name</param>
|
/// <param name="query">Optional query to filter files by name</param>
|
||||||
|
/// <param name="order">The field to order by (date, size, name - defaults to date)</param>
|
||||||
|
/// <param name="orderDesc">Whether to order in descending order (defaults to true)</param>
|
||||||
/// <returns>List of files in the specified path</returns>
|
/// <returns>List of files in the specified path</returns>
|
||||||
[HttpGet("browse")]
|
[HttpGet("browse")]
|
||||||
public async Task<IActionResult> BrowseFiles([FromQuery] string path = "/", [FromQuery] string? query = null)
|
public async Task<IActionResult> BrowseFiles(
|
||||||
|
[FromQuery] string path = "/",
|
||||||
|
[FromQuery] string? query = null,
|
||||||
|
[FromQuery] string order = "date",
|
||||||
|
[FromQuery] bool orderDesc = true
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
||||||
return new ObjectResult(ApiError.Unauthorized()) { StatusCode = 401 };
|
return new ObjectResult(ApiError.Unauthorized()) { StatusCode = 401 };
|
||||||
@@ -44,6 +51,17 @@ public class FileIndexController(
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply sorting
|
||||||
|
fileIndexes = order.ToLower() switch
|
||||||
|
{
|
||||||
|
"name" => orderDesc ? fileIndexes.OrderByDescending(fi => fi.File.Name).ToList()
|
||||||
|
: fileIndexes.OrderBy(fi => fi.File.Name).ToList(),
|
||||||
|
"size" => orderDesc ? fileIndexes.OrderByDescending(fi => fi.File.Size).ToList()
|
||||||
|
: fileIndexes.OrderBy(fi => fi.File.Size).ToList(),
|
||||||
|
_ => orderDesc ? fileIndexes.OrderByDescending(fi => fi.File.CreatedAt).ToList()
|
||||||
|
: fileIndexes.OrderBy(fi => fi.File.CreatedAt).ToList()
|
||||||
|
};
|
||||||
|
|
||||||
// Get all file indexes for this account to extract child folders
|
// Get all file indexes for this account to extract child folders
|
||||||
var allFileIndexes = await fileIndexService.GetByAccountIdAsync(accountId);
|
var allFileIndexes = await fileIndexService.GetByAccountIdAsync(accountId);
|
||||||
|
|
||||||
@@ -109,9 +127,15 @@ public class FileIndexController(
|
|||||||
/// Gets all files for the current user (across all paths)
|
/// Gets all files for the current user (across all paths)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="query">Optional query to filter files by name</param>
|
/// <param name="query">Optional query to filter files by name</param>
|
||||||
|
/// <param name="order">The field to order by (date, size, name - defaults to date)</param>
|
||||||
|
/// <param name="orderDesc">Whether to order in descending order (defaults to true)</param>
|
||||||
/// <returns>List of all files for the user</returns>
|
/// <returns>List of all files for the user</returns>
|
||||||
[HttpGet("all")]
|
[HttpGet("all")]
|
||||||
public async Task<IActionResult> GetAllFiles([FromQuery] string? query = null)
|
public async Task<IActionResult> GetAllFiles(
|
||||||
|
[FromQuery] string? query = null,
|
||||||
|
[FromQuery] string order = "date",
|
||||||
|
[FromQuery] bool orderDesc = true
|
||||||
|
)
|
||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
||||||
return new ObjectResult(ApiError.Unauthorized()) { StatusCode = 401 };
|
return new ObjectResult(ApiError.Unauthorized()) { StatusCode = 401 };
|
||||||
@@ -129,6 +153,17 @@ public class FileIndexController(
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply sorting
|
||||||
|
fileIndexes = order.ToLower() switch
|
||||||
|
{
|
||||||
|
"name" => orderDesc ? fileIndexes.OrderByDescending(fi => fi.File.Name).ToList()
|
||||||
|
: fileIndexes.OrderBy(fi => fi.File.Name).ToList(),
|
||||||
|
"size" => orderDesc ? fileIndexes.OrderByDescending(fi => fi.File.Size).ToList()
|
||||||
|
: fileIndexes.OrderBy(fi => fi.File.Size).ToList(),
|
||||||
|
_ => orderDesc ? fileIndexes.OrderByDescending(fi => fi.File.CreatedAt).ToList()
|
||||||
|
: fileIndexes.OrderBy(fi => fi.File.CreatedAt).ToList()
|
||||||
|
};
|
||||||
|
|
||||||
return Ok(new
|
return Ok(new
|
||||||
{
|
{
|
||||||
Files = fileIndexes,
|
Files = fileIndexes,
|
||||||
@@ -154,6 +189,9 @@ public class FileIndexController(
|
|||||||
/// <param name="offset">The number of files to skip</param>
|
/// <param name="offset">The number of files to skip</param>
|
||||||
/// <param name="take">The number of files to return</param>
|
/// <param name="take">The number of files to return</param>
|
||||||
/// <param name="pool">The pool ID of those files</param>
|
/// <param name="pool">The pool ID of those files</param>
|
||||||
|
/// <param name="query">Optional query to filter files by name</param>
|
||||||
|
/// <param name="order">The field to order by (date, size, name - defaults to date)</param>
|
||||||
|
/// <param name="orderDesc">Whether to order in descending order (defaults to true)</param>
|
||||||
/// <returns>List of unindexed files</returns>
|
/// <returns>List of unindexed files</returns>
|
||||||
[HttpGet("unindexed")]
|
[HttpGet("unindexed")]
|
||||||
public async Task<IActionResult> GetUnindexedFiles(
|
public async Task<IActionResult> GetUnindexedFiles(
|
||||||
@@ -161,7 +199,9 @@ public class FileIndexController(
|
|||||||
[FromQuery] bool recycled = false,
|
[FromQuery] bool recycled = false,
|
||||||
[FromQuery] int offset = 0,
|
[FromQuery] int offset = 0,
|
||||||
[FromQuery] int take = 20,
|
[FromQuery] int take = 20,
|
||||||
[FromQuery] string? query = null
|
[FromQuery] string? query = null,
|
||||||
|
[FromQuery] string order = "date",
|
||||||
|
[FromQuery] bool orderDesc = true
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser)
|
||||||
@@ -176,9 +216,19 @@ public class FileIndexController(
|
|||||||
&& f.IsMarkedRecycle == recycled
|
&& f.IsMarkedRecycle == recycled
|
||||||
&& !db.FileIndexes.Any(fi => fi.FileId == f.Id && fi.AccountId == accountId)
|
&& !db.FileIndexes.Any(fi => fi.FileId == f.Id && fi.AccountId == accountId)
|
||||||
)
|
)
|
||||||
.OrderByDescending(f => f.CreatedAt)
|
|
||||||
.AsQueryable();
|
.AsQueryable();
|
||||||
|
|
||||||
|
// Apply sorting
|
||||||
|
filesQuery = order.ToLower() switch
|
||||||
|
{
|
||||||
|
"name" => orderDesc ? filesQuery.OrderByDescending(f => f.Name)
|
||||||
|
: filesQuery.OrderBy(f => f.Name),
|
||||||
|
"size" => orderDesc ? filesQuery.OrderByDescending(f => f.Size)
|
||||||
|
: filesQuery.OrderBy(f => f.Size),
|
||||||
|
_ => orderDesc ? filesQuery.OrderByDescending(f => f.CreatedAt)
|
||||||
|
: filesQuery.OrderBy(f => f.CreatedAt)
|
||||||
|
};
|
||||||
|
|
||||||
if (pool.HasValue) filesQuery = filesQuery.Where(f => f.PoolId == pool);
|
if (pool.HasValue) filesQuery = filesQuery.Where(f => f.PoolId == pool);
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(query))
|
if (!string.IsNullOrWhiteSpace(query))
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using DysonNetwork.Drive.Billing;
|
|
||||||
using DysonNetwork.Shared.Auth;
|
using DysonNetwork.Shared.Auth;
|
||||||
using DysonNetwork.Shared.Models;
|
using DysonNetwork.Shared.Models;
|
||||||
using DysonNetwork.Shared.Proto;
|
using DysonNetwork.Shared.Proto;
|
||||||
@@ -14,7 +13,6 @@ namespace DysonNetwork.Drive.Storage;
|
|||||||
public class FileController(
|
public class FileController(
|
||||||
AppDatabase db,
|
AppDatabase db,
|
||||||
FileService fs,
|
FileService fs,
|
||||||
QuotaService qs,
|
|
||||||
IConfiguration configuration,
|
IConfiguration configuration,
|
||||||
IWebHostEnvironment env,
|
IWebHostEnvironment env,
|
||||||
FileReferenceService fileReferenceService
|
FileReferenceService fileReferenceService
|
||||||
@@ -295,7 +293,9 @@ public class FileController(
|
|||||||
[FromQuery] bool recycled = false,
|
[FromQuery] bool recycled = false,
|
||||||
[FromQuery] int offset = 0,
|
[FromQuery] int offset = 0,
|
||||||
[FromQuery] int take = 20,
|
[FromQuery] int take = 20,
|
||||||
[FromQuery] string? query = null
|
[FromQuery] string? query = null,
|
||||||
|
[FromQuery] string order = "date",
|
||||||
|
[FromQuery] bool orderDesc = true
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||||
@@ -305,7 +305,6 @@ public class FileController(
|
|||||||
.Where(e => e.IsMarkedRecycle == recycled)
|
.Where(e => e.IsMarkedRecycle == recycled)
|
||||||
.Where(e => e.AccountId == accountId)
|
.Where(e => e.AccountId == accountId)
|
||||||
.Include(e => e.Pool)
|
.Include(e => e.Pool)
|
||||||
.OrderByDescending(e => e.CreatedAt)
|
|
||||||
.AsQueryable();
|
.AsQueryable();
|
||||||
|
|
||||||
if (pool.HasValue) filesQuery = filesQuery.Where(e => e.PoolId == pool);
|
if (pool.HasValue) filesQuery = filesQuery.Where(e => e.PoolId == pool);
|
||||||
@@ -315,6 +314,14 @@ public class FileController(
|
|||||||
filesQuery = filesQuery.Where(e => e.Name.Contains(query));
|
filesQuery = filesQuery.Where(e => e.Name.Contains(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filesQuery = order.ToLower() switch
|
||||||
|
{
|
||||||
|
"date" => orderDesc ? filesQuery.OrderByDescending(e => e.CreatedAt) : filesQuery.OrderBy(e => e.CreatedAt),
|
||||||
|
"size" => orderDesc ? filesQuery.OrderByDescending(e => e.Size) : filesQuery.OrderBy(e => e.Size),
|
||||||
|
"name" => orderDesc ? filesQuery.OrderByDescending(e => e.Name) : filesQuery.OrderBy(e => e.Name),
|
||||||
|
_ => filesQuery.OrderByDescending(e => e.CreatedAt)
|
||||||
|
};
|
||||||
|
|
||||||
var total = await filesQuery.CountAsync();
|
var total = await filesQuery.CountAsync();
|
||||||
Response.Headers.Append("X-Total", total.ToString());
|
Response.Headers.Append("X-Total", total.ToString());
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Security.Cryptography;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using DysonNetwork.Shared.Cache;
|
using DysonNetwork.Shared.Cache;
|
||||||
|
using DysonNetwork.Shared.Data;
|
||||||
using DysonNetwork.Shared.Models;
|
using DysonNetwork.Shared.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NodaTime;
|
using NodaTime;
|
||||||
|
|||||||
Reference in New Issue
Block a user