A posted picture is described again by editing its post
PUT /api/v1/media/:id on a picture already posted changed the upload but never the post, which keeps its own copy, so the new description or focal point reached nobody. As on Mastodon, PUT now takes only media not posted yet (404 otherwise), and a status edit takes media_attributes[] (id, description, focus; from a JSON body or a form): the uploads and the post's copies change, and the Update the edit federates carries them. An edit that sends no media keeps them as they were described. No pasture scenario edits a description, so the sweep could not see this. MediaLifecycleTests: PUT on a posted picture is refused, an edit describes it again and keeps its warning, flag and language as sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
This commit is contained in:
1 parent
a4ced664cf
commit
5252b8f320
4 files changed
+87
-2
No files matched your search
@@ -167,11 +167,41 @@ namespace PrivaPub.Api.Mastodon.Controllers
|
||||
SpoilerText = Params.Get("spoiler_text"),
|
||||
Sensitive = Params.Bool("sensitive") ?? false,
|
||||
Language = Params.Get("language"),
|
||||
MediaIds = Params.Has("media_ids") ? Params.List("media_ids") : default
|
||||
MediaIds = Params.Has("media_ids") ? Params.List("media_ids") : default,
|
||||
MediaChanges = MediaAttributes()
|
||||
}, token);
|
||||
return outcome.Ok ? Json(await _mapper.Status(outcome.Post, MyId, token)) : Error(outcome.Status, outcome.Error);
|
||||
}
|
||||
|
||||
// Mastodon's media_attributes: a JSON body's array of objects, or a form's media_attributes[i][field] or
|
||||
// media_attributes[][field] (each field then listed in the same order)
|
||||
IReadOnlyList<MediaChange> MediaAttributes()
|
||||
{
|
||||
var changes = new List<MediaChange>();
|
||||
if (Params.Json is { ValueKind: System.Text.Json.JsonValueKind.Object } json && json.TryGetProperty("media_attributes", out var array)
|
||||
&& array.ValueKind == System.Text.Json.JsonValueKind.Array)
|
||||
{
|
||||
foreach (var item in array.EnumerateArray().Where(i => i.ValueKind == System.Text.Json.JsonValueKind.Object).Take(4))
|
||||
{
|
||||
var hasDescription = item.TryGetProperty("description", out var description);
|
||||
changes.Add(new MediaChange(Text(item, "id"), hasDescription, hasDescription ? Text(item, "description") : default, Text(item, "focus")));
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
for (var i = 0; i < 4 && Params.Get($"media_attributes[{i}][id]") is { } id; i++)
|
||||
changes.Add(new MediaChange(id, Params.Has($"media_attributes[{i}][description]"), Params.Get($"media_attributes[{i}][description]"), Params.Get($"media_attributes[{i}][focus]")));
|
||||
var ids = Params.List("media_attributes[][id]");
|
||||
var descriptions = Params.List("media_attributes[][description]");
|
||||
var foci = Params.List("media_attributes[][focus]");
|
||||
for (var i = 0; i < Math.Min(ids.Count, 4); i++)
|
||||
changes.Add(new MediaChange(ids[i], i < descriptions.Count, i < descriptions.Count ? descriptions[i] : default, i < foci.Count ? foci[i] : default));
|
||||
return changes;
|
||||
|
||||
static string Text(System.Text.Json.JsonElement item, string name) => item.TryGetProperty(name, out var value)
|
||||
? value.ValueKind == System.Text.Json.JsonValueKind.String ? value.GetString() : value.ValueKind is System.Text.Json.JsonValueKind.Null ? default : value.GetRawText()
|
||||
: default;
|
||||
}
|
||||
|
||||
[HttpDelete("/api/v1/statuses/{id}"), Scope("write:statuses")]
|
||||
public async Task<IActionResult> Delete(string id, CancellationToken token)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user