From 05985e08520ffe81dd784af905bbc2728dfefb11 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 15 Nov 2025 02:59:26 +0800 Subject: [PATCH] :sparkles: Unindxed files --- .../Index/FileIndexController.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/DysonNetwork.Drive/Index/FileIndexController.cs b/DysonNetwork.Drive/Index/FileIndexController.cs index 74febab..65736b8 100644 --- a/DysonNetwork.Drive/Index/FileIndexController.cs +++ b/DysonNetwork.Drive/Index/FileIndexController.cs @@ -131,6 +131,51 @@ public class FileIndexController( } } + /// + /// Gets files that have not been indexed for the current user. + /// + /// The number of files to skip + /// The number of files to return + /// List of unindexed files + [HttpGet("unindexed")] + public async Task GetUnindexedFiles([FromQuery] int offset = 0, [FromQuery] int take = 20) + { + if (HttpContext.Items["CurrentUser"] is not Account currentUser) + return new ObjectResult(ApiError.Unauthorized()) { StatusCode = 401 }; + + var accountId = Guid.Parse(currentUser.Id); + + try + { + var query = db.Files + .Where(f => f.AccountId == accountId + && !f.IsMarkedRecycle + && !db.FileIndexes.Any(fi => fi.FileId == f.Id && fi.AccountId == accountId)) + .OrderByDescending(f => f.CreatedAt); + + var totalCount = await query.CountAsync(); + + Response.Headers.Append("X-Total", totalCount.ToString()); + + var unindexedFiles = await query + .Skip(offset) + .Take(take) + .ToListAsync(); + + return Ok(unindexedFiles); + } + catch (Exception ex) + { + logger.LogError(ex, "Failed to get unindexed files for account {AccountId}", accountId); + return new ObjectResult(new ApiError + { + Code = "GET_UNINDEXED_FAILED", + Message = "Failed to get unindexed files", + Status = 500 + }) { StatusCode = 500 }; + } + } + /// /// Moves a file to a new path ///