chore: bump deps; fix clippy lints & cleanup
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I4c4815ad145650a07f108614034d2e996a6a6964
This commit is contained in:
parent
c535650f45
commit
cd1161ee5d
41 changed files with 1283 additions and 740 deletions
|
|
@ -12,13 +12,14 @@ use chrono::{DateTime, Utc};
|
|||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{model::MediaId, users::UserId};
|
||||
use crate::{error::PinakesError, model::MediaId, users::UserId};
|
||||
|
||||
/// Unique identifier for a share.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct ShareId(pub Uuid);
|
||||
|
||||
impl ShareId {
|
||||
/// Creates a new share ID.
|
||||
pub fn new() -> Self {
|
||||
Self(Uuid::now_v7())
|
||||
}
|
||||
|
|
@ -47,6 +48,7 @@ pub enum ShareTarget {
|
|||
}
|
||||
|
||||
impl ShareTarget {
|
||||
/// Returns the type of target being shared.
|
||||
pub fn target_type(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Media { .. } => "media",
|
||||
|
|
@ -56,6 +58,7 @@ impl ShareTarget {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the ID of the target being shared.
|
||||
pub fn target_id(&self) -> Uuid {
|
||||
match self {
|
||||
Self::Media { media_id } => media_id.0,
|
||||
|
|
@ -87,6 +90,7 @@ pub enum ShareRecipient {
|
|||
}
|
||||
|
||||
impl ShareRecipient {
|
||||
/// Returns the type of recipient.
|
||||
pub fn recipient_type(&self) -> &'static str {
|
||||
match self {
|
||||
Self::PublicLink { .. } => "public_link",
|
||||
|
|
@ -117,7 +121,7 @@ pub struct SharePermissions {
|
|||
}
|
||||
|
||||
impl SharePermissions {
|
||||
/// View-only permissions
|
||||
/// Creates a new share with view-only permissions.
|
||||
pub fn view_only() -> Self {
|
||||
Self {
|
||||
can_view: true,
|
||||
|
|
@ -125,7 +129,7 @@ impl SharePermissions {
|
|||
}
|
||||
}
|
||||
|
||||
/// Download permissions (includes view)
|
||||
/// Creates a new share with download permissions.
|
||||
pub fn download() -> Self {
|
||||
Self {
|
||||
can_view: true,
|
||||
|
|
@ -134,7 +138,7 @@ impl SharePermissions {
|
|||
}
|
||||
}
|
||||
|
||||
/// Edit permissions (includes view and download)
|
||||
/// Creates a new share with edit permissions.
|
||||
pub fn edit() -> Self {
|
||||
Self {
|
||||
can_view: true,
|
||||
|
|
@ -145,7 +149,7 @@ impl SharePermissions {
|
|||
}
|
||||
}
|
||||
|
||||
/// Full permissions
|
||||
/// Creates a new share with full permissions.
|
||||
pub fn full() -> Self {
|
||||
Self {
|
||||
can_view: true,
|
||||
|
|
@ -157,7 +161,7 @@ impl SharePermissions {
|
|||
}
|
||||
}
|
||||
|
||||
/// Merge permissions (takes the most permissive of each)
|
||||
/// Merges two permission sets, taking the most permissive values.
|
||||
pub fn merge(&self, other: &Self) -> Self {
|
||||
Self {
|
||||
can_view: self.can_view || other.can_view,
|
||||
|
|
@ -246,17 +250,17 @@ impl Share {
|
|||
}
|
||||
}
|
||||
|
||||
/// Check if the share has expired.
|
||||
/// Checks if the share has expired.
|
||||
pub fn is_expired(&self) -> bool {
|
||||
self.expires_at.map(|exp| exp < Utc::now()).unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Check if this is a public link share.
|
||||
/// Checks if this is a public link share.
|
||||
pub fn is_public(&self) -> bool {
|
||||
matches!(self.recipient, ShareRecipient::PublicLink { .. })
|
||||
}
|
||||
|
||||
/// Get the public token if this is a public link share.
|
||||
/// Returns the public token if this is a public link share.
|
||||
pub fn public_token(&self) -> Option<&str> {
|
||||
match &self.recipient {
|
||||
ShareRecipient::PublicLink { token, .. } => Some(token),
|
||||
|
|
@ -322,6 +326,7 @@ pub struct ShareActivity {
|
|||
}
|
||||
|
||||
impl ShareActivity {
|
||||
/// Creates a new share activity entry.
|
||||
pub fn new(share_id: ShareId, action: ShareActivityAction) -> Self {
|
||||
Self {
|
||||
id: Uuid::now_v7(),
|
||||
|
|
@ -334,16 +339,19 @@ impl ShareActivity {
|
|||
}
|
||||
}
|
||||
|
||||
/// Sets the actor who performed the activity.
|
||||
pub fn with_actor(mut self, actor_id: UserId) -> Self {
|
||||
self.actor_id = Some(actor_id);
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the IP address of the actor.
|
||||
pub fn with_ip(mut self, ip: &str) -> Self {
|
||||
self.actor_ip = Some(ip.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets additional details about the activity.
|
||||
pub fn with_details(mut self, details: &str) -> Self {
|
||||
self.details = Some(details.to_string());
|
||||
self
|
||||
|
|
@ -400,6 +408,7 @@ pub struct ShareNotification {
|
|||
}
|
||||
|
||||
impl ShareNotification {
|
||||
/// Creates a new share notification.
|
||||
pub fn new(
|
||||
user_id: UserId,
|
||||
share_id: ShareId,
|
||||
|
|
@ -416,20 +425,18 @@ impl ShareNotification {
|
|||
}
|
||||
}
|
||||
|
||||
/// Generate a random share token using UUID.
|
||||
/// Generates a random share token.
|
||||
pub fn generate_share_token() -> String {
|
||||
// Use UUIDv4 for random tokens - simple string representation
|
||||
Uuid::new_v4().simple().to_string()
|
||||
}
|
||||
|
||||
/// Hash a share password.
|
||||
pub fn hash_share_password(password: &str) -> String {
|
||||
// Use BLAKE3 for password hashing (in production, use Argon2)
|
||||
blake3::hash(password.as_bytes()).to_hex().to_string()
|
||||
/// Hashes a share password using Argon2id.
|
||||
pub fn hash_share_password(password: &str) -> Result<String, PinakesError> {
|
||||
crate::users::auth::hash_password(password)
|
||||
}
|
||||
|
||||
/// Verify a share password.
|
||||
/// Verifies a share password against an Argon2id hash.
|
||||
pub fn verify_share_password(password: &str, hash: &str) -> bool {
|
||||
let computed = hash_share_password(password);
|
||||
computed == hash
|
||||
crate::users::auth::verify_password(password, hash).unwrap_or(false)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue