diff --git a/DysonNetwork.Drive/Storage/FileController.cs b/DysonNetwork.Drive/Storage/FileController.cs index 293d3e7..5456e4d 100644 --- a/DysonNetwork.Drive/Storage/FileController.cs +++ b/DysonNetwork.Drive/Storage/FileController.cs @@ -333,6 +333,22 @@ public class FileController( return Ok(files); } + public class FileBatchDeletionRequest + { + public List FileIds { get; set; } = []; + } + + [Authorize] + [HttpPost("batches/delete")] + public async Task DeleteFileBatch([FromBody] FileBatchDeletionRequest request) + { + if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); + var userId = Guid.Parse(currentUser.Id); + + var count = await fs.DeleteAccountFileBatchAsync(userId, request.FileIds); + return Ok(new { Count = count }); + } + [Authorize] [HttpDelete("{id}")] public async Task> DeleteFile(string id) @@ -371,4 +387,4 @@ public class FileController( var count = await fs.DeleteAllRecycledFilesAsync(); return Ok(new { Count = count }); } -} +} \ No newline at end of file diff --git a/DysonNetwork.Drive/Storage/FileService.cs b/DysonNetwork.Drive/Storage/FileService.cs index d94a403..ac8965c 100644 --- a/DysonNetwork.Drive/Storage/FileService.cs +++ b/DysonNetwork.Drive/Storage/FileService.cs @@ -718,6 +718,21 @@ public class FileService( return count; } + public async Task DeleteAccountFileBatchAsync(Guid accountId, List fileIds) + { + var files = await db.Files + .Where(f => f.AccountId == accountId && fileIds.Contains(f.Id)) + .ToListAsync(); + var count = files.Count; + var tasks = files.Select(f => DeleteFileDataAsync(f, true)); + await Task.WhenAll(tasks); + var fileIdsList = files.Select(f => f.Id).ToList(); + await _PurgeCacheRangeAsync(fileIdsList); + db.RemoveRange(files); + await db.SaveChangesAsync(); + return count; + } + public async Task DeletePoolRecycledFilesAsync(Guid poolId) { var files = await db.Files @@ -788,4 +803,4 @@ file class UpdatableCloudFile(SnCloudFile file) .SetProperty(f => f.UserMeta, userMeta) .SetProperty(f => f.IsMarkedRecycle, IsMarkedRecycle); } -} \ No newline at end of file +}