mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 03:11:32 +00:00
add upload user banner
This commit is contained in:
parent
5f0619534e
commit
5f49b2aaec
4 changed files with 22 additions and 12 deletions
|
@ -3,12 +3,10 @@ use actix_web::web::Json;
|
|||
use lemmy_api_common::{
|
||||
context::LemmyContext,
|
||||
person::SaveUserSettings,
|
||||
request::replace_image,
|
||||
utils::{
|
||||
get_url_blocklist,
|
||||
local_site_to_slur_regex,
|
||||
process_markdown_opt,
|
||||
proxy_image_link_opt_api,
|
||||
send_verification_email,
|
||||
},
|
||||
SuccessResponse,
|
||||
|
@ -21,7 +19,7 @@ use lemmy_db_schema::{
|
|||
person::{Person, PersonUpdateForm},
|
||||
},
|
||||
traits::Crud,
|
||||
utils::{diesel_string_update, diesel_url_update},
|
||||
utils::diesel_string_update,
|
||||
};
|
||||
use lemmy_db_views::structs::{LocalUserView, SiteView};
|
||||
use lemmy_utils::{
|
||||
|
@ -46,10 +44,6 @@ pub async fn save_user_settings(
|
|||
.as_deref(),
|
||||
);
|
||||
|
||||
let banner = diesel_url_update(data.banner.as_deref())?;
|
||||
replace_image(&banner, &local_user_view.person.banner, &context).await?;
|
||||
let banner = proxy_image_link_opt_api(banner, &context).await?;
|
||||
|
||||
let display_name = diesel_string_update(data.display_name.as_deref());
|
||||
let matrix_user_id = diesel_string_update(data.matrix_user_id.as_deref());
|
||||
let email_deref = data.email.as_deref().map(str::to_lowercase);
|
||||
|
@ -104,7 +98,6 @@ pub async fn save_user_settings(
|
|||
bio,
|
||||
matrix_user_id,
|
||||
bot_account: data.bot_account,
|
||||
banner,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
|
|
@ -114,9 +114,6 @@ pub struct SaveUserSettings {
|
|||
/// The language of the lemmy interface
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
pub interface_language: Option<String>,
|
||||
/// A URL for your banner.
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
pub banner: Option<String>,
|
||||
/// Your display name, which can contain strange characters, and does not need to be unique.
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
pub display_name: Option<String>,
|
||||
|
|
|
@ -22,6 +22,7 @@ use UploadType::*;
|
|||
|
||||
pub enum UploadType {
|
||||
Avatar,
|
||||
Banner,
|
||||
Other,
|
||||
}
|
||||
|
||||
|
@ -58,6 +59,24 @@ pub async fn upload_user_avatar(
|
|||
Ok(Json(SuccessResponse::default()))
|
||||
}
|
||||
|
||||
pub async fn upload_user_banner(
|
||||
req: HttpRequest,
|
||||
body: Payload,
|
||||
local_user_view: LocalUserView,
|
||||
context: Data<LemmyContext>,
|
||||
) -> LemmyResult<Json<SuccessResponse>> {
|
||||
let image = do_upload_image(req, body, Banner, &local_user_view, &context).await?;
|
||||
delete_old_image(&local_user_view.person.banner, &context).await?;
|
||||
|
||||
let person_form = PersonUpdateForm {
|
||||
banner: Some(Some(image.image_url.into())),
|
||||
..Default::default()
|
||||
};
|
||||
Person::update(&mut context.pool(), local_user_view.person.id, &person_form).await?;
|
||||
|
||||
Ok(Json(SuccessResponse::default()))
|
||||
}
|
||||
|
||||
pub async fn do_upload_image(
|
||||
req: HttpRequest,
|
||||
body: Payload,
|
||||
|
|
|
@ -162,7 +162,7 @@ use lemmy_routes::images::{
|
|||
delete_image,
|
||||
download::{get_image, image_proxy},
|
||||
pictrs_health,
|
||||
upload::{upload_image, upload_user_avatar},
|
||||
upload::{upload_image, upload_user_avatar, upload_user_banner},
|
||||
};
|
||||
use lemmy_utils::rate_limit::RateLimitCell;
|
||||
|
||||
|
@ -320,6 +320,7 @@ pub fn config(cfg: &mut ServiceConfig, rate_limit: &RateLimitCell) {
|
|||
.route("/list_logins", get().to(list_logins))
|
||||
.route("/validate_auth", get().to(validate_auth))
|
||||
.route("/avatar", post().to(upload_user_avatar))
|
||||
.route("/banner", post().to(upload_user_banner))
|
||||
.service(
|
||||
scope("/block")
|
||||
.route("/person", post().to(user_block_person))
|
||||
|
|
Loading…
Reference in a new issue