fix blog without image
This commit is contained in:
@@ -85,7 +85,7 @@ pub async fn create_post(
|
||||
}
|
||||
|
||||
let images = extract_images(&payload.content);
|
||||
if images.is_empty() {
|
||||
if images.is_empty() && state.site_mode == crate::models::SiteMode::Atelier {
|
||||
return Err(AppError::BadRequest(
|
||||
"A gallery entry must include at least one image ( in the markdown body)."
|
||||
.to_string(),
|
||||
|
||||
+21
-2
@@ -20,7 +20,7 @@ use tower_http::{
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
use crate::handlers::contact::RATE_LIMIT_WINDOW_MS;
|
||||
use crate::models::{ImageDim, PostInfo};
|
||||
use crate::models::{ImageDim, PostInfo, SiteMode};
|
||||
|
||||
pub struct CachedPost {
|
||||
pub info: PostInfo,
|
||||
@@ -31,6 +31,7 @@ pub struct AppState {
|
||||
pub admin_token: String,
|
||||
pub data_dir: PathBuf,
|
||||
pub cookie_secure: bool,
|
||||
pub site_mode: SiteMode,
|
||||
pub post_lock: Mutex<()>,
|
||||
pub posts_cache: RwLock<Vec<CachedPost>>,
|
||||
pub image_dims_cache: RwLock<HashMap<String, ImageDim>>,
|
||||
@@ -55,8 +56,25 @@ async fn main() {
|
||||
let cookie_secure = env::var("COOKIE_SECURE")
|
||||
.map(|v| v != "false" && v != "0")
|
||||
.unwrap_or(true);
|
||||
let site_mode = env::var("SITE_MODE")
|
||||
.map(|v| {
|
||||
if v.to_lowercase() == "blog" {
|
||||
SiteMode::Blog
|
||||
} else {
|
||||
SiteMode::Atelier
|
||||
}
|
||||
})
|
||||
.unwrap_or(SiteMode::Atelier);
|
||||
|
||||
info!("Initializing backend with data dir: {:?}", data_dir);
|
||||
info!(
|
||||
"Initializing backend with data dir: {:?}, mode: {:?}",
|
||||
data_dir,
|
||||
if site_mode == SiteMode::Blog {
|
||||
"blog"
|
||||
} else {
|
||||
"atelier"
|
||||
}
|
||||
);
|
||||
|
||||
let posts_dir = data_dir.join("posts");
|
||||
let uploads_dir = data_dir.join("uploads");
|
||||
@@ -71,6 +89,7 @@ async fn main() {
|
||||
admin_token,
|
||||
data_dir,
|
||||
cookie_secure,
|
||||
site_mode,
|
||||
post_lock: Mutex::new(()),
|
||||
posts_cache: RwLock::new(Vec::new()),
|
||||
image_dims_cache: RwLock::new(HashMap::new()),
|
||||
|
||||
@@ -2,6 +2,19 @@ use chrono::NaiveDate;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum SiteMode {
|
||||
Blog,
|
||||
Atelier,
|
||||
}
|
||||
|
||||
impl Default for SiteMode {
|
||||
fn default() -> Self {
|
||||
Self::Atelier
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct ContactLink {
|
||||
pub kind: String,
|
||||
|
||||
Reference in New Issue
Block a user