From 46612b28aa6ccf2d614200c5f51ca32b87442cfa Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 27 Jul 2025 00:29:59 +0800 Subject: [PATCH] :sparkles: File management --- .../Client/src/layouts/dashboard.vue | 7 +- DysonNetwork.Drive/Client/src/root.vue | 24 ++- DysonNetwork.Drive/Client/src/router/index.ts | 8 +- .../Client/src/views/dashboard/files.vue | 184 ++++++++++++++++++ DysonNetwork.Drive/Storage/FileController.cs | 38 +++- DysonNetwork.Drive/Storage/FileService.cs | 2 +- 6 files changed, 250 insertions(+), 13 deletions(-) create mode 100644 DysonNetwork.Drive/Client/src/views/dashboard/files.vue diff --git a/DysonNetwork.Drive/Client/src/layouts/dashboard.vue b/DysonNetwork.Drive/Client/src/layouts/dashboard.vue index daf49db..7cccf82 100644 --- a/DysonNetwork.Drive/Client/src/layouts/dashboard.vue +++ b/DysonNetwork.Drive/Client/src/layouts/dashboard.vue @@ -16,7 +16,7 @@ diff --git a/DysonNetwork.Drive/Storage/FileController.cs b/DysonNetwork.Drive/Storage/FileController.cs index c07835f..e98e571 100644 --- a/DysonNetwork.Drive/Storage/FileController.cs +++ b/DysonNetwork.Drive/Storage/FileController.cs @@ -47,13 +47,15 @@ public class FileController( } var pool = await fs.GetPoolAsync(file.PoolId.Value); - if (pool is null) return StatusCode(StatusCodes.Status410Gone, "The pool of the file no longer exists or not accessible."); + if (pool is null) + return StatusCode(StatusCodes.Status410Gone, "The pool of the file no longer exists or not accessible."); var dest = pool.StorageConfig; if (!pool.PolicyConfig.AllowAnonymous) - if(HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); - // TODO: Provide ability to add access log - + if (HttpContext.Items["CurrentUser"] is not Account currentUser) + return Unauthorized(); + // TODO: Provide ability to add access log + var fileName = string.IsNullOrWhiteSpace(file.StorageId) ? file.Id : file.StorageId; if (!original && file.HasCompression) @@ -129,6 +131,34 @@ public class FileController( return file; } + [Authorize] + [HttpGet("me")] + public async Task>> GetMyFiles( + [FromQuery] Guid? pool, + [FromQuery] int offset = 0, + [FromQuery] int take = 20 + ) + { + if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); + var accountId = Guid.Parse(currentUser.Id); + + var query = db.Files + .Where(e => e.AccountId == accountId) + .Include(e => e.Pool) + .Skip(offset) + .Take(take); + + if (pool.HasValue) query = query.Where(e => e.PoolId == pool); + + var files = await query.ToListAsync(); + + var total = await query.CountAsync(); + Response.Headers.Append("X-Total", total.ToString()); + + + return Ok(files); + } + [Authorize] [HttpDelete("{id}")] public async Task DeleteFile(string id) diff --git a/DysonNetwork.Drive/Storage/FileService.cs b/DysonNetwork.Drive/Storage/FileService.cs index 289eab7..869e788 100644 --- a/DysonNetwork.Drive/Storage/FileService.cs +++ b/DysonNetwork.Drive/Storage/FileService.cs @@ -26,7 +26,7 @@ public class FileService( { private const string CacheKeyPrefix = "file:"; private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(15); - + /// /// The api for getting file meta with cache, /// the best use case is for accessing the file data.