208 lines
4.3 KiB
Rust
208 lines
4.3 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
pub enum Role {
|
|
User,
|
|
Admin,
|
|
}
|
|
|
|
impl Role {
|
|
pub fn as_str(&self) -> &'static str {
|
|
match self {
|
|
Role::User => "user",
|
|
Role::Admin => "admin",
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<&str> for Role {
|
|
fn from(s: &str) -> Self {
|
|
match s {
|
|
"admin" => Role::Admin,
|
|
_ => Role::User,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum MediaMetadataSource {
|
|
Exif,
|
|
TrackInfo,
|
|
}
|
|
|
|
impl MediaMetadataSource {
|
|
pub fn as_str(&self) -> &'static str {
|
|
match self {
|
|
MediaMetadataSource::Exif => "exif",
|
|
MediaMetadataSource::TrackInfo => "track_info",
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<&str> for MediaMetadataSource {
|
|
fn from(s: &str) -> Self {
|
|
match s {
|
|
"track_info" => MediaMetadataSource::TrackInfo,
|
|
_ => MediaMetadataSource::Exif,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct Media {
|
|
pub id: uuid::Uuid,
|
|
pub owner_id: uuid::Uuid,
|
|
pub storage_path: String,
|
|
pub original_filename: String,
|
|
pub mime_type: String,
|
|
pub hash: String,
|
|
pub created_at: chrono::DateTime<chrono::Utc>,
|
|
pub thumbnail_path: Option<String>,
|
|
pub date_taken: Option<chrono::DateTime<chrono::Utc>>,
|
|
}
|
|
|
|
pub struct MediaMetadata {
|
|
pub id: uuid::Uuid,
|
|
pub media_id: uuid::Uuid,
|
|
pub source: MediaMetadataSource,
|
|
pub tag_name: String,
|
|
pub tag_value: String,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct User {
|
|
pub id: uuid::Uuid,
|
|
pub username: String,
|
|
pub email: String,
|
|
pub hashed_password: String,
|
|
pub created_at: chrono::DateTime<chrono::Utc>,
|
|
pub updated_at: chrono::DateTime<chrono::Utc>,
|
|
|
|
pub role: Role,
|
|
pub storage_quota: i64, // in bytes
|
|
pub storage_used: i64, // in bytes
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct Album {
|
|
pub id: uuid::Uuid,
|
|
pub owner_id: uuid::Uuid,
|
|
pub name: String,
|
|
pub description: Option<String>,
|
|
pub is_public: bool,
|
|
pub created_at: chrono::DateTime<chrono::Utc>,
|
|
pub updated_at: chrono::DateTime<chrono::Utc>,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct Person {
|
|
pub id: uuid::Uuid,
|
|
pub owner_id: uuid::Uuid,
|
|
pub name: String,
|
|
pub thumbnail_media_id: Option<uuid::Uuid>,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct FaceRegion {
|
|
pub id: uuid::Uuid,
|
|
pub media_id: uuid::Uuid,
|
|
pub person_id: Option<uuid::Uuid>,
|
|
|
|
pub x_min: f32,
|
|
pub y_min: f32,
|
|
pub x_max: f32,
|
|
pub y_max: f32,
|
|
}
|
|
|
|
pub struct AlbumMedia {
|
|
pub album_id: uuid::Uuid,
|
|
pub media_id: uuid::Uuid,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum AlbumPermission {
|
|
View,
|
|
Contribute,
|
|
}
|
|
|
|
impl AlbumPermission {
|
|
pub fn as_str(&self) -> &'static str {
|
|
match self {
|
|
AlbumPermission::View => "view",
|
|
AlbumPermission::Contribute => "contribute",
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<&str> for AlbumPermission {
|
|
fn from(s: &str) -> Self {
|
|
match s {
|
|
"contribute" => AlbumPermission::Contribute,
|
|
_ => AlbumPermission::View,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct AlbumShare {
|
|
pub album_id: uuid::Uuid,
|
|
pub user_id: uuid::Uuid,
|
|
pub permission: AlbumPermission,
|
|
}
|
|
|
|
pub struct PublicAlbumBundle {
|
|
pub album: Album,
|
|
pub media: Vec<Media>,
|
|
}
|
|
|
|
pub struct MediaBundle {
|
|
pub media: Media,
|
|
pub metadata: Vec<MediaMetadata>,
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct Tag {
|
|
pub id: uuid::Uuid,
|
|
pub name: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum PersonPermission {
|
|
View,
|
|
CanUse,
|
|
}
|
|
|
|
impl PersonPermission {
|
|
pub fn as_str(&self) -> &'static str {
|
|
match self {
|
|
PersonPermission::View => "view",
|
|
PersonPermission::CanUse => "can_use",
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<&str> for PersonPermission {
|
|
fn from(s: &str) -> Self {
|
|
match s {
|
|
"can_use" => PersonPermission::CanUse,
|
|
_ => PersonPermission::View,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct PersonShare {
|
|
pub person_id: uuid::Uuid,
|
|
pub user_id: uuid::Uuid,
|
|
pub permission: PersonPermission,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct FaceEmbedding {
|
|
pub id: uuid::Uuid,
|
|
pub face_region_id: uuid::Uuid,
|
|
pub model_id: i16,
|
|
pub embedding: Vec<u8>,
|
|
}
|