mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-05 18:48:41 +00:00
feat: add delete functionality for pastes with authorization check
This commit is contained in:
@@ -64,6 +64,7 @@ namespace SharpbinV3.Server.Controllers
|
||||
paste.Syntax,
|
||||
paste.Visibility,
|
||||
paste.ExpiresAt,
|
||||
paste.EditedAt,
|
||||
Author = paste.User != null && paste.User.Visibility == 0 ? new
|
||||
{
|
||||
paste.User.UID,
|
||||
@@ -157,6 +158,21 @@ namespace SharpbinV3.Server.Controllers
|
||||
}
|
||||
});
|
||||
}
|
||||
[HttpDelete]
|
||||
[Route("{id}")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> DeletePaste(string id)
|
||||
{
|
||||
var paste = await _pasteService.Get(id);
|
||||
if (paste == null) return NotFound();
|
||||
var httpUser = HttpContext.User;
|
||||
var userUUID = httpUser?.FindFirst("UUID")?.Value;
|
||||
if (userUUID == null || paste.AuthorUUID != Guid.Parse(userUUID))
|
||||
return Forbid();
|
||||
bool result = await _pasteService.Delete(paste);
|
||||
if (!result) return NotFound();
|
||||
return Ok(new { message = "Paste deleted successfully." });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("create/options")]
|
||||
|
||||
Reference in New Issue
Block a user