fix blog without image
This commit is contained in:
@@ -85,7 +85,7 @@ pub async fn create_post(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let images = extract_images(&payload.content);
|
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(
|
return Err(AppError::BadRequest(
|
||||||
"A gallery entry must include at least one image ( in the markdown body)."
|
"A gallery entry must include at least one image ( in the markdown body)."
|
||||||
.to_string(),
|
.to_string(),
|
||||||
|
|||||||
+21
-2
@@ -20,7 +20,7 @@ use tower_http::{
|
|||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
|
|
||||||
use crate::handlers::contact::RATE_LIMIT_WINDOW_MS;
|
use crate::handlers::contact::RATE_LIMIT_WINDOW_MS;
|
||||||
use crate::models::{ImageDim, PostInfo};
|
use crate::models::{ImageDim, PostInfo, SiteMode};
|
||||||
|
|
||||||
pub struct CachedPost {
|
pub struct CachedPost {
|
||||||
pub info: PostInfo,
|
pub info: PostInfo,
|
||||||
@@ -31,6 +31,7 @@ pub struct AppState {
|
|||||||
pub admin_token: String,
|
pub admin_token: String,
|
||||||
pub data_dir: PathBuf,
|
pub data_dir: PathBuf,
|
||||||
pub cookie_secure: bool,
|
pub cookie_secure: bool,
|
||||||
|
pub site_mode: SiteMode,
|
||||||
pub post_lock: Mutex<()>,
|
pub post_lock: Mutex<()>,
|
||||||
pub posts_cache: RwLock<Vec<CachedPost>>,
|
pub posts_cache: RwLock<Vec<CachedPost>>,
|
||||||
pub image_dims_cache: RwLock<HashMap<String, ImageDim>>,
|
pub image_dims_cache: RwLock<HashMap<String, ImageDim>>,
|
||||||
@@ -55,8 +56,25 @@ async fn main() {
|
|||||||
let cookie_secure = env::var("COOKIE_SECURE")
|
let cookie_secure = env::var("COOKIE_SECURE")
|
||||||
.map(|v| v != "false" && v != "0")
|
.map(|v| v != "false" && v != "0")
|
||||||
.unwrap_or(true);
|
.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 posts_dir = data_dir.join("posts");
|
||||||
let uploads_dir = data_dir.join("uploads");
|
let uploads_dir = data_dir.join("uploads");
|
||||||
@@ -71,6 +89,7 @@ async fn main() {
|
|||||||
admin_token,
|
admin_token,
|
||||||
data_dir,
|
data_dir,
|
||||||
cookie_secure,
|
cookie_secure,
|
||||||
|
site_mode,
|
||||||
post_lock: Mutex::new(()),
|
post_lock: Mutex::new(()),
|
||||||
posts_cache: RwLock::new(Vec::new()),
|
posts_cache: RwLock::new(Vec::new()),
|
||||||
image_dims_cache: RwLock::new(HashMap::new()),
|
image_dims_cache: RwLock::new(HashMap::new()),
|
||||||
|
|||||||
@@ -2,6 +2,19 @@ use chrono::NaiveDate;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
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)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct ContactLink {
|
pub struct ContactLink {
|
||||||
pub kind: String,
|
pub kind: String,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ services:
|
|||||||
- DATA_DIR=/app/data
|
- DATA_DIR=/app/data
|
||||||
- COOKIE_SECURE=${COOKIE_SECURE:-true}
|
- COOKIE_SECURE=${COOKIE_SECURE:-true}
|
||||||
- FRONTEND_ORIGIN=${FRONTEND_ORIGIN:-}
|
- FRONTEND_ORIGIN=${FRONTEND_ORIGIN:-}
|
||||||
|
- SITE_MODE=${SITE_MODE:-atelier}
|
||||||
- RUST_LOG=${RUST_LOG:-info}
|
- RUST_LOG=${RUST_LOG:-info}
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
networks:
|
networks:
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export function usePostMeta({ editSlug, getContent, setContent, mode = 'atelier'
|
|||||||
notify('Title, slug, and body are required.', 'error');
|
notify('Title, slug, and body are required.', 'error');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!/!\[[^\]]*\]\([^)]+\)/.test(content)) {
|
if (mode === 'atelier' && !/!\[[^\]]*\]\([^)]+\)/.test(content)) {
|
||||||
notify(
|
notify(
|
||||||
'Add at least one image before saving — drag, paste, or use the Add image button.',
|
'Add at least one image before saving — drag, paste, or use the Add image button.',
|
||||||
'error',
|
'error',
|
||||||
|
|||||||
Reference in New Issue
Block a user