[backend/masto-client] Add status source endpoint (ISH-98)
This commit is contained in:
parent
0c70a23770
commit
edfa2e9c9a
3 changed files with 26 additions and 6 deletions
|
@ -75,7 +75,7 @@ public class NoteRenderer(
|
|||
})
|
||||
.ToList();
|
||||
|
||||
var content = text != null
|
||||
var content = text != null && data?.Source != true
|
||||
? await mfmConverter.ToHtmlAsync(text, mentionedUsers, note.UserHost)
|
||||
: null;
|
||||
|
||||
|
@ -106,7 +106,7 @@ public class NoteRenderer(
|
|||
ContentWarning = note.Cw ?? "",
|
||||
Visibility = StatusEntity.EncodeVisibility(note.Visibility),
|
||||
Content = content,
|
||||
Text = text,
|
||||
Text = data?.Source == true ? text : null,
|
||||
Mentions = mentions,
|
||||
IsPinned = false,
|
||||
Attachments = attachments,
|
||||
|
@ -226,5 +226,6 @@ public class NoteRenderer(
|
|||
public List<string>? LikedNotes;
|
||||
public List<string>? Renotes;
|
||||
public List<EmojiEntity>? Emoji;
|
||||
public bool Source;
|
||||
}
|
||||
}
|
|
@ -85,4 +85,11 @@ public class StatusContext
|
|||
{
|
||||
[J("ancestors")] public required List<StatusEntity> Ancestors { get; set; }
|
||||
[J("descendants")] public required List<StatusEntity> Descendants { get; set; }
|
||||
}
|
||||
|
||||
public class StatusSource
|
||||
{
|
||||
[J("id")] public required string Id { get; set; }
|
||||
[J("text")] public required string Text { get; set; }
|
||||
[J("spoiler_text")] public required string ContentWarning { get; set; }
|
||||
}
|
|
@ -276,19 +276,31 @@ public class StatusController(
|
|||
[HttpDelete("{id}")]
|
||||
[Authorize("write:statuses")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(StatusEntity))]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(MastodonErrorResponse))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))]
|
||||
public async Task<IActionResult> DeleteNote(string id)
|
||||
{
|
||||
var user = HttpContext.GetUserOrFail();
|
||||
var note = await db.Notes.IncludeCommonProperties().FirstOrDefaultAsync(p => p.Id == id && p.User == user) ??
|
||||
throw GracefulException.RecordNotFound();
|
||||
if (user.Id != note.UserId)
|
||||
throw GracefulException.RecordNotFound();
|
||||
|
||||
var res = await noteRenderer.RenderAsync(note, user);
|
||||
var res = await noteRenderer.RenderAsync(note, user, new NoteRenderer.NoteRendererDto { Source = true });
|
||||
await noteSvc.DeleteNoteAsync(note);
|
||||
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
[HttpGet("{id}/source")]
|
||||
[Authorize("read:statuses")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(StatusSource))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(MastodonErrorResponse))]
|
||||
public async Task<IActionResult> GetNoteSource(string id)
|
||||
{
|
||||
var user = HttpContext.GetUserOrFail();
|
||||
var res = await db.Notes.Where(p => p.Id == id && p.User == user)
|
||||
.Select(p => new StatusSource { Id = p.Id, ContentWarning = p.Cw ?? "", Text = p.Text ?? "" })
|
||||
.FirstOrDefaultAsync() ??
|
||||
throw GracefulException.RecordNotFound();
|
||||
|
||||
return Ok(res);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue