108 lines
2.4 KiB
Rust
108 lines
2.4 KiB
Rust
use chrono::{serde::*, DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
use sqlx::{types::Json, FromRow};
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Deserialize, Serialize, FromRow)]
|
|
pub struct Site {
|
|
/// Site internal ID
|
|
pub id: Uuid,
|
|
|
|
/// Site owner (user)
|
|
pub owner: Uuid,
|
|
|
|
/// Site name (unique per instance, shows up in URLs)
|
|
pub name: String,
|
|
|
|
/// Site's displayed name
|
|
pub title: String,
|
|
|
|
/// Site description (like a user's bio)
|
|
pub description: Option<String>,
|
|
|
|
/// Times
|
|
#[serde(with = "ts_seconds")]
|
|
pub created_at: DateTime<Utc>,
|
|
#[serde(with = "ts_seconds_option")]
|
|
pub modified_at: Option<DateTime<Utc>>,
|
|
#[serde(with = "ts_seconds_option")]
|
|
pub deleted_at: Option<DateTime<Utc>>,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize, FromRow)]
|
|
pub struct Page {
|
|
/// Page ID
|
|
pub id: Uuid,
|
|
|
|
/// Site ID
|
|
pub site: Uuid,
|
|
|
|
/// Author ID
|
|
pub author: Uuid,
|
|
|
|
/// URL-friendly short code for the page
|
|
pub slug: String,
|
|
|
|
/// Page title
|
|
pub title: String,
|
|
|
|
/// Page description (for SEO/content)
|
|
pub description: Option<String>,
|
|
|
|
/// Page tags (for internal search)
|
|
pub tags: Vec<String>,
|
|
|
|
/// Page blocks (content)
|
|
pub blocks: Json<Vec<PageBlock>>,
|
|
|
|
/// Times
|
|
#[serde(with = "ts_seconds")]
|
|
pub created_at: DateTime<Utc>,
|
|
#[serde(with = "ts_seconds_option")]
|
|
pub modified_at: Option<DateTime<Utc>>,
|
|
#[serde(with = "ts_seconds_option")]
|
|
pub deleted_at: Option<DateTime<Utc>>,
|
|
}
|
|
|
|
#[derive(Deserialize, Serialize)]
|
|
pub enum PageBlock {
|
|
Markup(MarkupBlock),
|
|
Gallery(GalleryBlock),
|
|
}
|
|
|
|
/// A block of content in written form (probably Markdown)
|
|
#[derive(Deserialize, Serialize)]
|
|
pub struct MarkupBlock {
|
|
/// Markup format (markdown, html, plain)
|
|
pub format: String,
|
|
|
|
/// Markup content (before rendering)
|
|
pub content: String,
|
|
}
|
|
|
|
/// A block containing one or more images
|
|
#[derive(Deserialize, Serialize)]
|
|
pub struct GalleryBlock {
|
|
/// Images in the gallery
|
|
pub images: Vec<ImageElement>,
|
|
}
|
|
|
|
/// Picture inside a gallery
|
|
#[derive(Deserialize, Serialize)]
|
|
pub struct ImageElement {
|
|
/// URL of the picture
|
|
pub url: String,
|
|
|
|
/// Image width in pixels
|
|
pub width: i32,
|
|
|
|
/// Image height in pixels
|
|
pub height: i32,
|
|
|
|
/// List of thumbnails, if available
|
|
pub thumbnails: Vec<ImageElement>,
|
|
|
|
/// Optional caption to put near the image
|
|
pub caption: Option<String>,
|
|
}
|