add: allow supporters to upload gif avatars/banners

This commit is contained in:
trisua 2025-05-04 16:19:34 -04:00
parent cf38022597
commit e727de9c63
10 changed files with 231 additions and 52 deletions

View file

@ -304,13 +304,21 @@ impl DataManager {
let avatar = PathBufD::current().extend(&[
self.0.dirs.media.as_str(),
"avatars",
&format!("{}.avif", &(user.id as i64)),
&format!(
"{}.{}",
&(user.id as i64),
user.settings.avatar_mime.replace("image/", "")
),
]);
let banner = PathBufD::current().extend(&[
self.0.dirs.media.as_str(),
"banners",
&format!("{}.avif", &(user.id as i64)),
&format!(
"{}.{}",
&(user.id as i64),
user.settings.banner_mime.replace("image/", "")
),
]);
if exists(&avatar).unwrap() {

View file

@ -199,6 +199,16 @@ pub struct UserSettings {
/// The user's status. Shows over connection info.
#[serde(default)]
pub status: String,
/// The mime type of the user's avatar.
#[serde(default = "mime_avif")]
pub avatar_mime: String,
/// The mime type of the user's banner.
#[serde(default = "mime_avif")]
pub banner_mime: String,
}
fn mime_avif() -> String {
"image/avif".to_string()
}
impl Default for User {

View file

@ -43,6 +43,7 @@ pub enum Error {
UsernameInUse,
TitleInUse,
QuestionsDisabled,
RequiresSupporter,
Unknown,
}
@ -63,6 +64,9 @@ impl Display for Error {
Self::UsernameInUse => "Username in use".to_string(),
Self::TitleInUse => "Title in use".to_string(),
Self::QuestionsDisabled => "You are not allowed to ask questions there".to_string(),
Self::RequiresSupporter => {
"Only site supporters can upload GIF files as their avatar/banner".to_string()
}
_ => format!("An unknown error as occurred: ({:?})", self),
})
}

View file

@ -10,8 +10,35 @@ pub enum PkceChallengeMethod {
#[derive(Serialize, Deserialize, PartialEq, Eq)]
pub enum AppScope {
#[serde(alias = "user-read-profile")]
UserReadProfile,
UserReadSessions,
UserReadPosts,
UserReadMessages,
UserCreatePosts,
UserCreateMessages,
UserDeletePosts,
UserDeleteMessages,
}
impl AppScope {
/// Parse the given input string as a list of scopes.
pub fn parse(input: &str) -> Vec<AppScope> {
let mut out: Vec<AppScope> = Vec::new();
for scope in input.split(" ") {
out.push(match scope {
"user-read-profile" => Self::UserReadProfile,
"user-read-sessions" => Self::UserReadSessions,
"user-read-posts" => Self::UserReadPosts,
"user-read-messages" => Self::UserReadMessages,
"user-create-posts" => Self::UserCreatePosts,
"user-create-messages" => Self::UserCreateMessages,
"user-delete-posts" => Self::UserDeletePosts,
"user-delete-messages" => Self::UserDeleteMessages,
_ => continue,
})
}
out
}
}
/// Check a verifier against the stored challenge (using the given [`PkceChallengeMethod`]).