add: image proxy

add: mentions in posts
TODO: audit log, reports, user mod panel
This commit is contained in:
trisua 2025-04-01 13:26:33 -04:00
parent e183a01887
commit 3a8af17154
14 changed files with 308 additions and 33 deletions

View file

@ -105,6 +105,49 @@ impl User {
pub fn check_password(&self, against: String) -> bool {
self.password == hash_salted(against, self.salt.clone())
}
/// Parse user mentions in a given `input`.
pub fn parse_mentions(input: &str) -> Vec<String> {
// state
let mut escape: bool = false;
let mut at: bool = false;
let mut buffer: String = String::new();
let mut out = Vec::new();
// parse
for char in input.chars() {
if (char == '\\') && !escape {
escape = true;
}
if (char == '@') && !escape {
at = true;
continue; // don't push @
}
if at {
if (char == ' ') && !escape {
// reached space, end @
at = false;
if !out.contains(&buffer) {
out.push(buffer);
}
buffer = String::new();
continue;
}
// push mention text
buffer.push(char);
}
escape = false;
}
// return
out
}
}
#[derive(Debug, Serialize, Deserialize)]

View file

@ -28,8 +28,8 @@ impl Serialize for CommunityPermission {
}
}
struct JournalPermissionVisitor;
impl<'de> Visitor<'de> for JournalPermissionVisitor {
struct CommunityPermissionVisitor;
impl<'de> Visitor<'de> for CommunityPermissionVisitor {
type Value = CommunityPermission;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
@ -75,22 +75,22 @@ impl<'de> Deserialize<'de> for CommunityPermission {
where
D: Deserializer<'de>,
{
deserializer.deserialize_any(JournalPermissionVisitor)
deserializer.deserialize_any(CommunityPermissionVisitor)
}
}
impl CommunityPermission {
/// Join two [`JournalPermission`]s into a single `u32`.
/// Join two [`CommunityPermission`]s into a single `u32`.
pub fn join(lhs: CommunityPermission, rhs: CommunityPermission) -> CommunityPermission {
lhs | rhs
}
/// Check if the given `input` contains the given [`JournalPermission`].
/// Check if the given `input` contains the given [`CommunityPermission`].
pub fn check(self, permission: CommunityPermission) -> bool {
if (self & CommunityPermission::ADMINISTRATOR) == CommunityPermission::ADMINISTRATOR {
// has administrator permission, meaning everything else is automatically true
return true;
} else if (self & CommunityPermission::BANNED) == CommunityPermission::BANNED {
} else if self.check_banned() {
// has banned permission, meaning everything else is automatically false
return false;
}
@ -98,15 +98,20 @@ impl CommunityPermission {
(self & permission) == permission
}
/// Check if the given [`JournalPermission`] qualifies as "Member" status.
/// Check if the given [`CommunityPermission`] qualifies as "Member" status.
pub fn check_member(self) -> bool {
self.check(CommunityPermission::MEMBER)
}
/// Check if the given [`JournalPermission`] qualifies as "Moderator" status.
/// Check if the given [`CommunityPermission`] qualifies as "Moderator" status.
pub fn check_moderator(self) -> bool {
self.check(CommunityPermission::MANAGE_POSTS)
}
/// Check if the given [`CommunityPermission`] qualifies as "Banned" status.
pub fn check_banned(self) -> bool {
(self & CommunityPermission::BANNED) == CommunityPermission::BANNED
}
}
impl Default for CommunityPermission {