picox/src/model/image.rs

56 lines
1.2 KiB
Rust

use std::path::PathBuf;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum StorageLocation {
FileStore {path: PathBuf},
Link
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Image {
pub filename: String,
pub tags: Vec<String>,
pub create_date: DateTime<Utc>,
pub link: String,
pub created_by: u64,
pub storage_location: StorageLocation,
id: Option<u64>
}
impl Image {
pub fn new(filename: &str, tags: Vec<String>, link: Url, created_by: u64, storage_location: StorageLocation) -> Self {
Self {
filename: filename.to_string(),
tags,
create_date: Utc::now(),
link: link.to_string(),
created_by,
storage_location,
id: None,
}
}
}
impl j_db::model::JdbModel for Image {
fn id(&self) -> Option<u64> {
self.id
}
fn set_id(&mut self, id: u64) {
self.id = Some(id)
}
fn tree() -> String {
"Image".to_string()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ImageData {
Bytes(Vec<u8>),
Link(String)
}