From ce7fb81df36e14186fbd602357e0f2072c1a506c Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Tue, 5 Mar 2024 10:24:13 +0500 Subject: [PATCH] monographs: self destruct monographs on api call --- .../Controllers/MonographsController.cs | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Notesnook.API/Controllers/MonographsController.cs b/Notesnook.API/Controllers/MonographsController.cs index 06126bb..5862962 100644 --- a/Notesnook.API/Controllers/MonographsController.cs +++ b/Notesnook.API/Controllers/MonographsController.cs @@ -20,6 +20,7 @@ along with this program. If not, see . using System; using System.Linq; using System.Security.Claims; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -117,14 +118,30 @@ namespace Notesnook.API.Controllers }); } - if (monograph.SelfDestruct) - await Monographs.DeleteByIdAsync(monograph.Id); - if (monograph.EncryptedContent == null) monograph.Content = monograph.CompressedContent.DecompressBrotli(); return Ok(monograph); } + [HttpGet("{id}/destruct")] + [AllowAnonymous] + public async Task DestructMonographAsync([FromRoute] string id) + { + var monograph = await Monographs.GetAsync(id); + if (monograph == null) + { + return NotFound(new + { + error = "invalid_id", + error_description = $"No such monograph found." + }); + } + + if (monograph.SelfDestruct) + await Monographs.DeleteByIdAsync(monograph.Id); + + return Ok(); + } [HttpDelete("{id}")] public async Task DeleteAsync([FromRoute] string id)