fix(backend-rs): update padding logic to accomodate non-ASCII payload
This commit is contained in:
parent
be894399a5
commit
7cf612f9f8
1 changed files with 7 additions and 4 deletions
|
@ -136,8 +136,9 @@ async fn encode_mastodon_payload(
|
||||||
serde_json::to_value(token.token)?,
|
serde_json::to_value(token.token)?,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Some apps expect notification_id to be an integer, but never use it.
|
// Some apps expect notification_id to be an integer,
|
||||||
if ["IceCubesApp", "Mammoth", "feather", "MaserApp"].contains(&client.name.as_str()) {
|
// but doesn’t break when the ID doesn’t match the rest of API.
|
||||||
|
if ["IceCubesApp", "Mammoth", "feather", "MaserApp", "Metatext", "Feditext"].contains(&client.name.as_str()) {
|
||||||
let timestamp = object
|
let timestamp = object
|
||||||
.get("notification_id")
|
.get("notification_id")
|
||||||
.and_then(|id| id.as_str())
|
.and_then(|id| id.as_str())
|
||||||
|
@ -153,9 +154,11 @@ async fn encode_mastodon_payload(
|
||||||
// Adding space paddings to the end of JSON payload to prevent
|
// Adding space paddings to the end of JSON payload to prevent
|
||||||
// `esm` from adding null bytes payload which many Mastodon clients don’t support.
|
// `esm` from adding null bytes payload which many Mastodon clients don’t support.
|
||||||
// https://firefish.dev/firefish/firefish/-/merge_requests/10905#note_6733
|
// https://firefish.dev/firefish/firefish/-/merge_requests/10905#note_6733
|
||||||
let padded_length = 126 + (res.len() + 1) / 128 * 128;
|
// not using {:padding_length$} directly on `res`` because we want the padding to be
|
||||||
|
// calculated based on the UTF-8 byte size of `res` instead of number of characters.
|
||||||
|
let padded_length = 126 + (res.len() + 1) / 128 * 128 - res.len();
|
||||||
|
|
||||||
Ok(format!("{:padded_length$}", res))
|
Ok(format!("{}{:padded_length$}", res, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_web_push_failure(
|
async fn handle_web_push_failure(
|
||||||
|
|
Loading…
Reference in a new issue