Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow doubled avatar resolution #6611

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,24 +252,27 @@ impl<'a> BlobObject<'a> {
}

pub async fn recode_to_avatar_size(&mut self, context: &Context) -> Result<()> {
let img_wh =
let (img_wh, max_bytes) =
match MediaQuality::from_i32(context.get_config_int(Config::MediaQuality).await?)
.unwrap_or_default()
{
MediaQuality::Balanced => constants::BALANCED_AVATAR_SIZE,
MediaQuality::Worse => constants::WORSE_AVATAR_SIZE,
MediaQuality::Balanced => (
constants::BALANCED_AVATAR_SIZE,
constants::BALANCED_AVATAR_BYTES,
),
MediaQuality::Worse => {
(constants::WORSE_AVATAR_SIZE, constants::WORSE_AVATAR_BYTES)
}
};

let maybe_sticker = &mut false;
let strict_limits = true;
// max_bytes is 20_000 bytes: Outlook servers don't allow headers larger than 32k.
// 32 / 4 * 3 = 24k if you account for base64 encoding. To be safe, we reduced this to 20k.
self.recode_to_size(
context,
None, // The name of an avatar doesn't matter
maybe_sticker,
img_wh,
20_000,
max_bytes,
strict_limits,
)?;

Expand Down
4 changes: 2 additions & 2 deletions src/blob/blob_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async fn test_selfavatar_outside_blobdir() {
let avatar_blob = t.get_config(Config::Selfavatar).await.unwrap().unwrap();
let avatar_path = Path::new(&avatar_blob);
assert!(
avatar_blob.ends_with("d98cd30ed8f2129bf3968420208849d.jpg"),
avatar_blob.ends_with("009161310a6afc319163e4bcabd23b9.jpg"),
"The avatar filename should be its hash, put instead it's {avatar_blob}"
);
let scaled_avatar_size = file_size(avatar_path).await;
Expand Down Expand Up @@ -226,7 +226,7 @@ async fn test_selfavatar_in_blobdir() {
.unwrap();
let avatar_cfg = t.get_config(Config::Selfavatar).await.unwrap().unwrap();
assert!(
avatar_cfg.ends_with("fa7418e646301203538041f60d03190.png"),
avatar_cfg.ends_with("ec054c444a5755adf2b0aaea40209f2.png"),
"Avatar file name {avatar_cfg} should end with its hash"
);

Expand Down
6 changes: 4 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,11 @@ pub(crate) const DC_FETCH_EXISTING_MSGS_COUNT: i64 = 100;
pub const BALANCED_IMAGE_BYTES: usize = 500_000;
pub const WORSE_IMAGE_BYTES: usize = 130_000;

// max. width/height of an avatar
pub(crate) const BALANCED_AVATAR_SIZE: u32 = 256;
// max. width/height and bytes of an avatar
pub(crate) const BALANCED_AVATAR_SIZE: u32 = 512;
pub(crate) const BALANCED_AVATAR_BYTES: usize = 60_000;
pub(crate) const WORSE_AVATAR_SIZE: u32 = 128;
pub(crate) const WORSE_AVATAR_BYTES: usize = 20_000; // this also fits to Outlook servers don't allowing headers larger than 32k.

// max. width/height of images scaled down because of being too huge
pub const BALANCED_IMAGE_SIZE: u32 = 1280;
Expand Down
Loading