fix: use image/avif as default avatar mime
fix: disable cross-origin iframes
This commit is contained in:
parent
a43e586e4c
commit
83c6df6f6e
3 changed files with 61 additions and 49 deletions
|
@ -82,14 +82,16 @@ pub async fn avatar_request(
|
|||
}
|
||||
};
|
||||
|
||||
let mime = if user.settings.avatar_mime.is_empty() {
|
||||
"image/avif"
|
||||
} else {
|
||||
&user.settings.avatar_mime
|
||||
};
|
||||
|
||||
let path = PathBufD::current().extend(&[
|
||||
data.0.0.dirs.media.as_str(),
|
||||
"avatars",
|
||||
&format!(
|
||||
"{}.{}",
|
||||
&(user.id as i64),
|
||||
user.settings.avatar_mime.replace("image/", "")
|
||||
),
|
||||
&format!("{}.{}", &(user.id as i64), mime.replace("image/", "")),
|
||||
]);
|
||||
|
||||
if !exists(&path).unwrap() {
|
||||
|
@ -104,10 +106,7 @@ pub async fn avatar_request(
|
|||
}
|
||||
|
||||
Ok((
|
||||
[(
|
||||
"Content-Type".to_string(),
|
||||
user.settings.avatar_mime.clone(),
|
||||
)],
|
||||
[("Content-Type".to_string(), mime.to_owned())],
|
||||
Body::from(read_image(path)),
|
||||
))
|
||||
}
|
||||
|
@ -134,14 +133,16 @@ pub async fn banner_request(
|
|||
}
|
||||
};
|
||||
|
||||
let mime = if user.settings.banner_mime.is_empty() {
|
||||
"image/avif"
|
||||
} else {
|
||||
&user.settings.banner_mime
|
||||
};
|
||||
|
||||
let path = PathBufD::current().extend(&[
|
||||
data.0.0.dirs.media.as_str(),
|
||||
"banners",
|
||||
&format!(
|
||||
"{}.{}",
|
||||
&(user.id as i64),
|
||||
user.settings.banner_mime.replace("image/", "")
|
||||
),
|
||||
&format!("{}.{}", &(user.id as i64), mime.replace("image/", "")),
|
||||
]);
|
||||
|
||||
if !exists(&path).unwrap() {
|
||||
|
@ -156,10 +157,7 @@ pub async fn banner_request(
|
|||
}
|
||||
|
||||
Ok((
|
||||
[(
|
||||
"Content-Type".to_string(),
|
||||
user.settings.banner_mime.clone(),
|
||||
)],
|
||||
[("Content-Type".to_string(), mime.to_owned())],
|
||||
Body::from(read_image(path)),
|
||||
))
|
||||
}
|
||||
|
@ -211,15 +209,6 @@ pub async fn upload_avatar_request(
|
|||
mime.replace("image/", "")
|
||||
);
|
||||
|
||||
// update user settings
|
||||
auth_user.settings.avatar_mime = mime.to_string();
|
||||
if let Err(e) = data
|
||||
.update_user_settings(auth_user.id, auth_user.settings)
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
|
||||
// upload image (gif)
|
||||
if mime == "image/gif" {
|
||||
// gif image, don't encode
|
||||
|
@ -256,11 +245,23 @@ pub async fn upload_avatar_request(
|
|||
image::ImageFormat::Avif
|
||||
},
|
||||
) {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Avatar uploaded. It might take a bit to update".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Ok(_) => {
|
||||
// update user settings
|
||||
auth_user.settings.avatar_mime = mime.to_string();
|
||||
if let Err(e) = data
|
||||
.update_user_settings(auth_user.id, auth_user.settings)
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
|
||||
// ...
|
||||
Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Avatar uploaded. It might take a bit to update".to_string(),
|
||||
payload: (),
|
||||
})
|
||||
}
|
||||
Err(e) => Json(Error::MiscError(e.to_string()).into()),
|
||||
}
|
||||
}
|
||||
|
@ -309,15 +310,6 @@ pub async fn upload_banner_request(
|
|||
mime.replace("image/", "")
|
||||
);
|
||||
|
||||
// update user settings
|
||||
auth_user.settings.banner_mime = mime.to_string();
|
||||
if let Err(e) = data
|
||||
.update_user_settings(auth_user.id, auth_user.settings)
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
|
||||
// upload image (gif)
|
||||
if mime == "image/gif" {
|
||||
// gif image, don't encode
|
||||
|
@ -354,11 +346,23 @@ pub async fn upload_banner_request(
|
|||
image::ImageFormat::Avif
|
||||
},
|
||||
) {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Banner uploaded. It might take a bit to update".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Ok(_) => {
|
||||
// update user settings
|
||||
auth_user.settings.banner_mime = mime.to_string();
|
||||
if let Err(e) = data
|
||||
.update_user_settings(auth_user.id, auth_user.settings)
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
|
||||
// ...
|
||||
Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Banner uploaded. It might take a bit to update".to_string(),
|
||||
payload: (),
|
||||
})
|
||||
}
|
||||
Err(e) => Json(Error::MiscError(e.to_string()).into()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue