mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-02-25 01:23:20 +00:00
s3: add bulk delete api (#82)
This commit is contained in:
@@ -21,20 +21,17 @@ using System;
|
||||
using System.Net.Http;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Amazon.S3.Model;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MongoDB.Driver;
|
||||
using Notesnook.API.Accessors;
|
||||
using Notesnook.API.Helpers;
|
||||
using Notesnook.API.Interfaces;
|
||||
using Notesnook.API.Models;
|
||||
using Streetwriters.Common;
|
||||
using Streetwriters.Common.Accessors;
|
||||
using Streetwriters.Common.Extensions;
|
||||
using Streetwriters.Common.Interfaces;
|
||||
using Streetwriters.Common.Models;
|
||||
|
||||
namespace Notesnook.API.Controllers
|
||||
@@ -212,5 +209,26 @@ namespace Notesnook.API.Controllers
|
||||
return BadRequest(new { error = "Failed to delete attachment." });
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("bulk-delete")]
|
||||
public async Task<IActionResult> DeleteBulkAsync([FromBody] DeleteBulkObjectsRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (request.Names == null || request.Names.Length == 0)
|
||||
{
|
||||
return BadRequest(new { error = "No files specified for deletion." });
|
||||
}
|
||||
|
||||
var userId = this.User.GetUserId();
|
||||
await s3Service.DeleteObjectsAsync(userId, request.Names);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Error deleting objects for user.");
|
||||
return BadRequest(new { error = "Failed to delete attachments." });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user