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.