fix: update API routes for fetching raw paste content and deleting pastes

This commit is contained in:
2026-01-04 09:55:15 -05:00
parent 2c24af5ac9
commit 48543c7ff0
2 changed files with 6 additions and 6 deletions
@@ -12,7 +12,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
}; };
} }
const pasteData = (await paste.json()) as Paste; const pasteData = (await paste.json()) as Paste;
const pasteContent = await fetch(`/api/paste/raw/${id}`); const pasteContent = await fetch(`/api/paste/${id}/raw`);
const pasteOptions = await fetch('/api/paste/create/options'); const pasteOptions = await fetch('/api/paste/create/options');
const options = await pasteOptions.json(); const options = await pasteOptions.json();
const content = await pasteContent.text(); const content = await pasteContent.text();
@@ -77,7 +77,7 @@ namespace SharpbinV3.Server.Controllers
}); });
} }
[HttpGet] [HttpGet]
[Route("raw/{id}")] [Route("{id}/raw")]
public async Task<IActionResult> GetRawPasteByID(string id) public async Task<IActionResult> GetRawPasteByID(string id)
{ {
var paste = await _pasteService.Get(id); var paste = await _pasteService.Get(id);
@@ -109,7 +109,7 @@ namespace SharpbinV3.Server.Controllers
.Where(c => c.Type == ClaimTypes.Role) .Where(c => c.Type == ClaimTypes.Role)
.Select(c => int.Parse(c.Value)) .Select(c => int.Parse(c.Value))
.Any(r => r == 1 || r == 255); .Any(r => r == 1 || r == 255);
if (paste.AuthorUUID != Guid.Parse(uuidClaim) || !hasPrivilegedRole) if (paste.AuthorUUID != Guid.Parse(uuidClaim) && !hasPrivilegedRole)
return Forbid(); return Forbid();
bool result = await _pasteService.EditText(paste, content); bool result = await _pasteService.EditText(paste, content);
if (!result) return NotFound(); if (!result) return NotFound();
@@ -130,7 +130,7 @@ namespace SharpbinV3.Server.Controllers
.Where(c => c.Type == ClaimTypes.Role) .Where(c => c.Type == ClaimTypes.Role)
.Select(c => int.Parse(c.Value)) .Select(c => int.Parse(c.Value))
.Any(r => r == 1 || r == 255); .Any(r => r == 1 || r == 255);
if (paste.AuthorUUID != Guid.Parse(uuidClaim) || !hasPrivilegedRole) if (paste.AuthorUUID != Guid.Parse(uuidClaim) && !hasPrivilegedRole)
return Forbid(); return Forbid();
if (request.Title != null) if (request.Title != null)
paste.Title = request.Title; paste.Title = request.Title;
@@ -170,7 +170,7 @@ namespace SharpbinV3.Server.Controllers
}); });
} }
[HttpDelete] [HttpDelete]
[Route("{id}")] [Route("{id}/delete")]
[Authorize] [Authorize]
public async Task<IActionResult> DeletePaste(string id) public async Task<IActionResult> DeletePaste(string id)
{ {
@@ -183,7 +183,7 @@ namespace SharpbinV3.Server.Controllers
.Where(c => c.Type == ClaimTypes.Role) .Where(c => c.Type == ClaimTypes.Role)
.Select(c => int.Parse(c.Value)) .Select(c => int.Parse(c.Value))
.Any(r => r == 1 || r == 255); .Any(r => r == 1 || r == 255);
if (paste.AuthorUUID != Guid.Parse(uuidClaim) || !hasPrivilegedRole) if (paste.AuthorUUID != Guid.Parse(uuidClaim) && !hasPrivilegedRole)
return Forbid(); return Forbid();
bool result = await _pasteService.Delete(paste); bool result = await _pasteService.Delete(paste);
if (!result) return NotFound(); if (!result) return NotFound();