Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79c287eaa0 | ||
|
|
cec96cab1e | ||
|
|
a9188f919b | ||
|
|
0edb8c12aa | ||
|
|
15c9528f47 | ||
|
|
9ee5048a43 | ||
|
|
2d43600066 | ||
|
|
d6e6075469 | ||
|
|
289b1e8d37 | ||
|
|
c4823b7e64 |
Generated
+1449
-126
File diff suppressed because it is too large
Load Diff
+6
-2
@@ -1,7 +1,8 @@
|
||||
[package]
|
||||
name = "web-petting"
|
||||
version = "1.0.2"
|
||||
version = "1.0.5"
|
||||
edition = "2024"
|
||||
default-run = "web-petting"
|
||||
|
||||
[dependencies]
|
||||
cot = { version = "0.6.0", default-features = false, features = ["postgres", "json"] }
|
||||
@@ -15,9 +16,12 @@ serde_json = "1"
|
||||
multer = "3"
|
||||
futures = "0.3"
|
||||
image = { version = "0.25", default-features = false, features = ["jpeg", "png", "webp"] }
|
||||
tokio = { version = "1", features = ["fs"] }
|
||||
tokio = { version = "1", features = ["fs", "process", "rt-multi-thread"] }
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
base64 = "0.22"
|
||||
urlencoding = "2"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
web-push-native = "0.5"
|
||||
async-trait = "0.1"
|
||||
aws-sdk-s3 = { version = "1", default-features = false, features = ["rustls", "rt-tokio"] }
|
||||
|
||||
+5
-3
@@ -1,16 +1,18 @@
|
||||
FROM rust:1-slim AS builder
|
||||
FROM rust:1-slim-bookworm AS builder
|
||||
RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /app
|
||||
COPY Cargo.toml Cargo.lock* ./
|
||||
COPY src ./src
|
||||
COPY templates ./templates
|
||||
RUN cargo build --release
|
||||
RUN cargo build --release --bins
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||
RUN apt-get update && apt-get install -y ca-certificates ffmpeg && rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /data
|
||||
ENV WEB_PETTING_UPLOAD_DIR=/data/uploads
|
||||
COPY --from=builder /app/target/release/web-petting /usr/local/bin/web-petting
|
||||
COPY --from=builder /app/target/release/migrate_uploads_to_r2 /usr/local/bin/migrate_uploads_to_r2
|
||||
COPY --from=builder /app/target/release/normalize_videos_to_r2 /usr/local/bin/normalize_videos_to_r2
|
||||
COPY static /app/static
|
||||
EXPOSE 3000
|
||||
CMD ["web-petting"]
|
||||
|
||||
+534
-65
@@ -13,9 +13,10 @@ use image::codecs::jpeg::JpegEncoder;
|
||||
use image::imageops::FilterType;
|
||||
use serde::Deserialize;
|
||||
use std::io::Cursor;
|
||||
use std::ops::Deref;
|
||||
|
||||
use crate::i18n::{Lang, Translations};
|
||||
use crate::models::{Client, Lead, Media, Setting, Testimonial, User, Visit};
|
||||
use crate::models::{Client, Lead, Media, PushSubscription, Setting, Testimonial, User, Visit};
|
||||
use crate::telegram;
|
||||
|
||||
const SESSION_USER_ID: &str = "user_id";
|
||||
@@ -145,6 +146,7 @@ fn transcode_uploaded_image(data: &[u8], ext: &str) -> cot::Result<Option<Vec<u8
|
||||
}
|
||||
|
||||
async fn save_uploaded_image(
|
||||
storage: &crate::uploads::Storage,
|
||||
upload_dir: &str,
|
||||
file_id: uuid::Uuid,
|
||||
ext: &str,
|
||||
@@ -152,15 +154,20 @@ async fn save_uploaded_image(
|
||||
) -> cot::Result<String> {
|
||||
if let Some(encoded) = transcode_uploaded_image(data, ext)? {
|
||||
let path = crate::uploads::join_db_path(upload_dir, &format!("{file_id}.jpg"));
|
||||
crate::uploads::write_db_file(&path, &encoded)
|
||||
storage
|
||||
.write(&path, &encoded)
|
||||
.await
|
||||
.map_err(|e| cot::Error::internal(e.to_string()))?;
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
crate::uploads::write_thumbnail(storage, &path, &encoded)
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
Ok(path)
|
||||
} else {
|
||||
let path = crate::uploads::join_db_path(upload_dir, &format!("{file_id}.{ext}"));
|
||||
crate::uploads::write_db_file(&path, data)
|
||||
storage
|
||||
.write(&path, data)
|
||||
.await
|
||||
.map_err(|e| cot::Error::internal(e.to_string()))?;
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
Ok(path)
|
||||
}
|
||||
}
|
||||
@@ -334,8 +341,80 @@ struct SettingsTemplate<'a> {
|
||||
admin_name: &'a str,
|
||||
settings: Vec<Setting>,
|
||||
saved: bool,
|
||||
error: Option<&'a str>,
|
||||
auth_password_checked: bool,
|
||||
auth_sso_checked: bool,
|
||||
client_notifications_checked: bool,
|
||||
r2_enabled_checked: bool,
|
||||
telegram_bot_token_configured: bool,
|
||||
turnstile_secret_configured: bool,
|
||||
oidc_client_secret_configured: bool,
|
||||
vapid_private_key_configured: bool,
|
||||
r2_secret_configured: bool,
|
||||
push_subscribers: Vec<PushSubscriberItem>,
|
||||
}
|
||||
|
||||
fn setting_has_value(settings: &[Setting], key: &str) -> bool {
|
||||
settings
|
||||
.iter()
|
||||
.find(|setting| setting.key == key)
|
||||
.is_some_and(|setting| !setting.value.trim().is_empty())
|
||||
}
|
||||
|
||||
fn preserved_secret_value(old_value: &str, submitted: &str, clear: bool) -> String {
|
||||
if !submitted.trim().is_empty() {
|
||||
submitted.trim().to_string()
|
||||
} else if clear {
|
||||
String::new()
|
||||
} else {
|
||||
old_value.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct PushSubscriberItem {
|
||||
client_name: String,
|
||||
device_count: usize,
|
||||
languages: String,
|
||||
last_updated: String,
|
||||
}
|
||||
|
||||
async fn load_push_subscribers(db: &Database) -> cot::Result<Vec<PushSubscriberItem>> {
|
||||
let clients = Client::objects().all(db).await?;
|
||||
let subscriptions = PushSubscription::objects().all(db).await?;
|
||||
let mut items = Vec::new();
|
||||
for client in clients {
|
||||
let client_id = client.id.unwrap();
|
||||
let active: Vec<_> = subscriptions
|
||||
.iter()
|
||||
.filter(|subscription| {
|
||||
subscription.status == "active"
|
||||
&& subscription.client_id.primary_key().unwrap() == client_id
|
||||
})
|
||||
.collect();
|
||||
if active.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut languages: Vec<&str> = active
|
||||
.iter()
|
||||
.map(|subscription| subscription.language.as_str())
|
||||
.collect();
|
||||
languages.sort_unstable();
|
||||
languages.dedup();
|
||||
let last_updated = active
|
||||
.iter()
|
||||
.map(|subscription| subscription.updated_at)
|
||||
.max()
|
||||
.unwrap();
|
||||
items.push(PushSubscriberItem {
|
||||
client_name: client.name,
|
||||
device_count: active.len(),
|
||||
languages: languages.join(", "),
|
||||
last_updated: last_updated.format("%d.%m.%Y %H:%M").to_string(),
|
||||
});
|
||||
}
|
||||
items.sort_by(|a, b| a.client_name.cmp(&b.client_name));
|
||||
Ok(items)
|
||||
}
|
||||
|
||||
#[derive(Debug, Template)]
|
||||
@@ -368,12 +447,27 @@ struct ScheduleEditTemplate<'a> {
|
||||
visit: Visit,
|
||||
client: Client,
|
||||
users: Vec<User>,
|
||||
media: Vec<Media>,
|
||||
media: Vec<MediaView>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct MediaView {
|
||||
media: Media,
|
||||
url: String,
|
||||
thumbnail_url: String,
|
||||
}
|
||||
|
||||
impl Deref for MediaView {
|
||||
type Target = Media;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.media
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct MediaItem {
|
||||
media: Media,
|
||||
media: MediaView,
|
||||
client_name: String,
|
||||
visit_date: Option<String>,
|
||||
}
|
||||
@@ -387,6 +481,8 @@ struct MediaTemplate<'a> {
|
||||
items: Vec<MediaItem>,
|
||||
clients: Vec<Client>,
|
||||
filter_client_id: i64,
|
||||
page: usize,
|
||||
total_pages: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Template)]
|
||||
@@ -400,6 +496,37 @@ struct MediaUploadTemplate<'a> {
|
||||
visit_label: &'a str,
|
||||
}
|
||||
|
||||
async fn admin_media_view(
|
||||
storage: &crate::uploads::Storage,
|
||||
media: Media,
|
||||
) -> cot::Result<MediaView> {
|
||||
let media_id = media.id.unwrap();
|
||||
let delivery = crate::uploads::media_delivery_paths(&media.file_type, &media.file_path);
|
||||
let url = storage
|
||||
.public_url(&delivery.media_path, format!("/admin/uploads/{media_id}"))
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
let thumbnail_fallback = format!("/admin/uploads/{media_id}/thumbnail");
|
||||
let thumbnail_url = if storage.is_r2()
|
||||
&& storage
|
||||
.exists(&delivery.thumbnail_path)
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?
|
||||
{
|
||||
storage
|
||||
.public_url(&delivery.thumbnail_path, thumbnail_fallback)
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?
|
||||
} else {
|
||||
thumbnail_fallback
|
||||
};
|
||||
Ok(MediaView {
|
||||
media,
|
||||
url,
|
||||
thumbnail_url,
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Auth Handlers
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -1196,14 +1323,39 @@ async fn settings_page(request: Request, session: Session, db: Database) -> cot:
|
||||
.find(|s| s.key == "auth_sso_enabled")
|
||||
.map(|s| s.value == "true")
|
||||
.unwrap_or(false);
|
||||
let client_notifications_checked = settings
|
||||
.iter()
|
||||
.find(|s| s.key == "client_notifications_enabled")
|
||||
.map(|s| s.value == "true")
|
||||
.unwrap_or(false);
|
||||
let r2_enabled_checked = settings
|
||||
.iter()
|
||||
.find(|setting| setting.key == crate::uploads::R2_ENABLED_KEY)
|
||||
.map(|setting| setting.value == "true")
|
||||
.unwrap_or(false);
|
||||
let telegram_bot_token_configured = setting_has_value(&settings, "telegram_bot_token");
|
||||
let turnstile_secret_configured = setting_has_value(&settings, "turnstile_secret_key");
|
||||
let oidc_client_secret_configured = setting_has_value(&settings, "oidc_client_secret");
|
||||
let vapid_private_key_configured = setting_has_value(&settings, "vapid_private_key");
|
||||
let r2_secret_configured =
|
||||
setting_has_value(&settings, crate::uploads::R2_SECRET_ACCESS_KEY_KEY);
|
||||
let body = SettingsTemplate {
|
||||
t: lang.t(),
|
||||
lang,
|
||||
admin_name: &admin_name,
|
||||
settings,
|
||||
saved: false,
|
||||
error: None,
|
||||
auth_password_checked,
|
||||
auth_sso_checked,
|
||||
client_notifications_checked,
|
||||
r2_enabled_checked,
|
||||
telegram_bot_token_configured,
|
||||
turnstile_secret_configured,
|
||||
oidc_client_secret_configured,
|
||||
vapid_private_key_configured,
|
||||
r2_secret_configured,
|
||||
push_subscribers: load_push_subscribers(&db).await?,
|
||||
}
|
||||
.render()?;
|
||||
html_response(body, lang)
|
||||
@@ -1283,10 +1435,31 @@ struct SettingsForm {
|
||||
oidc_client_id: String,
|
||||
oidc_client_secret: String,
|
||||
oidc_allowed_groups: String,
|
||||
vapid_public_key: String,
|
||||
vapid_private_key: String,
|
||||
vapid_subject: String,
|
||||
r2_account_id: String,
|
||||
r2_bucket: String,
|
||||
r2_access_key_id: String,
|
||||
r2_secret_access_key: String,
|
||||
#[serde(default)]
|
||||
clear_telegram_bot_token: Option<String>,
|
||||
#[serde(default)]
|
||||
clear_turnstile_secret_key: Option<String>,
|
||||
#[serde(default)]
|
||||
clear_oidc_client_secret: Option<String>,
|
||||
#[serde(default)]
|
||||
clear_vapid_private_key: Option<String>,
|
||||
#[serde(default)]
|
||||
clear_r2_secret_access_key: Option<String>,
|
||||
#[serde(default)]
|
||||
auth_password_enabled: Option<String>,
|
||||
#[serde(default)]
|
||||
auth_sso_enabled: Option<String>,
|
||||
#[serde(default)]
|
||||
client_notifications_enabled: Option<String>,
|
||||
#[serde(default)]
|
||||
r2_enabled: Option<String>,
|
||||
}
|
||||
|
||||
async fn save_settings(request: Request, session: Session, db: Database) -> cot::Result<Response> {
|
||||
@@ -1296,19 +1469,91 @@ async fn save_settings(request: Request, session: Session, db: Database) -> cot:
|
||||
Err(resp) => return Ok(resp),
|
||||
};
|
||||
|
||||
let old_settings = Setting::objects().all(&db).await?;
|
||||
let old_value = |key: &str| {
|
||||
old_settings
|
||||
.iter()
|
||||
.find(|setting| setting.key == key)
|
||||
.map(|setting| setting.value.as_str())
|
||||
.unwrap_or("")
|
||||
};
|
||||
let telegram_bot_token = preserved_secret_value(
|
||||
old_value("telegram_bot_token"),
|
||||
&form.telegram_bot_token,
|
||||
form.clear_telegram_bot_token.is_some(),
|
||||
);
|
||||
let turnstile_secret_key = preserved_secret_value(
|
||||
old_value("turnstile_secret_key"),
|
||||
&form.turnstile_secret_key,
|
||||
form.clear_turnstile_secret_key.is_some(),
|
||||
);
|
||||
let oidc_client_secret = preserved_secret_value(
|
||||
old_value("oidc_client_secret"),
|
||||
&form.oidc_client_secret,
|
||||
form.clear_oidc_client_secret.is_some(),
|
||||
);
|
||||
let vapid_private_key = preserved_secret_value(
|
||||
old_value("vapid_private_key"),
|
||||
&form.vapid_private_key,
|
||||
form.clear_vapid_private_key.is_some(),
|
||||
);
|
||||
let r2_secret_access_key = preserved_secret_value(
|
||||
old_value(crate::uploads::R2_SECRET_ACCESS_KEY_KEY),
|
||||
&form.r2_secret_access_key,
|
||||
form.clear_r2_secret_access_key.is_some(),
|
||||
);
|
||||
let had_vapid_keys = !old_value("vapid_public_key").trim().is_empty()
|
||||
|| !old_value("vapid_private_key").trim().is_empty();
|
||||
let vapid_keys_changed = had_vapid_keys
|
||||
&& (old_value("vapid_public_key").trim() != form.vapid_public_key.trim()
|
||||
|| old_value("vapid_private_key").trim() != vapid_private_key.trim());
|
||||
let requested_r2_enabled = form.r2_enabled.is_some();
|
||||
let r2_config_valid = crate::uploads::R2Config::fields_are_valid(
|
||||
&form.r2_account_id,
|
||||
&form.r2_bucket,
|
||||
&form.r2_access_key_id,
|
||||
&r2_secret_access_key,
|
||||
);
|
||||
let r2_enabled = requested_r2_enabled && r2_config_valid;
|
||||
let settings_error =
|
||||
(requested_r2_enabled && !r2_config_valid).then_some(lang.t().settings_r2_error_incomplete);
|
||||
|
||||
for (key, value) in [
|
||||
("telegram_bot_token", form.telegram_bot_token),
|
||||
("telegram_bot_token", telegram_bot_token),
|
||||
("contact_info", form.contact_info),
|
||||
("pricing_info", form.pricing_info),
|
||||
("timezone", form.timezone),
|
||||
("site_domain", form.site_domain),
|
||||
("seo_keywords", form.seo_keywords),
|
||||
("turnstile_site_key", form.turnstile_site_key),
|
||||
("turnstile_secret_key", form.turnstile_secret_key),
|
||||
("turnstile_secret_key", turnstile_secret_key),
|
||||
("oidc_issuer_url", form.oidc_issuer_url),
|
||||
("oidc_client_id", form.oidc_client_id),
|
||||
("oidc_client_secret", form.oidc_client_secret),
|
||||
("oidc_client_secret", oidc_client_secret),
|
||||
("oidc_allowed_groups", form.oidc_allowed_groups),
|
||||
("vapid_public_key", form.vapid_public_key),
|
||||
("vapid_private_key", vapid_private_key),
|
||||
("vapid_subject", form.vapid_subject),
|
||||
(
|
||||
crate::uploads::R2_ACCOUNT_ID_KEY,
|
||||
form.r2_account_id.trim().to_ascii_lowercase(),
|
||||
),
|
||||
(
|
||||
crate::uploads::R2_BUCKET_KEY,
|
||||
form.r2_bucket.trim().to_string(),
|
||||
),
|
||||
(
|
||||
crate::uploads::R2_ACCESS_KEY_ID_KEY,
|
||||
form.r2_access_key_id.trim().to_string(),
|
||||
),
|
||||
(
|
||||
crate::uploads::R2_SECRET_ACCESS_KEY_KEY,
|
||||
r2_secret_access_key,
|
||||
),
|
||||
(
|
||||
crate::uploads::R2_ENABLED_KEY,
|
||||
if r2_enabled { "true" } else { "false" }.to_string(),
|
||||
),
|
||||
(
|
||||
"auth_password_enabled",
|
||||
if form.auth_password_enabled.is_some() {
|
||||
@@ -1325,6 +1570,14 @@ async fn save_settings(request: Request, session: Session, db: Database) -> cot:
|
||||
"false".to_string()
|
||||
},
|
||||
),
|
||||
(
|
||||
"client_notifications_enabled",
|
||||
if form.client_notifications_enabled.is_some() {
|
||||
"true".to_string()
|
||||
} else {
|
||||
"false".to_string()
|
||||
},
|
||||
),
|
||||
] {
|
||||
let k = key.to_string();
|
||||
let existing = query!(Setting, $key == k).get(&db).await?;
|
||||
@@ -1346,6 +1599,16 @@ async fn save_settings(request: Request, session: Session, db: Database) -> cot:
|
||||
}
|
||||
}
|
||||
|
||||
if vapid_keys_changed {
|
||||
for mut subscription in PushSubscription::objects().all(&db).await? {
|
||||
if subscription.status == "active" {
|
||||
subscription.status = "archived".to_string();
|
||||
subscription.updated_at = now_utc();
|
||||
subscription.save(&db).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let settings = Setting::objects().all(&db).await?;
|
||||
let auth_password_checked = settings
|
||||
.iter()
|
||||
@@ -1357,14 +1620,39 @@ async fn save_settings(request: Request, session: Session, db: Database) -> cot:
|
||||
.find(|s| s.key == "auth_sso_enabled")
|
||||
.map(|s| s.value == "true")
|
||||
.unwrap_or(false);
|
||||
let client_notifications_checked = settings
|
||||
.iter()
|
||||
.find(|s| s.key == "client_notifications_enabled")
|
||||
.map(|s| s.value == "true")
|
||||
.unwrap_or(false);
|
||||
let r2_enabled_checked = settings
|
||||
.iter()
|
||||
.find(|setting| setting.key == crate::uploads::R2_ENABLED_KEY)
|
||||
.map(|setting| setting.value == "true")
|
||||
.unwrap_or(false);
|
||||
let telegram_bot_token_configured = setting_has_value(&settings, "telegram_bot_token");
|
||||
let turnstile_secret_configured = setting_has_value(&settings, "turnstile_secret_key");
|
||||
let oidc_client_secret_configured = setting_has_value(&settings, "oidc_client_secret");
|
||||
let vapid_private_key_configured = setting_has_value(&settings, "vapid_private_key");
|
||||
let r2_secret_configured =
|
||||
setting_has_value(&settings, crate::uploads::R2_SECRET_ACCESS_KEY_KEY);
|
||||
let rendered = SettingsTemplate {
|
||||
t: lang.t(),
|
||||
lang,
|
||||
admin_name: &admin_name,
|
||||
settings,
|
||||
saved: true,
|
||||
saved: settings_error.is_none(),
|
||||
error: settings_error,
|
||||
auth_password_checked,
|
||||
auth_sso_checked,
|
||||
client_notifications_checked,
|
||||
r2_enabled_checked,
|
||||
telegram_bot_token_configured,
|
||||
turnstile_secret_configured,
|
||||
oidc_client_secret_configured,
|
||||
vapid_private_key_configured,
|
||||
r2_secret_configured,
|
||||
push_subscribers: load_push_subscribers(&db).await?,
|
||||
}
|
||||
.render()?;
|
||||
html_response(rendered, lang)
|
||||
@@ -1857,6 +2145,11 @@ async fn schedule_edit_page(
|
||||
.unwrap_or(false)
|
||||
});
|
||||
visit_media.sort_by(|a, b| a.created_at.cmp(&b.created_at));
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
let mut media_views = Vec::with_capacity(visit_media.len());
|
||||
for media in visit_media {
|
||||
media_views.push(admin_media_view(&storage, media).await?);
|
||||
}
|
||||
let body = ScheduleEditTemplate {
|
||||
t: lang.t(),
|
||||
lang,
|
||||
@@ -1864,7 +2157,7 @@ async fn schedule_edit_page(
|
||||
visit,
|
||||
client,
|
||||
users,
|
||||
media: visit_media,
|
||||
media: media_views,
|
||||
}
|
||||
.render()?;
|
||||
html_response(body, lang)
|
||||
@@ -1895,6 +2188,7 @@ async fn schedule_edit_submit(
|
||||
if visit.status == "deleted" {
|
||||
return Redirect::new(format!("/admin/schedule?lang={}", lang.code())).into_response();
|
||||
}
|
||||
let became_completed = visit.status != "completed" && form.status == "completed";
|
||||
visit.user_id = ForeignKey::PrimaryKey(Auto::fixed(form.user_id));
|
||||
if let Ok(d) = chrono::NaiveDate::parse_from_str(&form.visit_date, "%Y-%m-%d") {
|
||||
visit.visit_date = d;
|
||||
@@ -1906,6 +2200,9 @@ async fn schedule_edit_submit(
|
||||
visit.public_notes = form.public_notes.filter(|s| !s.trim().is_empty());
|
||||
visit.updated_at = now_utc();
|
||||
visit.save(&db).await?;
|
||||
if became_completed {
|
||||
crate::web_push::notify_visit_completed(&db, &visit).await;
|
||||
}
|
||||
}
|
||||
Redirect::new(format!("/admin/schedule?lang={}", lang.code())).into_response()
|
||||
}
|
||||
@@ -1942,9 +2239,13 @@ async fn visit_set_done(
|
||||
if visit.status == "deleted" {
|
||||
return Redirect::new(format!("/admin/schedule?lang={}", lang.code())).into_response();
|
||||
}
|
||||
let became_completed = visit.status != "completed";
|
||||
visit.status = "completed".to_string();
|
||||
visit.updated_at = now_utc();
|
||||
visit.save(&db).await?;
|
||||
if became_completed {
|
||||
crate::web_push::notify_visit_completed(&db, &visit).await;
|
||||
}
|
||||
}
|
||||
Redirect::new(format!("/admin/schedule?lang={}", lang.code())).into_response()
|
||||
}
|
||||
@@ -1975,6 +2276,7 @@ async fn visit_set_cancel(
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async fn media_page(request: Request, session: Session, db: Database) -> cot::Result<Response> {
|
||||
const MEDIA_PER_PAGE: usize = 24;
|
||||
let lang = detect_lang(&request);
|
||||
let admin_name = match require_auth(&session, lang).await {
|
||||
Ok(name) => name,
|
||||
@@ -1991,6 +2293,17 @@ async fn media_page(request: Request, session: Session, db: Database) -> cot::Re
|
||||
.and_then(|v| v.parse().ok())
|
||||
})
|
||||
.unwrap_or(0);
|
||||
let requested_page = request
|
||||
.uri()
|
||||
.query()
|
||||
.and_then(|query| {
|
||||
query
|
||||
.split('&')
|
||||
.find_map(|part| part.strip_prefix("page="))
|
||||
.and_then(|value| value.parse::<usize>().ok())
|
||||
})
|
||||
.unwrap_or(1)
|
||||
.max(1);
|
||||
|
||||
let clients_all = Client::objects().all(&db).await?;
|
||||
let visits_all = Visit::objects().all(&db).await?;
|
||||
@@ -2026,26 +2339,29 @@ async fn media_page(request: Request, session: Session, db: Database) -> cot::Re
|
||||
}
|
||||
media_list.sort_by(|a, b| b.created_at.cmp(&a.created_at));
|
||||
|
||||
let items: Vec<MediaItem> = media_list
|
||||
.into_iter()
|
||||
.map(|m| {
|
||||
let cid: i64 = m.client_id.primary_key().unwrap();
|
||||
let client = clients_all.iter().find(|c| c.id.unwrap() == cid);
|
||||
let visit_date = m
|
||||
.visit_id
|
||||
.as_ref()
|
||||
.and_then(|fk| {
|
||||
let vid: i64 = fk.primary_key().unwrap();
|
||||
visits_all.iter().find(|v| v.id.unwrap() == vid)
|
||||
})
|
||||
.map(|v| v.visit_date.to_string());
|
||||
MediaItem {
|
||||
client_name: client.map(|c| c.name.clone()).unwrap_or_default(),
|
||||
visit_date,
|
||||
media: m,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let total_pages = media_list.len().div_ceil(MEDIA_PER_PAGE).max(1);
|
||||
let page = requested_page.min(total_pages);
|
||||
let page_start = (page - 1) * MEDIA_PER_PAGE;
|
||||
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
let mut items = Vec::new();
|
||||
for media in media_list.into_iter().skip(page_start).take(MEDIA_PER_PAGE) {
|
||||
let cid: i64 = media.client_id.primary_key().unwrap();
|
||||
let client = clients_all.iter().find(|c| c.id.unwrap() == cid);
|
||||
let visit_date = media
|
||||
.visit_id
|
||||
.as_ref()
|
||||
.and_then(|fk| {
|
||||
let vid: i64 = fk.primary_key().unwrap();
|
||||
visits_all.iter().find(|v| v.id.unwrap() == vid)
|
||||
})
|
||||
.map(|v| v.visit_date.to_string());
|
||||
items.push(MediaItem {
|
||||
client_name: client.map(|c| c.name.clone()).unwrap_or_default(),
|
||||
visit_date,
|
||||
media: admin_media_view(&storage, media).await?,
|
||||
});
|
||||
}
|
||||
|
||||
let active_clients = clients_all
|
||||
.into_iter()
|
||||
@@ -2059,6 +2375,8 @@ async fn media_page(request: Request, session: Session, db: Database) -> cot::Re
|
||||
items,
|
||||
clients: active_clients,
|
||||
filter_client_id,
|
||||
page,
|
||||
total_pages,
|
||||
}
|
||||
.render()?;
|
||||
html_response(body, lang)
|
||||
@@ -2140,10 +2458,12 @@ async fn media_upload_submit(
|
||||
futures::stream::once(async move { Result::<_, std::convert::Infallible>::Ok(bytes) });
|
||||
let mut multipart = multer::Multipart::new(stream, boundary);
|
||||
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
let upload_dir = crate::uploads::media_dir(client_id, visit_id);
|
||||
crate::uploads::create_logical_dir(&upload_dir)
|
||||
storage
|
||||
.create_logical_dir(&upload_dir)
|
||||
.await
|
||||
.map_err(|e| cot::Error::internal(e.to_string()))?;
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
|
||||
let mut caption = String::new();
|
||||
let mut saved_files: Vec<(String, String)> = Vec::new(); // (path, file_type)
|
||||
@@ -2191,12 +2511,14 @@ async fn media_upload_submit(
|
||||
continue;
|
||||
}
|
||||
let file_path = if file_type == "photo" {
|
||||
save_uploaded_image(&upload_dir, file_id, &ext, &data).await?
|
||||
save_uploaded_image(&storage, &upload_dir, file_id, &ext, &data).await?
|
||||
} else {
|
||||
let path = crate::uploads::join_db_path(&upload_dir, &format!("{file_id}.{ext}"));
|
||||
crate::uploads::write_db_file(&path, &data)
|
||||
let original_path =
|
||||
crate::uploads::join_db_path(&upload_dir, &format!("{file_id}.{ext}"));
|
||||
let path = crate::uploads::normalized_video_db_path(&original_path);
|
||||
crate::uploads::write_compact_video(&storage, &path, &ext, &data)
|
||||
.await
|
||||
.map_err(|e| cot::Error::internal(e.to_string()))?;
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
path
|
||||
};
|
||||
|
||||
@@ -2247,11 +2569,12 @@ async fn media_delete(
|
||||
.get("referer")
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.map(|s| s.to_string());
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
if let Some(mut m) = query!(Media, $id == media_id).get(&db).await? {
|
||||
let file_path = m.file_path.clone();
|
||||
m.status = "archived".to_string();
|
||||
m.save(&db).await?;
|
||||
if let Err(err) = crate::uploads::remove_db_file(&file_path).await {
|
||||
if let Err(err) = storage.remove(&file_path).await {
|
||||
tracing::warn!(
|
||||
target: "uploads",
|
||||
media_id,
|
||||
@@ -2261,6 +2584,10 @@ async fn media_delete(
|
||||
"failed to remove uploaded file"
|
||||
);
|
||||
}
|
||||
let thumbnail_path = crate::uploads::thumbnail_db_path(&file_path);
|
||||
if let Err(error) = storage.remove(&thumbnail_path).await {
|
||||
tracing::warn!(%error, %thumbnail_path, "failed to remove media thumbnail");
|
||||
}
|
||||
}
|
||||
let redirect_url = referer
|
||||
.filter(|r| r.contains("/schedule/") && r.contains("/edit"))
|
||||
@@ -2268,6 +2595,74 @@ async fn media_delete(
|
||||
Redirect::new(redirect_url).into_response()
|
||||
}
|
||||
|
||||
async fn serve_upload_thumbnail(
|
||||
request: Request,
|
||||
session: Session,
|
||||
db: Database,
|
||||
Path(media_id): Path<i64>,
|
||||
) -> cot::Result<Response> {
|
||||
let lang = detect_lang(&request);
|
||||
if require_auth(&session, lang).await.is_err() {
|
||||
return Redirect::new(format!("/admin/login?lang={}", lang.code())).into_response();
|
||||
}
|
||||
let media = match query!(Media, $id == media_id).get(&db).await? {
|
||||
Some(media) if media.status == "active" => media,
|
||||
_ => return Html::new("404").into_response(),
|
||||
};
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
let display_path = match crate::uploads::ensure_media_delivery_paths(
|
||||
&storage,
|
||||
&media.file_type,
|
||||
&media.file_path,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(paths) => paths.thumbnail_path,
|
||||
Err(error) => {
|
||||
tracing::warn!(media_id, %error, "failed to create media thumbnail");
|
||||
if media.file_type == "photo" {
|
||||
media.file_path.clone()
|
||||
} else {
|
||||
return Html::new("404").into_response();
|
||||
}
|
||||
}
|
||||
};
|
||||
if storage.is_r2() {
|
||||
let url = storage
|
||||
.public_url(&display_path, String::new())
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
return Redirect::new(url).into_response();
|
||||
}
|
||||
let display_content_type = if display_path == media.file_path {
|
||||
crate::uploads::content_type_for_path(&media.file_path)
|
||||
} else {
|
||||
"image/jpeg"
|
||||
};
|
||||
match crate::uploads::ranged_local_file_response(&display_path, display_content_type, None)
|
||||
.await
|
||||
{
|
||||
Ok(path) => {
|
||||
let mut response = path;
|
||||
response.headers_mut().insert(
|
||||
"cache-control",
|
||||
"private, max-age=31536000, immutable".parse().unwrap(),
|
||||
);
|
||||
Ok(response)
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::warn!(media_id, %error, "failed to read media thumbnail");
|
||||
crate::uploads::ranged_local_file_response(
|
||||
&media.file_path,
|
||||
crate::uploads::content_type_for_path(&media.file_path),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|error| cot::Error::internal(error.to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Serve uploaded files by media ID.
|
||||
async fn serve_upload(
|
||||
request: Request,
|
||||
@@ -2291,28 +2686,31 @@ async fn serve_upload(
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.map(str::to_owned);
|
||||
|
||||
match {
|
||||
let content_type = match media.file_path.rsplit('.').next().unwrap_or("") {
|
||||
"jpg" | "jpeg" => "image/jpeg",
|
||||
"png" => "image/png",
|
||||
"heic" | "heif" => "image/heic",
|
||||
"webp" => "image/webp",
|
||||
"mp4" => "video/mp4",
|
||||
"mov" => "video/quicktime",
|
||||
"avi" => "video/x-msvideo",
|
||||
"mkv" => "video/x-matroska",
|
||||
"webm" => "video/webm",
|
||||
_ => "application/octet-stream",
|
||||
};
|
||||
crate::uploads::ranged_file_response(&media.file_path, content_type, range.as_deref()).await
|
||||
} {
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
let display_path =
|
||||
crate::uploads::media_delivery_paths(&media.file_type, &media.file_path).media_path;
|
||||
if storage.is_r2() {
|
||||
let url = storage
|
||||
.public_url(&display_path, String::new())
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
return Redirect::new(url).into_response();
|
||||
}
|
||||
|
||||
match crate::uploads::ranged_local_file_response(
|
||||
&display_path,
|
||||
crate::uploads::content_type_for_path(&display_path),
|
||||
range.as_deref(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(response) => Ok(response),
|
||||
Err(err) => {
|
||||
tracing::warn!(
|
||||
target: "uploads",
|
||||
media_id,
|
||||
db_path = %media.file_path,
|
||||
resolved_path = %crate::uploads::resolved_display_path(&media.file_path),
|
||||
db_path = %display_path,
|
||||
resolved_path = %crate::uploads::resolved_display_path(&display_path),
|
||||
error = %err,
|
||||
"uploaded file is missing or unreadable"
|
||||
);
|
||||
@@ -2331,7 +2729,43 @@ struct TestimonialsTemplate<'a> {
|
||||
t: &'a Translations,
|
||||
lang: Lang,
|
||||
admin_name: String,
|
||||
testimonials: Vec<Testimonial>,
|
||||
testimonials: Vec<TestimonialView>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct TestimonialView {
|
||||
testimonial: Testimonial,
|
||||
image_url: Option<String>,
|
||||
}
|
||||
|
||||
impl Deref for TestimonialView {
|
||||
type Target = Testimonial;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.testimonial
|
||||
}
|
||||
}
|
||||
|
||||
async fn admin_testimonial_view(
|
||||
storage: &crate::uploads::Storage,
|
||||
testimonial: Testimonial,
|
||||
) -> cot::Result<TestimonialView> {
|
||||
let image_url = match testimonial.image_path.as_deref() {
|
||||
Some(path) => Some(
|
||||
storage
|
||||
.public_url(
|
||||
path,
|
||||
format!("/admin/testimonials/{}/image", testimonial.id.unwrap()),
|
||||
)
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?,
|
||||
),
|
||||
None => None,
|
||||
};
|
||||
Ok(TestimonialView {
|
||||
testimonial,
|
||||
image_url,
|
||||
})
|
||||
}
|
||||
|
||||
async fn testimonials_page(
|
||||
@@ -2351,12 +2785,17 @@ async fn testimonials_page(
|
||||
.cmp(&b.sort_order)
|
||||
.then(b.id.unwrap().cmp(&a.id.unwrap()))
|
||||
});
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
let mut testimonial_views = Vec::with_capacity(testimonials.len());
|
||||
for testimonial in testimonials {
|
||||
testimonial_views.push(admin_testimonial_view(&storage, testimonial).await?);
|
||||
}
|
||||
|
||||
let body = TestimonialsTemplate {
|
||||
t: lang.t(),
|
||||
lang,
|
||||
admin_name,
|
||||
testimonials,
|
||||
testimonials: testimonial_views,
|
||||
}
|
||||
.render()?;
|
||||
html_response(body, lang)
|
||||
@@ -2379,6 +2818,7 @@ async fn testimonial_add(
|
||||
let stream =
|
||||
futures::stream::once(async move { Result::<_, std::convert::Infallible>::Ok(bytes) });
|
||||
let mut multipart = multer::Multipart::new(stream, boundary);
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
|
||||
let mut text = String::new();
|
||||
let mut author_note = String::new();
|
||||
@@ -2425,11 +2865,12 @@ async fn testimonial_add(
|
||||
continue;
|
||||
}
|
||||
let upload_dir = crate::uploads::testimonials_dir();
|
||||
crate::uploads::create_logical_dir(&upload_dir)
|
||||
storage
|
||||
.create_logical_dir(&upload_dir)
|
||||
.await
|
||||
.map_err(|e| cot::Error::internal(e.to_string()))?;
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
let file_id = uuid::Uuid::new_v4();
|
||||
let path = save_uploaded_image(&upload_dir, file_id, &ext, &data).await?;
|
||||
let path = save_uploaded_image(&storage, &upload_dir, file_id, &ext, &data).await?;
|
||||
image_path = Some(path);
|
||||
}
|
||||
_ => {}
|
||||
@@ -2519,6 +2960,7 @@ async fn testimonial_edit(
|
||||
let stream =
|
||||
futures::stream::once(async move { Result::<_, std::convert::Infallible>::Ok(bytes) });
|
||||
let mut multipart = multer::Multipart::new(stream, boundary);
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
|
||||
let mut text = String::new();
|
||||
let mut author_note = String::new();
|
||||
@@ -2573,11 +3015,12 @@ async fn testimonial_edit(
|
||||
continue;
|
||||
}
|
||||
let upload_dir = crate::uploads::testimonials_dir();
|
||||
crate::uploads::create_logical_dir(&upload_dir)
|
||||
storage
|
||||
.create_logical_dir(&upload_dir)
|
||||
.await
|
||||
.map_err(|e| cot::Error::internal(e.to_string()))?;
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
let file_id = uuid::Uuid::new_v4();
|
||||
let path = save_uploaded_image(&upload_dir, file_id, &ext, &data).await?;
|
||||
let path = save_uploaded_image(&storage, &upload_dir, file_id, &ext, &data).await?;
|
||||
new_image_path = Some(path);
|
||||
}
|
||||
_ => {}
|
||||
@@ -2618,7 +3061,15 @@ async fn serve_testimonial_image(
|
||||
Some(p) => p.clone(),
|
||||
None => return Html::new("404").into_response(),
|
||||
};
|
||||
match crate::uploads::read_db_file(&path).await {
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
if storage.is_r2() {
|
||||
let url = storage
|
||||
.public_url(&path, String::new())
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
return Redirect::new(url).into_response();
|
||||
}
|
||||
match storage.read(&path).await {
|
||||
Ok(data) => {
|
||||
let content_type = match path.rsplit('.').next().unwrap_or("") {
|
||||
"jpg" | "jpeg" => "image/jpeg",
|
||||
@@ -2767,6 +3218,11 @@ pub fn admin_router() -> Router {
|
||||
"admin-media-delete",
|
||||
),
|
||||
Route::with_handler_and_name("/uploads/{media_id}", serve_upload, "admin-uploads"),
|
||||
Route::with_handler_and_name(
|
||||
"/uploads/{media_id}/thumbnail",
|
||||
serve_upload_thumbnail,
|
||||
"admin-upload-thumbnail",
|
||||
),
|
||||
Route::with_handler_and_name("/testimonials", testimonials_page, "admin-testimonials"),
|
||||
Route::with_handler_and_name(
|
||||
"/testimonials/add",
|
||||
@@ -2797,3 +3253,16 @@ pub fn admin_router() -> Router {
|
||||
Route::with_handler_and_name("/settings/save", save_settings, "admin-settings-save"),
|
||||
])
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::preserved_secret_value;
|
||||
|
||||
#[test]
|
||||
fn keeps_masks_and_updates_secrets_consistently() {
|
||||
assert_eq!(preserved_secret_value("stored", "", false), "stored");
|
||||
assert_eq!(preserved_secret_value("stored", " new ", false), "new");
|
||||
assert_eq!(preserved_secret_value("stored", "", true), "");
|
||||
assert_eq!(preserved_secret_value("stored", "new", true), "new");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
|
||||
use web_push_native::jwt_simple::algorithms::ES256KeyPair;
|
||||
use web_push_native::p256::SecretKey;
|
||||
use web_push_native::p256::elliptic_curve::sec1::ToEncodedPoint;
|
||||
|
||||
fn main() {
|
||||
let key_pair = ES256KeyPair::generate();
|
||||
let private = key_pair.to_bytes();
|
||||
let public = SecretKey::from_slice(&private)
|
||||
.expect("generated key must be valid")
|
||||
.public_key()
|
||||
.to_encoded_point(false);
|
||||
println!("VAPID private key (copy only the next line):");
|
||||
println!("{}", URL_SAFE_NO_PAD.encode(&private));
|
||||
println!("\nVAPID public key (copy only the next line):");
|
||||
println!("{}", URL_SAFE_NO_PAD.encode(public.as_bytes()));
|
||||
println!("\nVAPID subject:");
|
||||
println!("mailto:admin@example.com");
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
#[allow(dead_code)]
|
||||
#[path = "../models.rs"]
|
||||
mod models;
|
||||
#[allow(dead_code)]
|
||||
#[path = "../uploads.rs"]
|
||||
mod uploads;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use cot::db::{Database, Model};
|
||||
use models::{Media, Testimonial};
|
||||
|
||||
fn database_url() -> String {
|
||||
std::env::var("WEB_PETTING_DATABASE_URL")
|
||||
.or_else(|_| std::env::var("DATABASE_URL"))
|
||||
.unwrap_or_else(|_| "postgresql://postgres:postgres@localhost:5432/web_petting".to_string())
|
||||
}
|
||||
|
||||
async fn add_thumbnail(
|
||||
sources: &mut BTreeMap<String, bool>,
|
||||
db_path: &str,
|
||||
required: bool,
|
||||
) -> bool {
|
||||
if !uploads::supports_thumbnail(db_path) {
|
||||
return true;
|
||||
}
|
||||
match uploads::ensure_local_thumbnail(db_path).await {
|
||||
Ok(thumbnail_path) => {
|
||||
sources
|
||||
.entry(thumbnail_path)
|
||||
.and_modify(|is_required| *is_required |= required)
|
||||
.or_insert(required);
|
||||
true
|
||||
}
|
||||
Err(error) => {
|
||||
eprintln!("Could not create thumbnail for {db_path}: {error}");
|
||||
!required
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn add_video_derivatives(
|
||||
sources: &mut BTreeMap<String, bool>,
|
||||
db_path: &str,
|
||||
required: bool,
|
||||
) -> bool {
|
||||
if !uploads::supports_video_preview(db_path) {
|
||||
return true;
|
||||
}
|
||||
match uploads::ensure_video_thumbnail(&uploads::Storage::Local, db_path).await {
|
||||
Ok(thumbnail_path) => {
|
||||
sources
|
||||
.entry(thumbnail_path)
|
||||
.and_modify(|is_required| *is_required |= required)
|
||||
.or_insert(required);
|
||||
true
|
||||
}
|
||||
Err(error) => {
|
||||
eprintln!("Could not create video derivatives for {db_path}: {error}");
|
||||
!required
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let db = Database::new(database_url()).await?;
|
||||
let storage = uploads::Storage::load_configured_r2(&db).await?;
|
||||
let mut sources: BTreeMap<String, bool> = BTreeMap::new();
|
||||
let mut preparation_failed = false;
|
||||
|
||||
for media in Media::objects().all(&db).await? {
|
||||
let required = media.status == "active";
|
||||
sources
|
||||
.entry(media.file_path.clone())
|
||||
.and_modify(|is_required| *is_required |= required)
|
||||
.or_insert(required);
|
||||
match media.file_type.as_str() {
|
||||
"photo" if !add_thumbnail(&mut sources, &media.file_path, required).await => {
|
||||
preparation_failed = true;
|
||||
}
|
||||
"video" if !add_video_derivatives(&mut sources, &media.file_path, required).await => {
|
||||
preparation_failed = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
for testimonial in Testimonial::objects().all(&db).await? {
|
||||
let Some(image_path) = testimonial.image_path else {
|
||||
continue;
|
||||
};
|
||||
let required = testimonial.status == "active";
|
||||
sources
|
||||
.entry(image_path.clone())
|
||||
.and_modify(|is_required| *is_required |= required)
|
||||
.or_insert(required);
|
||||
// Testimonial thumbnails are retained too, even though the landing page
|
||||
// currently displays the processed full-size image.
|
||||
let _ = add_thumbnail(&mut sources, &image_path, false).await;
|
||||
}
|
||||
|
||||
let mut uploaded = 0usize;
|
||||
let mut skipped = 0usize;
|
||||
let mut missing = 0usize;
|
||||
let mut failed = 0usize;
|
||||
|
||||
for (db_path, required) in sources {
|
||||
let local_path = uploads::resolve_db_path(&db_path);
|
||||
match tokio::fs::try_exists(&local_path).await {
|
||||
Ok(true) => {}
|
||||
Ok(false) => {
|
||||
eprintln!("Missing local file {}", local_path.display());
|
||||
missing += 1;
|
||||
if required {
|
||||
failed += 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
Err(error) => {
|
||||
eprintln!(
|
||||
"Could not inspect local file {}: {error}",
|
||||
local_path.display()
|
||||
);
|
||||
missing += 1;
|
||||
if required {
|
||||
failed += 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
if storage.exists(&db_path).await? {
|
||||
println!("Already in R2: {db_path}");
|
||||
skipped += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
match storage.upload_local_copy(&db_path, &local_path).await {
|
||||
Ok(()) => {
|
||||
println!("Uploaded: {db_path}");
|
||||
uploaded += 1;
|
||||
}
|
||||
Err(error) => {
|
||||
eprintln!("Failed to upload {db_path}: {error}");
|
||||
failed += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
db.close().await?;
|
||||
println!(
|
||||
"Migration summary: uploaded={uploaded}, already_present={skipped}, missing_local={missing}, failed={failed}"
|
||||
);
|
||||
println!("Local files were not deleted.");
|
||||
|
||||
if preparation_failed || failed > 0 {
|
||||
return Err("R2 migration did not complete successfully".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let runtime = tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.expect("failed to build Tokio runtime");
|
||||
if let Err(error) = runtime.block_on(run()) {
|
||||
eprintln!("Migration failed: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
#[allow(dead_code)]
|
||||
#[path = "../models.rs"]
|
||||
mod models;
|
||||
#[allow(dead_code)]
|
||||
#[path = "../uploads.rs"]
|
||||
mod uploads;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use cot::db::{Database, Model};
|
||||
use models::Media;
|
||||
|
||||
fn database_url() -> String {
|
||||
std::env::var("WEB_PETTING_DATABASE_URL")
|
||||
.or_else(|_| std::env::var("DATABASE_URL"))
|
||||
.unwrap_or_else(|_| "postgresql://postgres:postgres@localhost:5432/web_petting".to_string())
|
||||
}
|
||||
|
||||
async fn local_file_exists(path: &Path) -> Result<bool, std::io::Error> {
|
||||
match tokio::fs::metadata(path).await {
|
||||
Ok(metadata) => Ok(metadata.is_file() && metadata.len() > 0),
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(false),
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
}
|
||||
|
||||
async fn valid_local_video(path: &Path, media_id: i64) -> Result<bool, std::io::Error> {
|
||||
if !local_file_exists(path).await? {
|
||||
return Ok(false);
|
||||
}
|
||||
match uploads::validate_video_file(path).await {
|
||||
Ok(()) => Ok(true),
|
||||
Err(error) => {
|
||||
eprintln!(
|
||||
"Ignoring incomplete local output for media {media_id}: {} ({error})",
|
||||
path.display()
|
||||
);
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn download_to_workspace(
|
||||
r2: &uploads::Storage,
|
||||
db_path: &str,
|
||||
workspace: &Path,
|
||||
filename: &str,
|
||||
) -> Result<PathBuf, Box<dyn std::error::Error>> {
|
||||
let destination = workspace.join(filename);
|
||||
r2.download_to_path(db_path, &destination).await?;
|
||||
Ok(destination)
|
||||
}
|
||||
|
||||
async fn prepare_missing_objects(
|
||||
r2: &uploads::Storage,
|
||||
media_id: i64,
|
||||
original_db_path: &str,
|
||||
target_db_path: &str,
|
||||
target_thumbnail_db_path: &str,
|
||||
target_in_r2: bool,
|
||||
thumbnail_in_r2: bool,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let workspace =
|
||||
std::env::temp_dir().join(format!("web-petting-normalize-{}", uuid::Uuid::new_v4()));
|
||||
tokio::fs::create_dir(&workspace).await?;
|
||||
|
||||
let result = async {
|
||||
let original_path = uploads::resolve_db_path(original_db_path);
|
||||
let local_target_path = uploads::resolve_db_path(target_db_path);
|
||||
let generated_video_path = workspace.join("video.web.mp4");
|
||||
let generated_thumbnail_path = workspace.join("video.web.thumb.jpg");
|
||||
let mut prepared_video: Option<PathBuf> = None;
|
||||
let mut prepared_thumbnail: Option<PathBuf> = None;
|
||||
|
||||
if !target_in_r2 {
|
||||
if valid_local_video(&local_target_path, media_id).await? {
|
||||
println!("Reusing valid compact video on PVC for media {media_id}");
|
||||
prepared_video = Some(local_target_path.clone());
|
||||
} else {
|
||||
let source = if original_db_path != target_db_path
|
||||
&& local_file_exists(&original_path).await?
|
||||
{
|
||||
original_path.clone()
|
||||
} else if original_db_path != target_db_path && r2.exists(original_db_path).await? {
|
||||
println!("Downloading source from R2 for media {media_id}");
|
||||
let extension = original_db_path.rsplit('.').next().unwrap_or("mov");
|
||||
download_to_workspace(
|
||||
r2,
|
||||
original_db_path,
|
||||
&workspace,
|
||||
&format!("source.{extension}"),
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
return Err(format!(
|
||||
"source is absent from both PVC and R2: {}",
|
||||
original_path.display()
|
||||
)
|
||||
.into());
|
||||
};
|
||||
|
||||
println!("Converting media {media_id}: {original_db_path}");
|
||||
uploads::create_compact_video_files(
|
||||
&source,
|
||||
&generated_video_path,
|
||||
&generated_thumbnail_path,
|
||||
)
|
||||
.await?;
|
||||
prepared_video = Some(generated_video_path.clone());
|
||||
prepared_thumbnail = Some(generated_thumbnail_path.clone());
|
||||
}
|
||||
|
||||
let video_path = prepared_video
|
||||
.as_ref()
|
||||
.ok_or("compact video was not prepared")?;
|
||||
uploads::validate_video_file(video_path).await?;
|
||||
r2.upload_local_copy(target_db_path, video_path).await?;
|
||||
println!("Uploaded compact video: {target_db_path}");
|
||||
}
|
||||
|
||||
if !thumbnail_in_r2 {
|
||||
let video_for_preview = if let Some(video_path) = prepared_video.as_ref() {
|
||||
video_path.clone()
|
||||
} else if valid_local_video(&local_target_path, media_id).await? {
|
||||
local_target_path
|
||||
} else {
|
||||
println!("Downloading compact video from R2 for media {media_id}");
|
||||
let downloaded =
|
||||
download_to_workspace(r2, target_db_path, &workspace, "existing-video.web.mp4")
|
||||
.await?;
|
||||
uploads::validate_video_file(&downloaded).await?;
|
||||
downloaded
|
||||
};
|
||||
|
||||
let thumbnail_path = if let Some(thumbnail_path) = prepared_thumbnail.as_ref() {
|
||||
thumbnail_path.clone()
|
||||
} else {
|
||||
uploads::create_video_thumbnail_file(&video_for_preview, &generated_thumbnail_path)
|
||||
.await?;
|
||||
generated_thumbnail_path
|
||||
};
|
||||
if !local_file_exists(&thumbnail_path).await? {
|
||||
return Err(format!(
|
||||
"video preview was not created: {}",
|
||||
thumbnail_path.display()
|
||||
)
|
||||
.into());
|
||||
}
|
||||
r2.upload_local_copy(target_thumbnail_db_path, &thumbnail_path)
|
||||
.await?;
|
||||
println!("Uploaded video preview: {target_thumbnail_db_path}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
.await;
|
||||
|
||||
let _ = tokio::fs::remove_dir_all(&workspace).await;
|
||||
result
|
||||
}
|
||||
|
||||
async fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let db = Database::new(database_url()).await?;
|
||||
let r2 = uploads::Storage::load_configured_r2(&db).await?;
|
||||
let mut converted = 0usize;
|
||||
let mut already_normalized = 0usize;
|
||||
let mut missing_archived = 0usize;
|
||||
let mut failed = 0usize;
|
||||
|
||||
for mut media in Media::objects().all(&db).await? {
|
||||
if media.file_type != "video" {
|
||||
continue;
|
||||
}
|
||||
|
||||
let media_id = media.id.unwrap();
|
||||
let original_db_path = media.file_path.clone();
|
||||
let target_db_path = uploads::normalized_video_db_path(&original_db_path);
|
||||
let target_thumbnail_db_path = uploads::thumbnail_db_path(&target_db_path);
|
||||
let mut target_in_r2 = r2.exists(&target_db_path).await?;
|
||||
let mut thumbnail_in_r2 = r2.exists(&target_thumbnail_db_path).await?;
|
||||
|
||||
if !target_in_r2 || !thumbnail_in_r2 {
|
||||
if let Err(error) = prepare_missing_objects(
|
||||
&r2,
|
||||
media_id,
|
||||
&original_db_path,
|
||||
&target_db_path,
|
||||
&target_thumbnail_db_path,
|
||||
target_in_r2,
|
||||
thumbnail_in_r2,
|
||||
)
|
||||
.await
|
||||
{
|
||||
eprintln!("Could not prepare media {media_id}: {error}");
|
||||
if media.status == "active" {
|
||||
failed += 1;
|
||||
} else {
|
||||
missing_archived += 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
target_in_r2 = r2.exists(&target_db_path).await?;
|
||||
thumbnail_in_r2 = r2.exists(&target_thumbnail_db_path).await?;
|
||||
}
|
||||
|
||||
if !target_in_r2 || !thumbnail_in_r2 {
|
||||
eprintln!("Could not verify normalized R2 objects for media {media_id}");
|
||||
failed += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if original_db_path != target_db_path {
|
||||
// Both replacements are verified before old R2 keys are removed.
|
||||
// Original files on the PVC are deliberately left untouched.
|
||||
r2.remove(&original_db_path).await?;
|
||||
let original_thumbnail = uploads::thumbnail_db_path(&original_db_path);
|
||||
if original_thumbnail != target_thumbnail_db_path {
|
||||
r2.remove(&original_thumbnail).await?;
|
||||
}
|
||||
media.file_path = target_db_path.clone();
|
||||
media.save(&db).await?;
|
||||
converted += 1;
|
||||
println!("Normalized media {media_id}: {target_db_path}");
|
||||
} else {
|
||||
already_normalized += 1;
|
||||
}
|
||||
}
|
||||
|
||||
db.close().await?;
|
||||
println!(
|
||||
"Video normalization summary: converted={converted}, already_normalized={already_normalized}, missing_archived={missing_archived}, failed={failed}"
|
||||
);
|
||||
println!("Original PVC files were not changed or deleted.");
|
||||
if failed > 0 {
|
||||
return Err("video normalization did not complete successfully".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let runtime = tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.expect("failed to build Tokio runtime");
|
||||
if let Err(error) = runtime.block_on(run()) {
|
||||
eprintln!("Video normalization failed: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
+150
@@ -131,6 +131,16 @@ pub struct Translations {
|
||||
pub settings_save: &'static str,
|
||||
pub settings_saved: &'static str,
|
||||
pub settings_empty: &'static str,
|
||||
pub settings_intro: &'static str,
|
||||
pub settings_section_general_help: &'static str,
|
||||
pub settings_section_notifications_help: &'static str,
|
||||
pub settings_section_captcha_help: &'static str,
|
||||
pub settings_section_oidc_help: &'static str,
|
||||
pub settings_secret_saved: &'static str,
|
||||
pub settings_secret_not_set: &'static str,
|
||||
pub settings_secret_clear: &'static str,
|
||||
pub settings_status_enabled: &'static str,
|
||||
pub settings_status_disabled: &'static str,
|
||||
pub settings_telegram_bot_token: &'static str,
|
||||
pub settings_telegram_chat_id: &'static str,
|
||||
pub settings_contact_info: &'static str,
|
||||
@@ -151,6 +161,29 @@ pub struct Translations {
|
||||
pub settings_section_captcha: &'static str,
|
||||
pub settings_section_oidc: &'static str,
|
||||
pub settings_section_general: &'static str,
|
||||
pub settings_section_storage: &'static str,
|
||||
pub settings_r2_enabled: &'static str,
|
||||
pub settings_r2_help: &'static str,
|
||||
pub settings_r2_account_id: &'static str,
|
||||
pub settings_r2_bucket: &'static str,
|
||||
pub settings_r2_access_key_id: &'static str,
|
||||
pub settings_r2_secret_access_key: &'static str,
|
||||
pub settings_r2_secret_unchanged: &'static str,
|
||||
pub settings_r2_migration_help: &'static str,
|
||||
pub settings_r2_error_incomplete: &'static str,
|
||||
pub settings_client_notifications_enabled: &'static str,
|
||||
pub settings_client_notifications_help: &'static str,
|
||||
pub settings_vapid_public_key: &'static str,
|
||||
pub settings_vapid_private_key: &'static str,
|
||||
pub settings_vapid_subject: &'static str,
|
||||
pub settings_vapid_warning: &'static str,
|
||||
pub settings_vapid_generate: &'static str,
|
||||
pub settings_push_subscribers: &'static str,
|
||||
pub settings_push_no_subscribers: &'static str,
|
||||
pub settings_push_client: &'static str,
|
||||
pub settings_push_devices: &'static str,
|
||||
pub settings_push_language: &'static str,
|
||||
pub settings_push_updated: &'static str,
|
||||
pub landing_contact_label: &'static str,
|
||||
pub landing_pricing_title: &'static str,
|
||||
|
||||
@@ -280,6 +313,11 @@ pub struct Translations {
|
||||
pub media_delete: &'static str,
|
||||
pub media_delete_confirm: &'static str,
|
||||
pub media_all_clients: &'static str,
|
||||
pub media_files_selected: &'static str,
|
||||
pub media_upload_sending: &'static str,
|
||||
pub media_upload_processing: &'static str,
|
||||
pub media_upload_done: &'static str,
|
||||
pub media_upload_connection_error: &'static str,
|
||||
|
||||
// Client portal
|
||||
pub portal_title: &'static str,
|
||||
@@ -292,6 +330,18 @@ pub struct Translations {
|
||||
pub portal_feedback_submit: &'static str,
|
||||
pub portal_feedback_thanks: &'static str,
|
||||
pub portal_link: &'static str,
|
||||
pub portal_notifications: &'static str,
|
||||
pub portal_notifications_text: &'static str,
|
||||
pub portal_notifications_enable: &'static str,
|
||||
pub portal_notifications_disable: &'static str,
|
||||
pub portal_notifications_denied: &'static str,
|
||||
pub portal_notifications_active: &'static str,
|
||||
pub portal_notifications_error: &'static str,
|
||||
pub portal_notifications_unsupported: &'static str,
|
||||
pub portal_calendar: &'static str,
|
||||
pub portal_future_visit: &'static str,
|
||||
pub portal_previous: &'static str,
|
||||
pub portal_next: &'static str,
|
||||
|
||||
// Common
|
||||
pub no_value: &'static str,
|
||||
@@ -366,6 +416,16 @@ static RU: Translations = Translations {
|
||||
settings_save: "Сохранить",
|
||||
settings_saved: "Сохранено!",
|
||||
settings_empty: "Настройки не заданы.",
|
||||
settings_intro: "Параметры сайта, интеграций, хранения медиа и способов входа.",
|
||||
settings_section_general_help: "Публичные данные сайта и параметры, используемые при формировании ссылок и дат.",
|
||||
settings_section_notifications_help: "Telegram для администратора и браузерные push-уведомления для клиентов.",
|
||||
settings_section_captcha_help: "Ключи Cloudflare Turnstile для защиты публичных форм от автоматических отправок.",
|
||||
settings_section_oidc_help: "Настройте доступ администраторов по паролю и через внешний OIDC-провайдер.",
|
||||
settings_secret_saved: "Секрет сохранён. Оставьте поле пустым, чтобы не менять его.",
|
||||
settings_secret_not_set: "Секрет пока не задан.",
|
||||
settings_secret_clear: "Удалить сохранённый секрет",
|
||||
settings_status_enabled: "Включено",
|
||||
settings_status_disabled: "Выключено",
|
||||
settings_telegram_bot_token: "Токен Telegram бота",
|
||||
settings_telegram_chat_id: "Chat ID для уведомлений",
|
||||
settings_contact_info: "Контактная информация (отображается на лендинге)",
|
||||
@@ -386,6 +446,29 @@ static RU: Translations = Translations {
|
||||
settings_section_captcha: "Защита от ботов",
|
||||
settings_section_oidc: "Единый вход (SSO / OIDC)",
|
||||
settings_section_general: "Сайт",
|
||||
settings_section_storage: "Хранилище медиа",
|
||||
settings_r2_enabled: "Использовать Cloudflare R2",
|
||||
settings_r2_help: "Пока R2 выключен или настроен не полностью, медиа хранится локально. После включения новые файлы и миниатюры загружаются в приватный бакет, а страницы получают подписанные ссылки на 6 часов.",
|
||||
settings_r2_account_id: "Cloudflare Account ID",
|
||||
settings_r2_bucket: "Имя R2-бакета",
|
||||
settings_r2_access_key_id: "R2 Access Key ID",
|
||||
settings_r2_secret_access_key: "R2 Secret Access Key",
|
||||
settings_r2_secret_unchanged: "Секрет уже сохранён; оставьте поле пустым, чтобы не менять его",
|
||||
settings_r2_migration_help: "Порядок перехода: сохраните реквизиты с выключенным R2, выполните в контейнере migrate_uploads_to_r2 и normalize_videos_to_r2, затем включите R2 и отключите PVC. Для бакета разрешите CORS GET/HEAD с домена сайта и заголовок Range.",
|
||||
settings_r2_error_incomplete: "R2 не включён: проверьте Account ID, имя бакета, Access Key ID и Secret Access Key.",
|
||||
settings_client_notifications_enabled: "Разрешить клиентам браузерные уведомления",
|
||||
settings_client_notifications_help: "Показывает клиентам настройку уведомлений о завершённых визитах.",
|
||||
settings_vapid_public_key: "VAPID — публичный ключ",
|
||||
settings_vapid_private_key: "VAPID — приватный ключ",
|
||||
settings_vapid_subject: "VAPID — контакт (например mailto:admin@example.com)",
|
||||
settings_vapid_warning: "Важно: смена пары VAPID-ключей сделает недействительными подписки всех клиентов. Им потребуется снова включить уведомления.",
|
||||
settings_vapid_generate: "Для генерации новой пары ключей выполните:",
|
||||
settings_push_subscribers: "Активные подписки клиентов",
|
||||
settings_push_no_subscribers: "Активных подписок пока нет.",
|
||||
settings_push_client: "Клиент",
|
||||
settings_push_devices: "Устройства",
|
||||
settings_push_language: "Язык",
|
||||
settings_push_updated: "Обновлено",
|
||||
landing_contact_label: "Или свяжитесь с нами напрямую",
|
||||
landing_pricing_title: "Стоимость",
|
||||
|
||||
@@ -405,6 +488,11 @@ static RU: Translations = Translations {
|
||||
media_delete: "Удалить",
|
||||
media_delete_confirm: "Удалить этот файл?",
|
||||
media_all_clients: "Все клиенты",
|
||||
media_files_selected: "Выбрано файлов",
|
||||
media_upload_sending: "Загрузка на сервер...",
|
||||
media_upload_processing: "Конвертация и загрузка в R2...",
|
||||
media_upload_done: "Готово — обновляем медиагалерею...",
|
||||
media_upload_connection_error: "Ошибка соединения",
|
||||
|
||||
portal_title: "Визиты",
|
||||
portal_upcoming: "Предстоящие визиты",
|
||||
@@ -416,6 +504,18 @@ static RU: Translations = Translations {
|
||||
portal_feedback_submit: "Отправить",
|
||||
portal_feedback_thanks: "Спасибо за отзыв!",
|
||||
portal_link: "Ссылка клиента",
|
||||
portal_notifications: "Уведомления",
|
||||
portal_notifications_text: "Получайте уведомления о завершённых визитах, даже когда страница закрыта. На iPhone сначала добавьте сайт на экран «Домой» и откройте его оттуда.",
|
||||
portal_notifications_enable: "Включить уведомления",
|
||||
portal_notifications_disable: "Отключить уведомления",
|
||||
portal_notifications_denied: "Уведомления заблокированы в настройках браузера.",
|
||||
portal_notifications_active: "Уведомления подключены на этом устройстве.",
|
||||
portal_notifications_error: "Не удалось сохранить подписку. Обновите страницу и попробуйте ещё раз.",
|
||||
portal_notifications_unsupported: "Этот браузер не поддерживает фоновые уведомления.",
|
||||
portal_calendar: "Календарь визитов",
|
||||
portal_future_visit: "Будущий визит",
|
||||
portal_previous: "Назад",
|
||||
portal_next: "Далее",
|
||||
|
||||
login_title: "Вход в систему",
|
||||
login_button: "Войти",
|
||||
@@ -591,6 +691,16 @@ static EN: Translations = Translations {
|
||||
settings_save: "Save",
|
||||
settings_saved: "Saved!",
|
||||
settings_empty: "No settings configured.",
|
||||
settings_intro: "Site, integration, media storage, and sign-in settings.",
|
||||
settings_section_general_help: "Public site details and values used to build links and display dates.",
|
||||
settings_section_notifications_help: "Telegram alerts for administrators and browser push notifications for clients.",
|
||||
settings_section_captcha_help: "Cloudflare Turnstile keys used to protect public forms from automated submissions.",
|
||||
settings_section_oidc_help: "Configure administrator access with passwords and an external OIDC provider.",
|
||||
settings_secret_saved: "A secret is stored. Leave this field blank to keep it unchanged.",
|
||||
settings_secret_not_set: "No secret is currently stored.",
|
||||
settings_secret_clear: "Remove the stored secret",
|
||||
settings_status_enabled: "Enabled",
|
||||
settings_status_disabled: "Disabled",
|
||||
settings_telegram_bot_token: "Telegram Bot Token",
|
||||
settings_telegram_chat_id: "Notification Chat ID",
|
||||
settings_contact_info: "Contact info (shown on landing page)",
|
||||
@@ -611,6 +721,29 @@ static EN: Translations = Translations {
|
||||
settings_section_captcha: "Bot protection",
|
||||
settings_section_oidc: "Single Sign-On (SSO / OIDC)",
|
||||
settings_section_general: "Site",
|
||||
settings_section_storage: "Media storage",
|
||||
settings_r2_enabled: "Use Cloudflare R2",
|
||||
settings_r2_help: "While R2 is disabled or incomplete, media stays in local storage. Once enabled, new files and thumbnails are uploaded to the private bucket and pages receive signed URLs valid for 6 hours.",
|
||||
settings_r2_account_id: "Cloudflare Account ID",
|
||||
settings_r2_bucket: "R2 bucket name",
|
||||
settings_r2_access_key_id: "R2 Access Key ID",
|
||||
settings_r2_secret_access_key: "R2 Secret Access Key",
|
||||
settings_r2_secret_unchanged: "A secret is already stored; leave this blank to keep it unchanged",
|
||||
settings_r2_migration_help: "Migration order: save the credentials with R2 disabled, run migrate_uploads_to_r2 and normalize_videos_to_r2 inside the container, then enable R2 and detach the PVC. Allow CORS GET/HEAD from the site domain and the Range header on the bucket.",
|
||||
settings_r2_error_incomplete: "R2 was not enabled: check the Account ID, bucket name, Access Key ID, and Secret Access Key.",
|
||||
settings_client_notifications_enabled: "Allow client browser notifications",
|
||||
settings_client_notifications_help: "Shows clients the completed-visit notification setting.",
|
||||
settings_vapid_public_key: "VAPID public key",
|
||||
settings_vapid_private_key: "VAPID private key",
|
||||
settings_vapid_subject: "VAPID contact (for example mailto:admin@example.com)",
|
||||
settings_vapid_warning: "Important: changing the VAPID key pair invalidates every client subscription. Clients will need to enable notifications again.",
|
||||
settings_vapid_generate: "To generate a new key pair, run:",
|
||||
settings_push_subscribers: "Active client subscriptions",
|
||||
settings_push_no_subscribers: "There are no active subscriptions yet.",
|
||||
settings_push_client: "Client",
|
||||
settings_push_devices: "Devices",
|
||||
settings_push_language: "Language",
|
||||
settings_push_updated: "Updated",
|
||||
landing_contact_label: "Or contact us directly",
|
||||
landing_pricing_title: "Pricing",
|
||||
|
||||
@@ -630,6 +763,11 @@ static EN: Translations = Translations {
|
||||
media_delete: "Delete",
|
||||
media_delete_confirm: "Delete this file?",
|
||||
media_all_clients: "All clients",
|
||||
media_files_selected: "Files selected",
|
||||
media_upload_sending: "Uploading to the server...",
|
||||
media_upload_processing: "Converting and uploading to R2...",
|
||||
media_upload_done: "Done — refreshing the media gallery...",
|
||||
media_upload_connection_error: "Connection error",
|
||||
|
||||
portal_title: "Visits",
|
||||
portal_upcoming: "Upcoming visits",
|
||||
@@ -641,6 +779,18 @@ static EN: Translations = Translations {
|
||||
portal_feedback_submit: "Submit",
|
||||
portal_feedback_thanks: "Thank you for your feedback!",
|
||||
portal_link: "Client link",
|
||||
portal_notifications: "Notifications",
|
||||
portal_notifications_text: "Receive completed-visit notifications even when this page is closed. On iPhone, first add this site to the Home Screen and open it from there.",
|
||||
portal_notifications_enable: "Enable notifications",
|
||||
portal_notifications_disable: "Disable notifications",
|
||||
portal_notifications_denied: "Notifications are blocked in your browser settings.",
|
||||
portal_notifications_active: "Notifications are enabled on this device.",
|
||||
portal_notifications_error: "The subscription could not be saved. Reload the page and try again.",
|
||||
portal_notifications_unsupported: "This browser does not support background notifications.",
|
||||
portal_calendar: "Visit calendar",
|
||||
portal_future_visit: "Future visit",
|
||||
portal_previous: "Previous",
|
||||
portal_next: "Next",
|
||||
|
||||
login_title: "Sign In",
|
||||
login_button: "Sign In",
|
||||
|
||||
+40
-7
@@ -7,8 +7,7 @@ mod telegram;
|
||||
mod turnstile;
|
||||
mod tz;
|
||||
mod uploads;
|
||||
|
||||
use tracing_subscriber;
|
||||
mod web_push;
|
||||
|
||||
use cot::cli::CliMetadata;
|
||||
use cot::config::{
|
||||
@@ -17,7 +16,7 @@ use cot::config::{
|
||||
};
|
||||
use cot::db::migrations::SyncDynMigration;
|
||||
use cot::middleware::SessionMiddleware;
|
||||
use cot::project::{MiddlewareContext, RegisterAppsContext, RootHandler};
|
||||
use cot::project::{MiddlewareContext, ProjectContext, RegisterAppsContext, RootHandler};
|
||||
use cot::router::Router;
|
||||
use cot::session::db::SessionApp;
|
||||
use cot::{App, AppBuilder, Project};
|
||||
@@ -40,11 +39,17 @@ impl App for PettingApp {
|
||||
|
||||
struct PublicApp;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl App for PublicApp {
|
||||
fn name(&self) -> &'static str {
|
||||
"public"
|
||||
}
|
||||
|
||||
async fn init(&self, context: &mut ProjectContext) -> cot::Result<()> {
|
||||
web_push::initialize(context.database()).await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn router(&self) -> Router {
|
||||
public::public_router()
|
||||
}
|
||||
@@ -73,7 +78,13 @@ fn debug_enabled(config_name: &str) -> bool {
|
||||
fn database_url() -> String {
|
||||
std::env::var("WEB_PETTING_DATABASE_URL")
|
||||
.or_else(|_| std::env::var("DATABASE_URL"))
|
||||
.unwrap_or_else(|_| "postgresql://postgres:postgres@localhost:5432/web_petting".to_string())
|
||||
.unwrap_or_else(|_| {
|
||||
eprintln!(
|
||||
"WEB_PETTING_DATABASE_URL and DATABASE_URL are not set; using the local default \
|
||||
postgresql://postgres:postgres@localhost:5432/web_petting"
|
||||
);
|
||||
"postgresql://postgres:postgres@localhost:5432/web_petting".to_string()
|
||||
})
|
||||
}
|
||||
|
||||
impl Project for PettingProject {
|
||||
@@ -120,10 +131,32 @@ impl Project for PettingProject {
|
||||
}
|
||||
}
|
||||
|
||||
#[cot::main]
|
||||
fn main() -> impl Project {
|
||||
fn main() {
|
||||
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"));
|
||||
let _ = tracing_subscriber::fmt().with_env_filter(filter).try_init();
|
||||
PettingProject
|
||||
let runtime = tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.expect("failed to build Tokio runtime");
|
||||
if let Err(error) = runtime.block_on(cot::run_cli(PettingProject)) {
|
||||
let message = error.to_string();
|
||||
let details = format!("{error:?}");
|
||||
eprintln!("Failed to start web-petting: {message}\nDetails: {details}");
|
||||
if details.contains("28P01") || details.contains("password authentication failed") {
|
||||
eprintln!(
|
||||
"\nPostgreSQL rejected the configured username or password.\n\
|
||||
Set the connection string before starting the application, for example:\n\n \
|
||||
WEB_PETTING_DATABASE_URL='postgresql://postgres:YOUR_PASSWORD@localhost:5432/web_petting' cargo run\n\n\
|
||||
WEB_PETTING_DATABASE_URL takes priority over DATABASE_URL.\n\
|
||||
Check the current value with: printenv WEB_PETTING_DATABASE_URL"
|
||||
);
|
||||
} else if message.to_ascii_lowercase().contains("database") {
|
||||
eprintln!(
|
||||
"\nConfigure PostgreSQL with WEB_PETTING_DATABASE_URL or DATABASE_URL.\n\
|
||||
Example:\n\n WEB_PETTING_DATABASE_URL='postgresql://postgres:YOUR_PASSWORD@localhost:5432/web_petting' cargo run"
|
||||
);
|
||||
}
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -3,5 +3,9 @@
|
||||
//! Squashed for the PostgreSQL migration on 2026-07-11.
|
||||
|
||||
pub mod m_0001_initial;
|
||||
pub mod m_0002_push_subscription;
|
||||
/// The list of migrations for current app.
|
||||
pub const MIGRATIONS: &[&::cot::db::migrations::SyncDynMigration] = &[&m_0001_initial::Migration];
|
||||
pub const MIGRATIONS: &[&::cot::db::migrations::SyncDynMigration] = &[
|
||||
&m_0001_initial::Migration,
|
||||
&m_0002_push_subscription::Migration,
|
||||
];
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
//! Store browser Web Push subscriptions for client devices.
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub(super) struct Migration;
|
||||
|
||||
impl ::cot::db::migrations::Migration for Migration {
|
||||
const APP_NAME: &'static str = "web-petting";
|
||||
const MIGRATION_NAME: &'static str = "m_0002_push_subscription";
|
||||
const DEPENDENCIES: &'static [::cot::db::migrations::MigrationDependency] =
|
||||
&[::cot::db::migrations::MigrationDependency::migration(
|
||||
"web-petting",
|
||||
"m_0001_initial",
|
||||
)];
|
||||
const OPERATIONS: &'static [::cot::db::migrations::Operation] = &[
|
||||
::cot::db::migrations::Operation::create_model()
|
||||
.table_name(::cot::db::Identifier::new("web_petting__push_subscription"))
|
||||
.fields(&[
|
||||
::cot::db::migrations::Field::new(
|
||||
::cot::db::Identifier::new("id"),
|
||||
<cot::db::Auto<i64> as ::cot::db::DatabaseField>::TYPE,
|
||||
)
|
||||
.auto()
|
||||
.primary_key()
|
||||
.set_null(<cot::db::Auto<i64> as ::cot::db::DatabaseField>::NULLABLE),
|
||||
::cot::db::migrations::Field::new(
|
||||
::cot::db::Identifier::new("client_id"),
|
||||
<cot::db::ForeignKey<crate::models::Client> as ::cot::db::DatabaseField>::TYPE,
|
||||
)
|
||||
.foreign_key(
|
||||
<crate::models::Client as ::cot::db::Model>::TABLE_NAME,
|
||||
<crate::models::Client as ::cot::db::Model>::PRIMARY_KEY_NAME,
|
||||
::cot::db::ForeignKeyOnDeletePolicy::Restrict,
|
||||
::cot::db::ForeignKeyOnUpdatePolicy::Restrict,
|
||||
)
|
||||
.set_null(<cot::db::ForeignKey<crate::models::Client> as ::cot::db::DatabaseField>::NULLABLE),
|
||||
::cot::db::migrations::Field::new(
|
||||
::cot::db::Identifier::new("endpoint"),
|
||||
<String as ::cot::db::DatabaseField>::TYPE,
|
||||
).set_null(false).unique(),
|
||||
::cot::db::migrations::Field::new(
|
||||
::cot::db::Identifier::new("p256dh"),
|
||||
<String as ::cot::db::DatabaseField>::TYPE,
|
||||
).set_null(false),
|
||||
::cot::db::migrations::Field::new(
|
||||
::cot::db::Identifier::new("auth"),
|
||||
<String as ::cot::db::DatabaseField>::TYPE,
|
||||
).set_null(false),
|
||||
::cot::db::migrations::Field::new(
|
||||
::cot::db::Identifier::new("language"),
|
||||
<String as ::cot::db::DatabaseField>::TYPE,
|
||||
).set_null(false),
|
||||
::cot::db::migrations::Field::new(
|
||||
::cot::db::Identifier::new("status"),
|
||||
<String as ::cot::db::DatabaseField>::TYPE,
|
||||
).set_null(false),
|
||||
::cot::db::migrations::Field::new(
|
||||
::cot::db::Identifier::new("created_at"),
|
||||
<chrono::NaiveDateTime as ::cot::db::DatabaseField>::TYPE,
|
||||
).set_null(false),
|
||||
::cot::db::migrations::Field::new(
|
||||
::cot::db::Identifier::new("updated_at"),
|
||||
<chrono::NaiveDateTime as ::cot::db::DatabaseField>::TYPE,
|
||||
).set_null(false),
|
||||
])
|
||||
.build(),
|
||||
];
|
||||
}
|
||||
@@ -217,3 +217,21 @@ pub struct Setting {
|
||||
pub value: String,
|
||||
pub updated_at: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
/// A browser Web Push subscription belonging to a client device.
|
||||
#[derive(Debug, Clone)]
|
||||
#[model]
|
||||
pub struct PushSubscription {
|
||||
#[model(primary_key)]
|
||||
pub id: Auto<i64>,
|
||||
pub client_id: ForeignKey<Client>,
|
||||
#[model(unique)]
|
||||
pub endpoint: String,
|
||||
pub p256dh: String,
|
||||
pub auth: String,
|
||||
pub language: String,
|
||||
/// active | archived
|
||||
pub status: String,
|
||||
pub created_at: chrono::NaiveDateTime,
|
||||
pub updated_at: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
+607
-45
@@ -1,17 +1,20 @@
|
||||
use chrono::Datelike;
|
||||
use cot::Template;
|
||||
use cot::db::{Auto, Database, Model};
|
||||
use cot::db::{Auto, Database, ForeignKey, Model};
|
||||
use cot::html::Html;
|
||||
use cot::request::Request;
|
||||
use cot::request::extractors::Path;
|
||||
use cot::response::{IntoResponse, Redirect, Response};
|
||||
use cot::router::{Route, Router};
|
||||
use serde::Deserialize;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::ops::Deref;
|
||||
use tracing::info;
|
||||
|
||||
use cot::db::query;
|
||||
|
||||
use crate::i18n::{Lang, Translations};
|
||||
use crate::models::{Client, Lead, Media, Setting, Testimonial, User, Visit};
|
||||
use crate::models::{Client, Lead, Media, PushSubscription, Setting, Testimonial, User, Visit};
|
||||
use crate::telegram;
|
||||
|
||||
fn detect_lang(request: &Request) -> Lang {
|
||||
@@ -73,12 +76,26 @@ struct LandingTemplate<'a> {
|
||||
contact_info: String,
|
||||
pricing_info: String,
|
||||
seo_keywords: String,
|
||||
testimonials: Vec<Testimonial>,
|
||||
testimonials: Vec<TestimonialView>,
|
||||
site_domain: String,
|
||||
review_count: usize,
|
||||
turnstile_site_key: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct TestimonialView {
|
||||
testimonial: Testimonial,
|
||||
image_url: Option<String>,
|
||||
}
|
||||
|
||||
impl Deref for TestimonialView {
|
||||
type Target = Testimonial;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.testimonial
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Template)]
|
||||
#[template(path = "thank_you.html")]
|
||||
struct ThankYouTemplate<'a> {
|
||||
@@ -144,13 +161,33 @@ async fn landing_page(request: Request, db: Database) -> cot::Result<Response> {
|
||||
testimonials.retain(|t| t.status == "active");
|
||||
testimonials.sort_by(|a, b| a.sort_order.cmp(&b.sort_order));
|
||||
let review_count = testimonials.len();
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
let mut testimonial_views = Vec::with_capacity(testimonials.len());
|
||||
for testimonial in testimonials {
|
||||
let image_url = match testimonial.image_path.as_deref() {
|
||||
Some(path) => Some(
|
||||
storage
|
||||
.public_url(
|
||||
path,
|
||||
format!("/testimonial-image/{}", testimonial.id.unwrap()),
|
||||
)
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?,
|
||||
),
|
||||
None => None,
|
||||
};
|
||||
testimonial_views.push(TestimonialView {
|
||||
testimonial,
|
||||
image_url,
|
||||
});
|
||||
}
|
||||
let body = LandingTemplate {
|
||||
t: lang.t(),
|
||||
lang,
|
||||
contact_info,
|
||||
pricing_info,
|
||||
seo_keywords,
|
||||
testimonials,
|
||||
testimonials: testimonial_views,
|
||||
site_domain,
|
||||
review_count,
|
||||
turnstile_site_key,
|
||||
@@ -212,7 +249,72 @@ async fn submit_lead(request: Request, db: Database) -> cot::Result<Response> {
|
||||
struct PortalVisit {
|
||||
visit: Visit,
|
||||
admin_name: String,
|
||||
media: Vec<Media>,
|
||||
media: Vec<PortalMediaView>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct PortalMediaView {
|
||||
media: Media,
|
||||
url: String,
|
||||
thumbnail_url: String,
|
||||
}
|
||||
|
||||
impl Deref for PortalMediaView {
|
||||
type Target = Media;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.media
|
||||
}
|
||||
}
|
||||
|
||||
async fn portal_media_view(
|
||||
storage: &crate::uploads::Storage,
|
||||
media: Media,
|
||||
client_token: &str,
|
||||
) -> cot::Result<PortalMediaView> {
|
||||
let media_id = media.id.unwrap();
|
||||
let delivery = crate::uploads::media_delivery_paths(&media.file_type, &media.file_path);
|
||||
let url = storage
|
||||
.public_url(
|
||||
&delivery.media_path,
|
||||
format!("/client/{client_token}/media/{media_id}"),
|
||||
)
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
let thumbnail_fallback = format!("/client/{client_token}/media/{media_id}/thumbnail");
|
||||
let thumbnail_url = if storage.is_r2()
|
||||
&& storage
|
||||
.exists(&delivery.thumbnail_path)
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?
|
||||
{
|
||||
storage
|
||||
.public_url(&delivery.thumbnail_path, thumbnail_fallback)
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?
|
||||
} else {
|
||||
thumbnail_fallback
|
||||
};
|
||||
Ok(PortalMediaView {
|
||||
media,
|
||||
url,
|
||||
thumbnail_url,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct CalendarDay {
|
||||
number: u32,
|
||||
class_name: &'static str,
|
||||
href: Option<String>,
|
||||
title: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct CalendarMonth {
|
||||
label: String,
|
||||
leading_blanks: Vec<u8>,
|
||||
days: Vec<CalendarDay>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Template)]
|
||||
@@ -225,6 +327,62 @@ struct ClientPortalTemplate<'a> {
|
||||
past: Vec<PortalVisit>,
|
||||
feedback_sent: bool,
|
||||
turnstile_site_key: String,
|
||||
notifications_enabled: bool,
|
||||
vapid_public_key: String,
|
||||
calendar_months: Vec<CalendarMonth>,
|
||||
page: usize,
|
||||
total_pages: usize,
|
||||
has_previous_page: bool,
|
||||
has_next_page: bool,
|
||||
}
|
||||
|
||||
const PORTAL_VISITS_PER_PAGE: usize = 10;
|
||||
|
||||
fn query_page(request: &Request) -> usize {
|
||||
request
|
||||
.uri()
|
||||
.query()
|
||||
.and_then(|query| {
|
||||
query.split('&').find_map(|part| {
|
||||
part.strip_prefix("page=")
|
||||
.and_then(|value| value.parse::<usize>().ok())
|
||||
.filter(|page| *page > 0)
|
||||
})
|
||||
})
|
||||
.unwrap_or(1)
|
||||
}
|
||||
|
||||
fn month_label(year: i32, month: u32, lang: Lang) -> String {
|
||||
const RU: [&str; 12] = [
|
||||
"Январь",
|
||||
"Февраль",
|
||||
"Март",
|
||||
"Апрель",
|
||||
"Май",
|
||||
"Июнь",
|
||||
"Июль",
|
||||
"Август",
|
||||
"Сентябрь",
|
||||
"Октябрь",
|
||||
"Ноябрь",
|
||||
"Декабрь",
|
||||
];
|
||||
const EN: [&str; 12] = [
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December",
|
||||
];
|
||||
let names = if lang == Lang::Ru { RU } else { EN };
|
||||
format!("{} {year}", names[(month - 1) as usize])
|
||||
}
|
||||
|
||||
async fn client_portal(
|
||||
@@ -238,6 +396,7 @@ async fn client_portal(
|
||||
.query()
|
||||
.map(|q| q.split('&').any(|p| p == "feedback=ok"))
|
||||
.unwrap_or(false);
|
||||
let requested_page = query_page(&request);
|
||||
|
||||
let client = match query!(Client, $media_token == token).get(&db).await? {
|
||||
Some(c) if c.status != "deleted" => c,
|
||||
@@ -261,8 +420,48 @@ async fn client_portal(
|
||||
.then(a.time_start.cmp(&b.time_start))
|
||||
});
|
||||
|
||||
let mut upcoming_visits = Vec::new();
|
||||
let mut past_visits = Vec::new();
|
||||
for v in visits {
|
||||
if v.visit_date >= today && v.status == "scheduled" {
|
||||
upcoming_visits.push(v);
|
||||
} else {
|
||||
past_visits.push(v);
|
||||
}
|
||||
}
|
||||
past_visits.reverse(); // newest first
|
||||
|
||||
let total_pages = past_visits.len().div_ceil(PORTAL_VISITS_PER_PAGE).max(1);
|
||||
let page = requested_page.min(total_pages);
|
||||
let page_start = (page - 1) * PORTAL_VISITS_PER_PAGE;
|
||||
let page_end = (page_start + PORTAL_VISITS_PER_PAGE).min(past_visits.len());
|
||||
let visible_visit_ids: HashSet<i64> = past_visits[page_start..page_end]
|
||||
.iter()
|
||||
.chain(upcoming_visits.iter())
|
||||
.map(|visit| visit.id.unwrap())
|
||||
.collect();
|
||||
|
||||
let users = User::objects().all(&db).await?;
|
||||
let all_media = Media::objects().all(&db).await?;
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
let mut media_by_visit: HashMap<i64, Vec<PortalMediaView>> = HashMap::new();
|
||||
for media in all_media {
|
||||
if media.status != "active" || media.client_id.primary_key().unwrap() != client_id {
|
||||
continue;
|
||||
}
|
||||
let Some(visit_id) = media
|
||||
.visit_id
|
||||
.as_ref()
|
||||
.map(|foreign_key| foreign_key.primary_key().unwrap())
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
if !visible_visit_ids.contains(&visit_id) {
|
||||
continue;
|
||||
}
|
||||
let media_view = portal_media_view(&storage, media, &client.media_token).await?;
|
||||
media_by_visit.entry(visit_id).or_default().push(media_view);
|
||||
}
|
||||
|
||||
let build_portal_visit = |v: Visit| -> PortalVisit {
|
||||
let uid: i64 = v.user_id.primary_key().unwrap();
|
||||
@@ -272,18 +471,7 @@ async fn client_portal(
|
||||
.map(|u| u.display_name.as_deref().unwrap_or(&u.login).to_string())
|
||||
.unwrap_or_default();
|
||||
let vid = v.id.unwrap();
|
||||
let media: Vec<Media> = all_media
|
||||
.iter()
|
||||
.filter(|m| {
|
||||
m.status == "active"
|
||||
&& m.client_id.primary_key().unwrap() == client_id
|
||||
&& m.visit_id
|
||||
.as_ref()
|
||||
.map(|fk| fk.primary_key().unwrap() == vid)
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.cloned()
|
||||
.collect();
|
||||
let media = media_by_visit.get(&vid).cloned().unwrap_or_default();
|
||||
PortalVisit {
|
||||
visit: v,
|
||||
admin_name,
|
||||
@@ -291,16 +479,95 @@ async fn client_portal(
|
||||
}
|
||||
};
|
||||
|
||||
let mut upcoming = Vec::new();
|
||||
let mut past = Vec::new();
|
||||
for v in visits {
|
||||
if v.visit_date >= today && v.status == "scheduled" {
|
||||
upcoming.push(build_portal_visit(v));
|
||||
} else {
|
||||
past.push(build_portal_visit(v));
|
||||
}
|
||||
}
|
||||
past.reverse(); // newest first
|
||||
let past = past_visits[page_start..page_end]
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(&build_portal_visit)
|
||||
.collect();
|
||||
let upcoming: Vec<_> = upcoming_visits
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(&build_portal_visit)
|
||||
.collect();
|
||||
|
||||
let mut month_keys: Vec<(i32, u32)> = past_visits
|
||||
.iter()
|
||||
.chain(upcoming_visits.iter())
|
||||
.map(|visit| (visit.visit_date.year(), visit.visit_date.month()))
|
||||
.collect();
|
||||
month_keys.sort();
|
||||
month_keys.dedup();
|
||||
month_keys.reverse();
|
||||
let calendar_months = month_keys
|
||||
.into_iter()
|
||||
.map(|(year, month)| {
|
||||
let first = chrono::NaiveDate::from_ymd_opt(year, month, 1).unwrap();
|
||||
let next_month = if month == 12 {
|
||||
chrono::NaiveDate::from_ymd_opt(year + 1, 1, 1).unwrap()
|
||||
} else {
|
||||
chrono::NaiveDate::from_ymd_opt(year, month + 1, 1).unwrap()
|
||||
};
|
||||
let days_in_month = (next_month - first).num_days() as u32;
|
||||
let leading_blanks = vec![0; first.weekday().num_days_from_monday() as usize];
|
||||
let days = (1..=days_in_month)
|
||||
.map(|day| {
|
||||
let date = chrono::NaiveDate::from_ymd_opt(year, month, day).unwrap();
|
||||
if let Some(_visit) = upcoming_visits
|
||||
.iter()
|
||||
.find(|visit| visit.visit_date == date)
|
||||
{
|
||||
CalendarDay {
|
||||
number: day,
|
||||
class_name: "future",
|
||||
href: None,
|
||||
title: lang.t().portal_future_visit.to_string(),
|
||||
}
|
||||
} else if let Some((index, visit)) = past_visits
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find(|(_, visit)| visit.visit_date == date)
|
||||
{
|
||||
CalendarDay {
|
||||
number: day,
|
||||
class_name: "past",
|
||||
href: Some(format!(
|
||||
"?page={}#visit-{}",
|
||||
index / PORTAL_VISITS_PER_PAGE + 1,
|
||||
visit.id.unwrap()
|
||||
)),
|
||||
title: lang.t().visit_status(&visit.status).to_string(),
|
||||
}
|
||||
} else {
|
||||
CalendarDay {
|
||||
number: day,
|
||||
class_name: "empty",
|
||||
href: None,
|
||||
title: String::new(),
|
||||
}
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
CalendarMonth {
|
||||
label: month_label(year, month, lang),
|
||||
leading_blanks,
|
||||
days,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let notification_key = "client_notifications_enabled".to_string();
|
||||
let vapid_public_key = crate::web_push::load_config(&db)
|
||||
.await
|
||||
.map(|config| config.public_key)
|
||||
.unwrap_or_default();
|
||||
// The administrator setting controls whether the client can see notification
|
||||
// controls. Keep this independent from VAPID validation so a configuration
|
||||
// error is visible in the modal instead of silently removing the button.
|
||||
let notifications_enabled = query!(Setting, $key == notification_key)
|
||||
.get(&db)
|
||||
.await?
|
||||
.map(|setting| setting.value == "true")
|
||||
.unwrap_or(false);
|
||||
|
||||
let turnstile_site_key = crate::turnstile::get_site_key(&db).await?;
|
||||
let body = ClientPortalTemplate {
|
||||
@@ -311,11 +578,203 @@ async fn client_portal(
|
||||
past,
|
||||
feedback_sent,
|
||||
turnstile_site_key,
|
||||
notifications_enabled,
|
||||
vapid_public_key,
|
||||
calendar_months,
|
||||
page,
|
||||
total_pages,
|
||||
has_previous_page: page > 1,
|
||||
has_next_page: page < total_pages,
|
||||
}
|
||||
.render()?;
|
||||
html_response(body, lang)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct PushKeysForm {
|
||||
p256dh: String,
|
||||
auth: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct PushSubscriptionForm {
|
||||
endpoint: String,
|
||||
keys: PushKeysForm,
|
||||
#[serde(default)]
|
||||
language: String,
|
||||
}
|
||||
|
||||
async fn portal_push_subscribe(
|
||||
request: Request,
|
||||
db: Database,
|
||||
Path(token): Path<String>,
|
||||
) -> cot::Result<Response> {
|
||||
tracing::info!("client Web Push subscription request");
|
||||
if crate::web_push::load_config(&db).await.is_none() {
|
||||
return Html::new("404").into_response();
|
||||
}
|
||||
let client = match query!(Client, $media_token == token).get(&db).await? {
|
||||
Some(client) if client.status != "deleted" => client,
|
||||
_ => return Html::new("404").into_response(),
|
||||
};
|
||||
let bytes = request.into_body().into_bytes().await?;
|
||||
let form: PushSubscriptionForm =
|
||||
serde_json::from_slice(&bytes).map_err(|error| cot::Error::internal(error.to_string()))?;
|
||||
if !form.endpoint.starts_with("https://")
|
||||
|| form.endpoint.len() > 4096
|
||||
|| form.keys.p256dh.len() > 512
|
||||
|| form.keys.auth.len() > 256
|
||||
{
|
||||
let mut response = Response::new(cot::Body::fixed(
|
||||
"{\"ok\":false,\"error\":\"invalid subscription\"}",
|
||||
));
|
||||
*response.status_mut() = cot::StatusCode::BAD_REQUEST;
|
||||
response
|
||||
.headers_mut()
|
||||
.insert("content-type", "application/json".parse().unwrap());
|
||||
return Ok(response);
|
||||
}
|
||||
tracing::info!(
|
||||
client_id = client.id.unwrap(),
|
||||
"client Web Push subscription saved"
|
||||
);
|
||||
let endpoint = form.endpoint.clone();
|
||||
let now = chrono::Utc::now().naive_utc();
|
||||
if let Some(mut subscription) = query!(PushSubscription, $endpoint == endpoint)
|
||||
.get(&db)
|
||||
.await?
|
||||
{
|
||||
subscription.client_id = ForeignKey::PrimaryKey(Auto::fixed(client.id.unwrap()));
|
||||
subscription.p256dh = form.keys.p256dh;
|
||||
subscription.auth = form.keys.auth;
|
||||
subscription.language = if form.language == "ru" { "ru" } else { "en" }.to_string();
|
||||
subscription.status = "active".to_string();
|
||||
subscription.updated_at = now;
|
||||
subscription.save(&db).await?;
|
||||
} else {
|
||||
let mut subscription = PushSubscription {
|
||||
id: Auto::auto(),
|
||||
client_id: ForeignKey::PrimaryKey(Auto::fixed(client.id.unwrap())),
|
||||
endpoint: form.endpoint,
|
||||
p256dh: form.keys.p256dh,
|
||||
auth: form.keys.auth,
|
||||
language: if form.language == "ru" { "ru" } else { "en" }.to_string(),
|
||||
status: "active".to_string(),
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
};
|
||||
subscription.save(&db).await?;
|
||||
}
|
||||
let mut response = Response::new(cot::Body::fixed("{\"ok\":true}"));
|
||||
response
|
||||
.headers_mut()
|
||||
.insert("content-type", "application/json".parse().unwrap());
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
async fn portal_push_unsubscribe(
|
||||
request: Request,
|
||||
db: Database,
|
||||
Path(token): Path<String>,
|
||||
) -> cot::Result<Response> {
|
||||
let client = match query!(Client, $media_token == token).get(&db).await? {
|
||||
Some(client) if client.status != "deleted" => client,
|
||||
_ => return Html::new("404").into_response(),
|
||||
};
|
||||
let bytes = request.into_body().into_bytes().await?;
|
||||
let value: serde_json::Value =
|
||||
serde_json::from_slice(&bytes).map_err(|error| cot::Error::internal(error.to_string()))?;
|
||||
let endpoint = value
|
||||
.get("endpoint")
|
||||
.and_then(|value| value.as_str())
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
if let Some(mut subscription) = query!(PushSubscription, $endpoint == endpoint)
|
||||
.get(&db)
|
||||
.await?
|
||||
{
|
||||
if subscription.client_id.primary_key().unwrap() == client.id.unwrap() {
|
||||
subscription.status = "archived".to_string();
|
||||
subscription.updated_at = chrono::Utc::now().naive_utc();
|
||||
subscription.save(&db).await?;
|
||||
}
|
||||
}
|
||||
let mut response = Response::new(cot::Body::fixed("{\"ok\":true}"));
|
||||
response
|
||||
.headers_mut()
|
||||
.insert("content-type", "application/json".parse().unwrap());
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
async fn web_manifest(_request: Request, Path(token): Path<String>) -> cot::Result<Response> {
|
||||
let manifest = serde_json::json!({
|
||||
"id": format!("/client/{token}"),
|
||||
"name": "Pet Sitting Visits",
|
||||
"short_name": "Pet Visits",
|
||||
"start_url": format!("/client/{token}"),
|
||||
"display": "standalone",
|
||||
"background_color": "#f8f7ff",
|
||||
"theme_color": "#7c6cff",
|
||||
"icons": [{ "src": "/favicon.svg", "sizes": "any", "type": "image/svg+xml" }]
|
||||
});
|
||||
let mut response = Response::new(cot::Body::fixed(manifest.to_string()));
|
||||
response
|
||||
.headers_mut()
|
||||
.insert("content-type", "application/manifest+json".parse().unwrap());
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
async fn service_worker(_request: Request) -> cot::Result<Response> {
|
||||
let script = r#"
|
||||
self.addEventListener('install', function(event) {
|
||||
self.skipWaiting();
|
||||
});
|
||||
self.addEventListener('activate', function(event) {
|
||||
event.waitUntil(self.clients.claim());
|
||||
});
|
||||
self.addEventListener('push', function(event) {
|
||||
var data = event.data ? event.data.json() : {};
|
||||
event.waitUntil(self.registration.showNotification(data.title || 'Pet Visits', {
|
||||
body: data.body || '', tag: data.tag || 'visit', data: { url: data.url || '/' },
|
||||
icon: '/favicon.svg', badge: '/favicon.svg'
|
||||
}));
|
||||
});
|
||||
self.addEventListener('notificationclick', function(event) {
|
||||
event.notification.close();
|
||||
var target = new URL(event.notification.data.url || '/', self.location.origin).href;
|
||||
event.waitUntil((async function() {
|
||||
var list = await clients.matchAll({ type: 'window', includeUncontrolled: true });
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
if (list[i].url === target && 'focus' in list[i]) {
|
||||
return list[i].focus();
|
||||
}
|
||||
}
|
||||
for (var j = 0; j < list.length; j++) {
|
||||
if ('navigate' in list[j] && 'focus' in list[j]) {
|
||||
try {
|
||||
var navigated = await list[j].navigate(target);
|
||||
return navigated ? navigated.focus() : list[j].focus();
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
if (clients.openWindow) return clients.openWindow(target);
|
||||
})());
|
||||
});
|
||||
"#;
|
||||
let mut response = Response::new(cot::Body::fixed(script));
|
||||
response
|
||||
.headers_mut()
|
||||
.insert("content-type", "application/javascript".parse().unwrap());
|
||||
response
|
||||
.headers_mut()
|
||||
.insert("service-worker-allowed", "/".parse().unwrap());
|
||||
response.headers_mut().insert(
|
||||
"cache-control",
|
||||
"no-cache, no-store, must-revalidate".parse().unwrap(),
|
||||
);
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct FeedbackForm {
|
||||
feedback: String,
|
||||
@@ -400,28 +859,31 @@ async fn portal_media(
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.map(str::to_owned);
|
||||
|
||||
match {
|
||||
let content_type = match media.file_path.rsplit('.').next().unwrap_or("") {
|
||||
"jpg" | "jpeg" => "image/jpeg",
|
||||
"png" => "image/png",
|
||||
"heic" | "heif" => "image/heic",
|
||||
"webp" => "image/webp",
|
||||
"mp4" => "video/mp4",
|
||||
"mov" => "video/quicktime",
|
||||
"avi" => "video/x-msvideo",
|
||||
"mkv" => "video/x-matroska",
|
||||
"webm" => "video/webm",
|
||||
_ => "application/octet-stream",
|
||||
};
|
||||
crate::uploads::ranged_file_response(&media.file_path, content_type, range.as_deref()).await
|
||||
} {
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
let display_path =
|
||||
crate::uploads::media_delivery_paths(&media.file_type, &media.file_path).media_path;
|
||||
if storage.is_r2() {
|
||||
let url = storage
|
||||
.public_url(&display_path, String::new())
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
return Redirect::new(url).into_response();
|
||||
}
|
||||
|
||||
match crate::uploads::ranged_local_file_response(
|
||||
&display_path,
|
||||
crate::uploads::content_type_for_path(&display_path),
|
||||
range.as_deref(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(response) => Ok(response),
|
||||
Err(err) => {
|
||||
tracing::warn!(
|
||||
target: "uploads",
|
||||
media_id,
|
||||
db_path = %media.file_path,
|
||||
resolved_path = %crate::uploads::resolved_display_path(&media.file_path),
|
||||
db_path = %display_path,
|
||||
resolved_path = %crate::uploads::resolved_display_path(&display_path),
|
||||
error = %err,
|
||||
"portal media file is missing or unreadable"
|
||||
);
|
||||
@@ -430,6 +892,76 @@ async fn portal_media(
|
||||
}
|
||||
}
|
||||
|
||||
async fn portal_media_thumbnail(
|
||||
_request: Request,
|
||||
db: Database,
|
||||
Path((token, media_id)): Path<(String, i64)>,
|
||||
) -> cot::Result<Response> {
|
||||
let client = match query!(Client, $media_token == token).get(&db).await? {
|
||||
Some(client) if client.status != "deleted" => client,
|
||||
_ => return Html::new("404").into_response(),
|
||||
};
|
||||
let media = match query!(Media, $id == media_id).get(&db).await? {
|
||||
Some(media)
|
||||
if media.client_id.primary_key().unwrap() == client.id.unwrap()
|
||||
&& media.status == "active" =>
|
||||
{
|
||||
media
|
||||
}
|
||||
_ => return Html::new("404").into_response(),
|
||||
};
|
||||
if let Some(visit) = &media.visit_id {
|
||||
let visit_id = visit.primary_key().unwrap();
|
||||
match query!(Visit, $id == visit_id).get(&db).await? {
|
||||
Some(visit) if visit.status != "deleted" => {}
|
||||
_ => return Html::new("404").into_response(),
|
||||
}
|
||||
}
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
let display_path = match crate::uploads::ensure_media_delivery_paths(
|
||||
&storage,
|
||||
&media.file_type,
|
||||
&media.file_path,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(paths) => paths.thumbnail_path,
|
||||
Err(error) => {
|
||||
tracing::warn!(media_id, %error, "failed to create portal media thumbnail");
|
||||
if media.file_type == "photo" {
|
||||
media.file_path.clone()
|
||||
} else {
|
||||
return Html::new("404").into_response();
|
||||
}
|
||||
}
|
||||
};
|
||||
if storage.is_r2() {
|
||||
let url = storage
|
||||
.public_url(&display_path, String::new())
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
return Redirect::new(url).into_response();
|
||||
}
|
||||
let content_type = if display_path == media.file_path {
|
||||
crate::uploads::content_type_for_path(&media.file_path)
|
||||
} else {
|
||||
"image/jpeg"
|
||||
};
|
||||
match crate::uploads::ranged_local_file_response(&display_path, content_type, None).await {
|
||||
Ok(mut response) => {
|
||||
response.headers_mut().insert(
|
||||
"cache-control",
|
||||
"private, max-age=31536000, immutable".parse().unwrap(),
|
||||
);
|
||||
Ok(response)
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::warn!(media_id, %error, "failed to read portal media thumbnail");
|
||||
Html::new("404").into_response()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn serve_testimonial_image(
|
||||
_request: Request,
|
||||
db: Database,
|
||||
@@ -443,7 +975,15 @@ async fn serve_testimonial_image(
|
||||
Some(p) => p.clone(),
|
||||
None => return Html::new("404").into_response(),
|
||||
};
|
||||
match crate::uploads::read_db_file(&path).await {
|
||||
let storage = crate::uploads::Storage::load(&db).await?;
|
||||
if storage.is_r2() {
|
||||
let url = storage
|
||||
.public_url(&path, String::new())
|
||||
.await
|
||||
.map_err(crate::uploads::storage_error)?;
|
||||
return Redirect::new(url).into_response();
|
||||
}
|
||||
match storage.read(&path).await {
|
||||
Ok(data) => {
|
||||
let content_type = match path.rsplit('.').next().unwrap_or("") {
|
||||
"jpg" | "jpeg" => "image/jpeg",
|
||||
@@ -506,6 +1046,7 @@ async fn serve_static(_request: Request, Path(filename): Path<String>) -> cot::R
|
||||
},
|
||||
};
|
||||
let content_type = match ext {
|
||||
"css" => "text/css; charset=utf-8",
|
||||
"png" => "image/png",
|
||||
"jpg" | "jpeg" => "image/jpeg",
|
||||
"webp" => "image/webp",
|
||||
@@ -578,6 +1119,12 @@ pub fn public_router() -> Router {
|
||||
Router::with_urls([
|
||||
Route::with_handler_and_name("/", landing_page, "landing"),
|
||||
Route::with_handler_and_name("/favicon.svg", favicon, "favicon"),
|
||||
Route::with_handler_and_name(
|
||||
"/client/{token}/manifest.webmanifest",
|
||||
web_manifest,
|
||||
"web-manifest",
|
||||
),
|
||||
Route::with_handler_and_name("/service-worker.js", service_worker, "service-worker"),
|
||||
Route::with_handler_and_name("/static/{filename}", serve_static, "static-file"),
|
||||
Route::with_handler_and_name("/robots.txt", robots_txt, "robots-txt"),
|
||||
Route::with_handler_and_name("/sitemap.xml", sitemap_xml, "sitemap-xml"),
|
||||
@@ -588,6 +1135,16 @@ pub fn public_router() -> Router {
|
||||
"testimonial-image",
|
||||
),
|
||||
Route::with_handler_and_name("/client/{token}", client_portal, "client-portal"),
|
||||
Route::with_handler_and_name(
|
||||
"/client/{token}/push/subscribe",
|
||||
portal_push_subscribe,
|
||||
"client-push-subscribe",
|
||||
),
|
||||
Route::with_handler_and_name(
|
||||
"/client/{token}/push/unsubscribe",
|
||||
portal_push_unsubscribe,
|
||||
"client-push-unsubscribe",
|
||||
),
|
||||
Route::with_handler_and_name(
|
||||
"/client/{token}/{visit_id}/feedback",
|
||||
submit_feedback,
|
||||
@@ -598,5 +1155,10 @@ pub fn public_router() -> Router {
|
||||
portal_media,
|
||||
"client-media",
|
||||
),
|
||||
Route::with_handler_and_name(
|
||||
"/client/{token}/media/{media_id}/thumbnail",
|
||||
portal_media_thumbnail,
|
||||
"client-media-thumbnail",
|
||||
),
|
||||
])
|
||||
}
|
||||
|
||||
+873
-14
@@ -1,12 +1,403 @@
|
||||
use std::fmt;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
|
||||
use aws_sdk_s3::Client;
|
||||
use aws_sdk_s3::config::{BehaviorVersion, Credentials, Region};
|
||||
use aws_sdk_s3::presigning::PresigningConfig;
|
||||
use aws_sdk_s3::primitives::ByteStream;
|
||||
use cot::db::{Database, Model};
|
||||
use cot::response::Response;
|
||||
use cot::{Body, StatusCode};
|
||||
use image::codecs::jpeg::JpegEncoder;
|
||||
use tokio::io::{AsyncReadExt, AsyncSeekExt};
|
||||
use tokio::process::Command;
|
||||
|
||||
use crate::models::Setting;
|
||||
|
||||
const THUMBNAIL_MAX_DIMENSION: u32 = 360;
|
||||
const THUMBNAIL_JPEG_QUALITY: u8 = 70;
|
||||
pub const VIDEO_PREVIEW_FRAME_COUNT: usize = 4;
|
||||
const VIDEO_PREVIEW_FRAME_WIDTH: u32 = 320;
|
||||
const VIDEO_PREVIEW_FRAME_HEIGHT: u32 = 240;
|
||||
const PRESIGNED_URL_TTL: Duration = Duration::from_secs(6 * 60 * 60);
|
||||
|
||||
const DEFAULT_UPLOAD_DIR: &str = "uploads";
|
||||
const UPLOAD_DIR_ENV: &str = "WEB_PETTING_UPLOAD_DIR";
|
||||
|
||||
pub const R2_ENABLED_KEY: &str = "r2_enabled";
|
||||
pub const R2_ACCOUNT_ID_KEY: &str = "r2_account_id";
|
||||
pub const R2_BUCKET_KEY: &str = "r2_bucket";
|
||||
pub const R2_ACCESS_KEY_ID_KEY: &str = "r2_access_key_id";
|
||||
pub const R2_SECRET_ACCESS_KEY_KEY: &str = "r2_secret_access_key";
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StorageError(String);
|
||||
|
||||
impl StorageError {
|
||||
fn new(context: &str, error: impl fmt::Display) -> Self {
|
||||
Self(format!("{context}: {error}"))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for StorageError {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
formatter.write_str(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for StorageError {}
|
||||
|
||||
pub type StorageResult<T> = Result<T, StorageError>;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct R2Config {
|
||||
pub account_id: String,
|
||||
pub bucket: String,
|
||||
pub access_key_id: String,
|
||||
pub secret_access_key: String,
|
||||
}
|
||||
|
||||
impl R2Config {
|
||||
pub fn from_settings(settings: &[Setting]) -> Option<Self> {
|
||||
let value = |key: &str| {
|
||||
settings
|
||||
.iter()
|
||||
.find(|setting| setting.key == key)
|
||||
.map(|setting| setting.value.trim().to_string())
|
||||
.unwrap_or_default()
|
||||
};
|
||||
let config = Self {
|
||||
account_id: value(R2_ACCOUNT_ID_KEY),
|
||||
bucket: value(R2_BUCKET_KEY),
|
||||
access_key_id: value(R2_ACCESS_KEY_ID_KEY),
|
||||
secret_access_key: value(R2_SECRET_ACCESS_KEY_KEY),
|
||||
};
|
||||
config.is_valid().then_some(config)
|
||||
}
|
||||
|
||||
pub fn fields_are_valid(
|
||||
account_id: &str,
|
||||
bucket: &str,
|
||||
access_key_id: &str,
|
||||
secret_access_key: &str,
|
||||
) -> bool {
|
||||
let account_id = account_id.trim();
|
||||
let bucket = bucket.trim();
|
||||
account_id.len() == 32
|
||||
&& account_id.bytes().all(|byte| byte.is_ascii_hexdigit())
|
||||
&& (3..=63).contains(&bucket.len())
|
||||
&& !bucket.starts_with('-')
|
||||
&& !bucket.ends_with('-')
|
||||
&& bucket
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_lowercase() || byte.is_ascii_digit() || byte == b'-')
|
||||
&& !access_key_id.trim().is_empty()
|
||||
&& !secret_access_key.trim().is_empty()
|
||||
}
|
||||
|
||||
pub fn is_valid(&self) -> bool {
|
||||
Self::fields_are_valid(
|
||||
&self.account_id,
|
||||
&self.bucket,
|
||||
&self.access_key_id,
|
||||
&self.secret_access_key,
|
||||
)
|
||||
}
|
||||
|
||||
fn endpoint(&self) -> String {
|
||||
format!("https://{}.r2.cloudflarestorage.com", self.account_id)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct R2Storage {
|
||||
client: Client,
|
||||
bucket: String,
|
||||
}
|
||||
|
||||
impl R2Storage {
|
||||
fn new(config: R2Config) -> Self {
|
||||
let endpoint = config.endpoint();
|
||||
let bucket = config.bucket.clone();
|
||||
let credentials = Credentials::new(
|
||||
config.access_key_id,
|
||||
config.secret_access_key,
|
||||
None,
|
||||
None,
|
||||
"web-petting-r2",
|
||||
);
|
||||
let sdk_config = aws_sdk_s3::Config::builder()
|
||||
.behavior_version(BehaviorVersion::latest())
|
||||
.endpoint_url(endpoint)
|
||||
.credentials_provider(credentials)
|
||||
.region(Region::new("auto"))
|
||||
.build();
|
||||
Self {
|
||||
client: Client::from_conf(sdk_config),
|
||||
bucket,
|
||||
}
|
||||
}
|
||||
|
||||
async fn put(&self, db_path: &str, data: &[u8]) -> StorageResult<()> {
|
||||
self.put_stream(db_path, ByteStream::from(data.to_vec()))
|
||||
.await
|
||||
}
|
||||
|
||||
async fn put_stream(&self, db_path: &str, body: ByteStream) -> StorageResult<()> {
|
||||
self.client
|
||||
.put_object()
|
||||
.bucket(&self.bucket)
|
||||
.key(object_key(db_path))
|
||||
.content_type(content_type_for_path(db_path))
|
||||
.cache_control("private, max-age=21600")
|
||||
.body(body)
|
||||
.send()
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to upload object to R2", error))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get(&self, db_path: &str) -> StorageResult<Vec<u8>> {
|
||||
let response = self
|
||||
.client
|
||||
.get_object()
|
||||
.bucket(&self.bucket)
|
||||
.key(object_key(db_path))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to download object from R2", error))?;
|
||||
let bytes = response
|
||||
.body
|
||||
.collect()
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to read R2 response body", error))?;
|
||||
Ok(bytes.into_bytes().to_vec())
|
||||
}
|
||||
|
||||
pub async fn download_to_path(&self, db_path: &str, destination: &Path) -> StorageResult<()> {
|
||||
let response = self
|
||||
.client
|
||||
.get_object()
|
||||
.bucket(&self.bucket)
|
||||
.key(object_key(db_path))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to download object from R2", error))?;
|
||||
let mut reader = response.body.into_async_read();
|
||||
let mut file = tokio::fs::File::create(destination)
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to create temporary media file", error))?;
|
||||
tokio::io::copy(&mut reader, &mut file)
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to stream R2 object to disk", error))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete(&self, db_path: &str) -> StorageResult<()> {
|
||||
self.client
|
||||
.delete_object()
|
||||
.bucket(&self.bucket)
|
||||
.key(object_key(db_path))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to delete object from R2", error))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn exists(&self, db_path: &str) -> StorageResult<bool> {
|
||||
match self
|
||||
.client
|
||||
.head_object()
|
||||
.bucket(&self.bucket)
|
||||
.key(object_key(db_path))
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Ok(_) => Ok(true),
|
||||
Err(error)
|
||||
if error
|
||||
.as_service_error()
|
||||
.is_some_and(|service_error| service_error.is_not_found()) =>
|
||||
{
|
||||
Ok(false)
|
||||
}
|
||||
Err(error) => Err(StorageError::new("failed to inspect R2 object", error)),
|
||||
}
|
||||
}
|
||||
|
||||
async fn presigned_get_url(&self, db_path: &str) -> StorageResult<String> {
|
||||
let config = PresigningConfig::expires_in(PRESIGNED_URL_TTL)
|
||||
.map_err(|error| StorageError::new("failed to configure R2 signed URL", error))?;
|
||||
let request = self
|
||||
.client
|
||||
.get_object()
|
||||
.bucket(&self.bucket)
|
||||
.key(object_key(db_path))
|
||||
.presigned(config)
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to sign R2 object URL", error))?;
|
||||
Ok(request.uri().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum Storage {
|
||||
Local,
|
||||
R2(R2Storage),
|
||||
}
|
||||
|
||||
impl Storage {
|
||||
pub async fn load(db: &Database) -> cot::Result<Self> {
|
||||
let settings = Setting::objects().all(db).await?;
|
||||
let enabled = settings
|
||||
.iter()
|
||||
.find(|setting| setting.key == R2_ENABLED_KEY)
|
||||
.map(|setting| setting.value == "true")
|
||||
.unwrap_or(false);
|
||||
if !enabled {
|
||||
return Ok(Self::Local);
|
||||
}
|
||||
match R2Config::from_settings(&settings) {
|
||||
Some(config) => Ok(Self::R2(R2Storage::new(config))),
|
||||
None => {
|
||||
tracing::error!(
|
||||
target: "uploads",
|
||||
"R2 is enabled but its configuration is incomplete; using local storage"
|
||||
);
|
||||
Ok(Self::Local)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Load configured R2 even when it is not enabled yet. This lets the
|
||||
/// one-time migration run before the site is switched away from local storage.
|
||||
#[allow(dead_code)]
|
||||
pub async fn load_configured_r2(db: &Database) -> cot::Result<Self> {
|
||||
let settings = Setting::objects().all(db).await?;
|
||||
let config = R2Config::from_settings(&settings).ok_or_else(|| {
|
||||
cot::Error::internal("R2 settings are missing or invalid".to_string())
|
||||
})?;
|
||||
Ok(Self::R2(R2Storage::new(config)))
|
||||
}
|
||||
|
||||
pub fn is_r2(&self) -> bool {
|
||||
matches!(self, Self::R2(_))
|
||||
}
|
||||
|
||||
pub async fn create_logical_dir(&self, db_dir: &str) -> StorageResult<()> {
|
||||
if matches!(self, Self::Local) {
|
||||
tokio::fs::create_dir_all(resolve_db_path(db_dir))
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to create upload directory", error))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn write(&self, db_path: &str, data: &[u8]) -> StorageResult<()> {
|
||||
match self {
|
||||
Self::Local => {
|
||||
let physical_path = resolve_db_path(db_path);
|
||||
if let Some(parent) = physical_path.parent() {
|
||||
tokio::fs::create_dir_all(parent).await.map_err(|error| {
|
||||
StorageError::new("failed to create upload directory", error)
|
||||
})?;
|
||||
}
|
||||
tokio::fs::write(physical_path, data)
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to write uploaded file", error))
|
||||
}
|
||||
Self::R2(storage) => storage.put(db_path, data).await,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn read(&self, db_path: &str) -> StorageResult<Vec<u8>> {
|
||||
match self {
|
||||
Self::Local => tokio::fs::read(resolve_db_path(db_path))
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to read uploaded file", error)),
|
||||
Self::R2(storage) => storage.get(db_path).await,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn remove(&self, db_path: &str) -> StorageResult<()> {
|
||||
match self {
|
||||
Self::Local => match tokio::fs::remove_file(resolve_db_path(db_path)).await {
|
||||
Ok(()) => Ok(()),
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(()),
|
||||
Err(error) => Err(StorageError::new("failed to remove uploaded file", error)),
|
||||
},
|
||||
Self::R2(storage) => storage.delete(db_path).await,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn exists(&self, db_path: &str) -> StorageResult<bool> {
|
||||
match self {
|
||||
Self::Local => tokio::fs::try_exists(resolve_db_path(db_path))
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to inspect uploaded file", error)),
|
||||
Self::R2(storage) => storage.exists(db_path).await,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn public_url(&self, db_path: &str, local_fallback: String) -> StorageResult<String> {
|
||||
match self {
|
||||
Self::Local => Ok(local_fallback),
|
||||
Self::R2(storage) => storage.presigned_get_url(db_path).await,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn download_to_path(&self, db_path: &str, destination: &Path) -> StorageResult<()> {
|
||||
match self {
|
||||
Self::Local => {
|
||||
tokio::fs::copy(resolve_db_path(db_path), destination)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
StorageError::new("failed to copy local media to temporary file", error)
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
Self::R2(storage) => storage.download_to_path(db_path, destination).await,
|
||||
}
|
||||
}
|
||||
|
||||
/// Stream a local PVC file into R2 without loading large videos into memory.
|
||||
#[allow(dead_code)]
|
||||
pub async fn upload_local_copy(&self, db_path: &str, local_path: &Path) -> StorageResult<()> {
|
||||
let Self::R2(storage) = self else {
|
||||
return Err(StorageError::new(
|
||||
"failed to migrate local file",
|
||||
"R2 storage is not configured",
|
||||
));
|
||||
};
|
||||
let metadata = tokio::fs::metadata(local_path).await.map_err(|error| {
|
||||
StorageError::new(
|
||||
&format!(
|
||||
"failed to inspect local migration file {}",
|
||||
local_path.display()
|
||||
),
|
||||
error,
|
||||
)
|
||||
})?;
|
||||
if !metadata.is_file() || metadata.len() == 0 {
|
||||
return Err(StorageError::new(
|
||||
"failed to open local file for migration",
|
||||
format!("{} is not a non-empty file", local_path.display()),
|
||||
));
|
||||
}
|
||||
let body = ByteStream::from_path(local_path).await.map_err(|error| {
|
||||
StorageError::new(
|
||||
&format!(
|
||||
"failed to open local file for migration {}",
|
||||
local_path.display()
|
||||
),
|
||||
error,
|
||||
)
|
||||
})?;
|
||||
storage.put_stream(db_path, body).await
|
||||
}
|
||||
}
|
||||
|
||||
pub fn media_dir(client_id: i64, visit_id: i64) -> String {
|
||||
format!("{DEFAULT_UPLOAD_DIR}/{client_id}/{visit_id}")
|
||||
}
|
||||
@@ -41,20 +432,416 @@ pub fn resolved_display_path(db_path: &str) -> String {
|
||||
resolve_db_path(db_path).display().to_string()
|
||||
}
|
||||
|
||||
pub async fn create_logical_dir(db_dir: &str) -> std::io::Result<()> {
|
||||
tokio::fs::create_dir_all(resolve_db_path(db_dir)).await
|
||||
pub fn object_key(db_path: &str) -> String {
|
||||
db_path
|
||||
.replace('\\', "/")
|
||||
.trim_start_matches('/')
|
||||
.to_string()
|
||||
}
|
||||
|
||||
pub async fn write_db_file(db_path: &str, data: &[u8]) -> std::io::Result<()> {
|
||||
let physical_path = resolve_db_path(db_path);
|
||||
if let Some(parent) = physical_path.parent() {
|
||||
tokio::fs::create_dir_all(parent).await?;
|
||||
pub fn thumbnail_db_path(db_path: &str) -> String {
|
||||
match db_path.rsplit_once('.') {
|
||||
Some((stem, _)) => format!("{stem}.thumb.jpg"),
|
||||
None => format!("{db_path}.thumb.jpg"),
|
||||
}
|
||||
tokio::fs::write(physical_path, data).await
|
||||
}
|
||||
|
||||
pub async fn read_db_file(db_path: &str) -> std::io::Result<Vec<u8>> {
|
||||
tokio::fs::read(resolve_db_path(db_path)).await
|
||||
pub fn normalized_video_db_path(db_path: &str) -> String {
|
||||
match db_path.rsplit_once('.') {
|
||||
Some((stem, _)) if stem.ends_with(".web") => format!("{stem}.mp4"),
|
||||
Some((stem, _)) => format!("{stem}.web.mp4"),
|
||||
None => format!("{db_path}.web.mp4"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn supports_thumbnail(db_path: &str) -> bool {
|
||||
matches!(
|
||||
db_path
|
||||
.rsplit('.')
|
||||
.next()
|
||||
.unwrap_or("")
|
||||
.to_ascii_lowercase()
|
||||
.as_str(),
|
||||
"jpg" | "jpeg" | "png" | "webp"
|
||||
)
|
||||
}
|
||||
|
||||
pub fn supports_video_preview(db_path: &str) -> bool {
|
||||
matches!(
|
||||
db_path
|
||||
.rsplit('.')
|
||||
.next()
|
||||
.unwrap_or("")
|
||||
.to_ascii_lowercase()
|
||||
.as_str(),
|
||||
"mp4" | "mov" | "avi" | "mkv" | "webm"
|
||||
)
|
||||
}
|
||||
|
||||
pub fn content_type_for_path(path: &str) -> &'static str {
|
||||
match path
|
||||
.rsplit('.')
|
||||
.next()
|
||||
.unwrap_or("")
|
||||
.to_ascii_lowercase()
|
||||
.as_str()
|
||||
{
|
||||
"jpg" | "jpeg" => "image/jpeg",
|
||||
"png" => "image/png",
|
||||
"heic" | "heif" => "image/heic",
|
||||
"webp" => "image/webp",
|
||||
"mp4" => "video/mp4",
|
||||
"mov" => "video/quicktime",
|
||||
"avi" => "video/x-msvideo",
|
||||
"mkv" => "video/x-matroska",
|
||||
"webm" => "video/webm",
|
||||
_ => "application/octet-stream",
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_thumbnail(data: &[u8]) -> StorageResult<Vec<u8>> {
|
||||
let image = image::load_from_memory(data)
|
||||
.map_err(|error| StorageError::new("failed to decode image for thumbnail", error))?;
|
||||
let thumbnail = image.thumbnail(THUMBNAIL_MAX_DIMENSION, THUMBNAIL_MAX_DIMENSION);
|
||||
let rgb = thumbnail.to_rgb8();
|
||||
let mut encoded = Vec::new();
|
||||
let mut encoder = JpegEncoder::new_with_quality(&mut encoded, THUMBNAIL_JPEG_QUALITY);
|
||||
encoder
|
||||
.encode_image(&rgb)
|
||||
.map_err(|error| StorageError::new("failed to encode image thumbnail", error))?;
|
||||
Ok(encoded)
|
||||
}
|
||||
|
||||
pub async fn ensure_thumbnail(storage: &Storage, db_path: &str) -> StorageResult<String> {
|
||||
let thumbnail_path = thumbnail_db_path(db_path);
|
||||
if storage.exists(&thumbnail_path).await? {
|
||||
return Ok(thumbnail_path);
|
||||
}
|
||||
let data = storage.read(db_path).await?;
|
||||
write_thumbnail(storage, db_path, &data).await?;
|
||||
Ok(thumbnail_path)
|
||||
}
|
||||
|
||||
pub async fn write_thumbnail(
|
||||
storage: &Storage,
|
||||
db_path: &str,
|
||||
source_data: &[u8],
|
||||
) -> StorageResult<String> {
|
||||
let thumbnail_path = thumbnail_db_path(db_path);
|
||||
let encoded = encode_thumbnail(source_data)?;
|
||||
storage.write(&thumbnail_path, &encoded).await?;
|
||||
Ok(thumbnail_path)
|
||||
}
|
||||
|
||||
/// Create a missing thumbnail from the local PVC even when R2 is enabled.
|
||||
#[allow(dead_code)]
|
||||
pub async fn ensure_local_thumbnail(db_path: &str) -> StorageResult<String> {
|
||||
let thumbnail_path = thumbnail_db_path(db_path);
|
||||
if tokio::fs::try_exists(resolve_db_path(&thumbnail_path))
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to inspect local thumbnail", error))?
|
||||
{
|
||||
return Ok(thumbnail_path);
|
||||
}
|
||||
let data = tokio::fs::read(resolve_db_path(db_path))
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to read local image", error))?;
|
||||
let encoded = encode_thumbnail(&data)?;
|
||||
let physical_path = resolve_db_path(&thumbnail_path);
|
||||
if let Some(parent) = physical_path.parent() {
|
||||
tokio::fs::create_dir_all(parent)
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to create thumbnail directory", error))?;
|
||||
}
|
||||
tokio::fs::write(physical_path, encoded)
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to write local thumbnail", error))?;
|
||||
Ok(thumbnail_path)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MediaDeliveryPaths {
|
||||
pub media_path: String,
|
||||
pub thumbnail_path: String,
|
||||
}
|
||||
|
||||
async fn create_video_workspace() -> StorageResult<PathBuf> {
|
||||
let path = std::env::temp_dir().join(format!(
|
||||
"web-petting-video-preview-{}",
|
||||
uuid::Uuid::new_v4()
|
||||
));
|
||||
tokio::fs::create_dir(&path)
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to create video workspace", error))?;
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
async fn run_media_command(command: &mut Command, context: &str) -> StorageResult<()> {
|
||||
let output = command
|
||||
.output()
|
||||
.await
|
||||
.map_err(|error| StorageError::new(context, error))?;
|
||||
if output.status.success() {
|
||||
return Ok(());
|
||||
}
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
Err(StorageError::new(
|
||||
context,
|
||||
stderr
|
||||
.trim()
|
||||
.lines()
|
||||
.last()
|
||||
.unwrap_or("unknown ffmpeg error"),
|
||||
))
|
||||
}
|
||||
|
||||
fn video_transcode_command(source: &Path, destination: &Path, include_audio: bool) -> Command {
|
||||
let mut command = Command::new("ffmpeg");
|
||||
command
|
||||
.args([
|
||||
"-hide_banner",
|
||||
"-loglevel",
|
||||
"error",
|
||||
"-y",
|
||||
"-ignore_unknown",
|
||||
"-i",
|
||||
])
|
||||
.arg(source)
|
||||
.args(["-map", "0:v:0"]);
|
||||
if include_audio {
|
||||
command.args(["-map", "0:a:0?"]);
|
||||
} else {
|
||||
command.arg("-an");
|
||||
}
|
||||
command
|
||||
.args(["-map_metadata", "-1", "-map_chapters", "-1", "-sn", "-dn"])
|
||||
.args([
|
||||
"-vf",
|
||||
"scale=w='min(1280,iw)':h='min(1280,ih)':force_original_aspect_ratio=decrease:force_divisible_by=2",
|
||||
"-c:v",
|
||||
"libx264",
|
||||
"-preset",
|
||||
"fast",
|
||||
"-crf",
|
||||
"26",
|
||||
"-pix_fmt",
|
||||
"yuv420p",
|
||||
"-tag:v",
|
||||
"avc1",
|
||||
"-c:a",
|
||||
"aac",
|
||||
"-b:a",
|
||||
"96k",
|
||||
"-movflags",
|
||||
"+faststart",
|
||||
"-threads",
|
||||
"2",
|
||||
])
|
||||
.arg(destination);
|
||||
command
|
||||
}
|
||||
|
||||
async fn transcode_video_for_browser(source: &Path, destination: &Path) -> StorageResult<()> {
|
||||
let mut with_audio = video_transcode_command(source, destination, true);
|
||||
match run_media_command(&mut with_audio, "failed to transcode video with ffmpeg").await {
|
||||
Ok(()) => Ok(()),
|
||||
Err(audio_error) => {
|
||||
// Some iPhone MOV files contain a second, audio-like service stream
|
||||
// with no decoder. Preserve audio when possible, but keep the video
|
||||
// usable by retrying without that stream.
|
||||
let mut video_only = video_transcode_command(source, destination, false);
|
||||
run_media_command(
|
||||
&mut video_only,
|
||||
&format!("{audio_error}; video-only fallback also failed"),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn video_duration(source: &Path) -> StorageResult<f64> {
|
||||
let mut command = Command::new("ffprobe");
|
||||
command
|
||||
.args([
|
||||
"-v",
|
||||
"error",
|
||||
"-show_entries",
|
||||
"format=duration",
|
||||
"-of",
|
||||
"default=noprint_wrappers=1:nokey=1",
|
||||
])
|
||||
.arg(source);
|
||||
let output = command
|
||||
.output()
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to inspect video with ffprobe", error))?;
|
||||
if !output.status.success() {
|
||||
return Err(StorageError::new(
|
||||
"failed to inspect video with ffprobe",
|
||||
String::from_utf8_lossy(&output.stderr).trim(),
|
||||
));
|
||||
}
|
||||
let duration = String::from_utf8_lossy(&output.stdout)
|
||||
.trim()
|
||||
.parse::<f64>()
|
||||
.map_err(|error| StorageError::new("failed to parse video duration", error))?;
|
||||
if !duration.is_finite() || duration <= 0.0 {
|
||||
return Err(StorageError::new(
|
||||
"failed to inspect video duration",
|
||||
"duration is zero or invalid",
|
||||
));
|
||||
}
|
||||
Ok(duration)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn validate_video_file(source: &Path) -> StorageResult<()> {
|
||||
video_duration(source).await.map(|_| ())
|
||||
}
|
||||
|
||||
async fn create_video_sprite(source: &Path, destination: &Path) -> StorageResult<()> {
|
||||
let duration = video_duration(source).await?;
|
||||
let frame_times = [0.08, 0.34, 0.60, 0.86].map(|position| duration * position);
|
||||
let mut command = Command::new("ffmpeg");
|
||||
command.args(["-hide_banner", "-loglevel", "error", "-y"]);
|
||||
for timestamp in frame_times {
|
||||
command
|
||||
.arg("-ss")
|
||||
.arg(format!("{timestamp:.3}"))
|
||||
.arg("-i")
|
||||
.arg(source);
|
||||
}
|
||||
let frame_filter = format!(
|
||||
"scale={VIDEO_PREVIEW_FRAME_WIDTH}:{VIDEO_PREVIEW_FRAME_HEIGHT}:force_original_aspect_ratio=decrease,pad={VIDEO_PREVIEW_FRAME_WIDTH}:{VIDEO_PREVIEW_FRAME_HEIGHT}:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1"
|
||||
);
|
||||
let filter = format!(
|
||||
"[0:v]{frame_filter}[v0];[1:v]{frame_filter}[v1];[2:v]{frame_filter}[v2];[3:v]{frame_filter}[v3];[v0][v1][v2][v3]hstack=inputs={VIDEO_PREVIEW_FRAME_COUNT}[out]"
|
||||
);
|
||||
command
|
||||
.arg("-filter_complex")
|
||||
.arg(filter)
|
||||
.args(["-map", "[out]", "-frames:v", "1", "-q:v", "4"])
|
||||
.arg(destination);
|
||||
run_media_command(&mut command, "failed to create video preview with ffmpeg").await
|
||||
}
|
||||
|
||||
pub async fn create_video_thumbnail_file(source: &Path, destination: &Path) -> StorageResult<()> {
|
||||
create_video_sprite(source, destination).await
|
||||
}
|
||||
|
||||
/// Create the compact browser MP4 and its four-frame JPEG sprite on disk.
|
||||
/// The source path is only read and is never changed or removed.
|
||||
pub async fn create_compact_video_files(
|
||||
source: &Path,
|
||||
video_destination: &Path,
|
||||
thumbnail_destination: &Path,
|
||||
) -> StorageResult<()> {
|
||||
let result = async {
|
||||
transcode_video_for_browser(source, video_destination).await?;
|
||||
create_video_sprite(video_destination, thumbnail_destination).await
|
||||
}
|
||||
.await;
|
||||
if result.is_err() {
|
||||
let _ = tokio::fs::remove_file(video_destination).await;
|
||||
let _ = tokio::fs::remove_file(thumbnail_destination).await;
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
/// Convert an incoming upload and store only the compact browser MP4 and its
|
||||
/// JPEG sprite. The original upload bytes are never written to storage.
|
||||
pub async fn write_compact_video(
|
||||
storage: &Storage,
|
||||
db_path: &str,
|
||||
source_extension: &str,
|
||||
source_data: &[u8],
|
||||
) -> StorageResult<()> {
|
||||
let workspace = create_video_workspace().await?;
|
||||
let source = workspace.join(format!("source.{source_extension}"));
|
||||
let compact_video = workspace.join("video.mp4");
|
||||
let thumbnail = workspace.join("preview.jpg");
|
||||
let result = async {
|
||||
tokio::fs::write(&source, source_data)
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to write temporary video", error))?;
|
||||
create_compact_video_files(&source, &compact_video, &thumbnail).await?;
|
||||
let video_data = tokio::fs::read(&compact_video)
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to read transcoded video", error))?;
|
||||
let thumbnail_data = tokio::fs::read(&thumbnail)
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to read video preview", error))?;
|
||||
let thumbnail_path = thumbnail_db_path(db_path);
|
||||
storage.write(db_path, &video_data).await?;
|
||||
storage.write(&thumbnail_path, &thumbnail_data).await?;
|
||||
Ok(())
|
||||
}
|
||||
.await;
|
||||
let _ = tokio::fs::remove_dir_all(&workspace).await;
|
||||
result
|
||||
}
|
||||
|
||||
/// Create and persist a missing video sprite. In R2 mode the compact source is
|
||||
/// downloaded only once; subsequent page loads reuse the generated JPEG.
|
||||
pub async fn ensure_video_thumbnail(storage: &Storage, db_path: &str) -> StorageResult<String> {
|
||||
let thumbnail_path = thumbnail_db_path(db_path);
|
||||
if storage.exists(&thumbnail_path).await? {
|
||||
return Ok(thumbnail_path);
|
||||
}
|
||||
|
||||
let workspace = create_video_workspace().await?;
|
||||
let extension = db_path.rsplit('.').next().unwrap_or("mp4");
|
||||
let source = workspace.join(format!("source.{extension}"));
|
||||
let thumbnail = workspace.join("preview.jpg");
|
||||
let result = async {
|
||||
storage.download_to_path(db_path, &source).await?;
|
||||
create_video_thumbnail_file(&source, &thumbnail).await?;
|
||||
let data = tokio::fs::read(&thumbnail)
|
||||
.await
|
||||
.map_err(|error| StorageError::new("failed to read video preview", error))?;
|
||||
storage.write(&thumbnail_path, &data).await?;
|
||||
Ok(thumbnail_path.clone())
|
||||
}
|
||||
.await;
|
||||
let _ = tokio::fs::remove_dir_all(&workspace).await;
|
||||
result
|
||||
}
|
||||
|
||||
pub async fn ensure_media_delivery_paths(
|
||||
storage: &Storage,
|
||||
file_type: &str,
|
||||
db_path: &str,
|
||||
) -> StorageResult<MediaDeliveryPaths> {
|
||||
if file_type == "video" && supports_video_preview(db_path) {
|
||||
let thumbnail_path = ensure_video_thumbnail(storage, db_path).await?;
|
||||
return Ok(MediaDeliveryPaths {
|
||||
media_path: db_path.to_string(),
|
||||
thumbnail_path,
|
||||
});
|
||||
}
|
||||
let thumbnail_path = if file_type == "photo" && supports_thumbnail(db_path) {
|
||||
ensure_thumbnail(storage, db_path).await?
|
||||
} else {
|
||||
db_path.to_string()
|
||||
};
|
||||
Ok(MediaDeliveryPaths {
|
||||
media_path: db_path.to_string(),
|
||||
thumbnail_path,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn media_delivery_paths(file_type: &str, db_path: &str) -> MediaDeliveryPaths {
|
||||
let thumbnail_path = if (file_type == "photo" && supports_thumbnail(db_path))
|
||||
|| (file_type == "video" && supports_video_preview(db_path))
|
||||
{
|
||||
thumbnail_db_path(db_path)
|
||||
} else {
|
||||
db_path.to_string()
|
||||
};
|
||||
MediaDeliveryPaths {
|
||||
media_path: db_path.to_string(),
|
||||
thumbnail_path,
|
||||
}
|
||||
}
|
||||
|
||||
enum ByteRange {
|
||||
@@ -112,8 +899,8 @@ fn parse_byte_range(header: Option<&str>, file_len: u64) -> ByteRange {
|
||||
ByteRange::Partial { start, end }
|
||||
}
|
||||
|
||||
/// Read a file into an HTTP response, honoring a single `Range: bytes=...` request.
|
||||
pub async fn ranged_file_response(
|
||||
/// Read a local file into an HTTP response, honoring one `Range: bytes=...` request.
|
||||
pub async fn ranged_local_file_response(
|
||||
db_path: &str,
|
||||
content_type: &str,
|
||||
range_header: Option<&str>,
|
||||
@@ -174,13 +961,33 @@ pub async fn ranged_file_response(
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub async fn remove_db_file(db_path: &str) -> std::io::Result<()> {
|
||||
tokio::fs::remove_file(resolve_db_path(db_path)).await
|
||||
pub fn storage_error(error: StorageError) -> cot::Error {
|
||||
cot::Error::internal(error.to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{ByteRange, parse_byte_range};
|
||||
use super::{
|
||||
ByteRange, R2Config, R2Storage, normalized_video_db_path, object_key, parse_byte_range,
|
||||
supports_video_preview, thumbnail_db_path,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn creates_stable_normalized_video_paths() {
|
||||
assert_eq!(
|
||||
normalized_video_db_path("uploads/1/report.mov"),
|
||||
"uploads/1/report.web.mp4"
|
||||
);
|
||||
assert_eq!(
|
||||
normalized_video_db_path("uploads/1/report.web.mp4"),
|
||||
"uploads/1/report.web.mp4"
|
||||
);
|
||||
assert_eq!(
|
||||
thumbnail_db_path("uploads/1/report.web.mp4"),
|
||||
"uploads/1/report.web.thumb.jpg"
|
||||
);
|
||||
assert!(supports_video_preview("report.MOV"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_byte_ranges() {
|
||||
@@ -201,4 +1008,56 @@ mod tests {
|
||||
ByteRange::Unsatisfiable
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validates_r2_fields() {
|
||||
assert!(R2Config::fields_are_valid(
|
||||
"0123456789abcdef0123456789abcdef",
|
||||
"pet-media",
|
||||
"access-key",
|
||||
"secret-key",
|
||||
));
|
||||
assert!(!R2Config::fields_are_valid(
|
||||
"not-an-account",
|
||||
"pet-media",
|
||||
"access-key",
|
||||
"secret-key",
|
||||
));
|
||||
assert!(!R2Config::fields_are_valid(
|
||||
"0123456789abcdef0123456789abcdef",
|
||||
"Invalid_Bucket",
|
||||
"access-key",
|
||||
"secret-key",
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn converts_database_paths_to_object_keys() {
|
||||
assert_eq!(object_key("uploads/1/photo.jpg"), "uploads/1/photo.jpg");
|
||||
assert_eq!(
|
||||
object_key("/data/uploads/photo.jpg"),
|
||||
"data/uploads/photo.jpg"
|
||||
);
|
||||
assert_eq!(object_key("uploads\\1\\photo.jpg"), "uploads/1/photo.jpg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn signs_r2_urls_for_six_hours() {
|
||||
let storage = R2Storage::new(R2Config {
|
||||
account_id: "0123456789abcdef0123456789abcdef".to_string(),
|
||||
bucket: "pet-media".to_string(),
|
||||
access_key_id: "access-key".to_string(),
|
||||
secret_access_key: "secret-key".to_string(),
|
||||
});
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
let url = runtime
|
||||
.block_on(storage.presigned_get_url("uploads/1/photo.jpg"))
|
||||
.unwrap();
|
||||
assert!(url.contains("X-Amz-Expires=21600"));
|
||||
assert!(url.contains("uploads/1/photo.jpg"));
|
||||
assert!(url.contains("pet-media"));
|
||||
}
|
||||
}
|
||||
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
|
||||
use cot::db::{Database, Model, query};
|
||||
use serde_json::json;
|
||||
use web_push_native::jwt_simple::algorithms::ES256KeyPair;
|
||||
use web_push_native::p256::PublicKey;
|
||||
use web_push_native::{Auth, WebPushBuilder};
|
||||
|
||||
use crate::models::{Client, PushSubscription, Setting, Visit};
|
||||
|
||||
pub struct VapidConfig {
|
||||
pub public_key: String,
|
||||
private_key: String,
|
||||
subject: String,
|
||||
}
|
||||
|
||||
fn normalize_key_pair(public_key: &str, private_key: &str) -> Option<(String, String)> {
|
||||
let strip_assignment = |value: &str, name: &str| {
|
||||
value
|
||||
.trim()
|
||||
.strip_prefix(&format!("{name}="))
|
||||
.unwrap_or(value.trim())
|
||||
.trim()
|
||||
.to_string()
|
||||
};
|
||||
let public_key = strip_assignment(public_key, "WEB_PETTING_VAPID_PUBLIC_KEY");
|
||||
let private_key = strip_assignment(private_key, "WEB_PETTING_VAPID_PRIVATE_KEY");
|
||||
let public_bytes = URL_SAFE_NO_PAD.decode(&public_key).ok()?;
|
||||
let private_bytes = URL_SAFE_NO_PAD.decode(&private_key).ok()?;
|
||||
|
||||
if public_bytes.len() == 65 && public_bytes.first() == Some(&4) && private_bytes.len() == 32 {
|
||||
return Some((public_key, private_key));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub async fn load_config(db: &Database) -> Option<VapidConfig> {
|
||||
let settings = Setting::objects().all(db).await.ok()?;
|
||||
let value = |key: &str| {
|
||||
settings
|
||||
.iter()
|
||||
.find(|setting| setting.key == key)
|
||||
.map(|setting| setting.value.trim().to_string())
|
||||
.filter(|value| !value.is_empty())
|
||||
};
|
||||
let raw_public_key = value("vapid_public_key")?;
|
||||
let raw_private_key = value("vapid_private_key")?;
|
||||
let (public_key, private_key) = match normalize_key_pair(&raw_public_key, &raw_private_key) {
|
||||
Some(keys) => keys,
|
||||
None => {
|
||||
tracing::warn!("invalid VAPID configuration in database");
|
||||
return None;
|
||||
}
|
||||
};
|
||||
let subject_value =
|
||||
value("vapid_subject").unwrap_or_else(|| "mailto:admin@localhost".to_string());
|
||||
let subject = subject_value
|
||||
.strip_prefix("WEB_PETTING_VAPID_SUBJECT=")
|
||||
.unwrap_or(&subject_value)
|
||||
.trim()
|
||||
.to_string();
|
||||
Some(VapidConfig {
|
||||
public_key,
|
||||
private_key,
|
||||
subject,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn initialize(db: &Database) {
|
||||
if load_config(db).await.is_some() {
|
||||
tracing::info!("VAPID configuration loaded from database");
|
||||
} else {
|
||||
tracing::info!("VAPID configuration is not set; client Web Push is disabled");
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn notify_visit_completed(db: &Database, visit: &Visit) {
|
||||
let setting_key = "client_notifications_enabled".to_string();
|
||||
let enabled = query!(Setting, $key == setting_key)
|
||||
.get(db)
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|setting| setting.value == "true")
|
||||
.unwrap_or(false);
|
||||
let Some(config) = load_config(db).await else {
|
||||
return;
|
||||
};
|
||||
if !enabled {
|
||||
return;
|
||||
}
|
||||
|
||||
let client_id = visit.client_id.primary_key().unwrap();
|
||||
let client = match query!(Client, $id == client_id).get(db).await {
|
||||
Ok(Some(client)) => client,
|
||||
_ => return,
|
||||
};
|
||||
let active = "active".to_string();
|
||||
let subscriptions = match query!(PushSubscription, $status == active).all(db).await {
|
||||
Ok(items) => items
|
||||
.into_iter()
|
||||
.filter(|item| item.client_id.primary_key().unwrap() == client_id)
|
||||
.collect::<Vec<_>>(),
|
||||
Err(error) => {
|
||||
tracing::warn!(%error, "failed to load Web Push subscriptions");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let mut visible_visits = match Visit::objects().all(db).await {
|
||||
Ok(visits) => visits
|
||||
.into_iter()
|
||||
.filter(|item| {
|
||||
item.client_id.primary_key().unwrap() == client_id
|
||||
&& item.status != "cancelled"
|
||||
&& item.status != "deleted"
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
Err(_) => Vec::new(),
|
||||
};
|
||||
visible_visits.sort_by(|a, b| {
|
||||
b.visit_date
|
||||
.cmp(&a.visit_date)
|
||||
.then(b.time_start.cmp(&a.time_start))
|
||||
});
|
||||
let page = visible_visits
|
||||
.iter()
|
||||
.position(|item| item.id.unwrap() == visit.id.unwrap())
|
||||
.map(|index| index / 10 + 1)
|
||||
.unwrap_or(1);
|
||||
|
||||
for mut subscription in subscriptions {
|
||||
let is_ru = subscription.language == "ru";
|
||||
let date = visit.visit_date.format("%d.%m.%Y");
|
||||
let body = if is_ru {
|
||||
format!("Визит {date} завершён. Нажмите для просмотра медиа и комментариев.")
|
||||
} else {
|
||||
format!("Visit {date} is complete. Click to view media and comments.")
|
||||
};
|
||||
let payload = json!({
|
||||
"title": if is_ru { "Визит завершён" } else { "Visit completed" },
|
||||
"body": body,
|
||||
"url": format!("/client/{}?page={}#visit-{}", client.media_token, page, visit.id.unwrap()),
|
||||
"tag": format!("visit-{}", visit.id.unwrap()),
|
||||
});
|
||||
|
||||
match send(&subscription, payload.to_string().into_bytes(), &config).await {
|
||||
Ok(status)
|
||||
if status == reqwest::StatusCode::NOT_FOUND
|
||||
|| status == reqwest::StatusCode::GONE =>
|
||||
{
|
||||
subscription.status = "archived".to_string();
|
||||
subscription.updated_at = chrono::Utc::now().naive_utc();
|
||||
if let Err(error) = subscription.save(db).await {
|
||||
tracing::warn!(%error, "failed to archive expired Web Push subscription");
|
||||
}
|
||||
}
|
||||
Ok(status) if status.is_success() => {}
|
||||
Ok(status) => tracing::warn!(%status, "Web Push gateway rejected notification"),
|
||||
Err(error) => tracing::warn!(%error, "failed to send Web Push notification"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn send(
|
||||
subscription: &PushSubscription,
|
||||
content: Vec<u8>,
|
||||
config: &VapidConfig,
|
||||
) -> Result<reqwest::StatusCode, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let private = URL_SAFE_NO_PAD.decode(&config.private_key)?;
|
||||
let key_pair = ES256KeyPair::from_bytes(&private)?;
|
||||
let p256dh = URL_SAFE_NO_PAD.decode(&subscription.p256dh)?;
|
||||
let auth = URL_SAFE_NO_PAD.decode(&subscription.auth)?;
|
||||
let builder = WebPushBuilder::new(
|
||||
subscription.endpoint.parse()?,
|
||||
PublicKey::from_sec1_bytes(&p256dh)?,
|
||||
Auth::clone_from_slice(&auth),
|
||||
)
|
||||
.with_vapid(&key_pair, &config.subject);
|
||||
let request = builder.build(content)?;
|
||||
let (parts, body) = request.into_parts();
|
||||
let response = reqwest::Client::builder()
|
||||
.timeout(std::time::Duration::from_secs(10))
|
||||
.build()?
|
||||
.request(parts.method, parts.uri.to_string())
|
||||
.headers(parts.headers)
|
||||
.body(body)
|
||||
.send()
|
||||
.await?;
|
||||
Ok(response.status())
|
||||
}
|
||||
@@ -0,0 +1,708 @@
|
||||
:root {
|
||||
--admin-accent: #7567e8;
|
||||
--admin-accent-dark: #6255cf;
|
||||
--admin-accent-soft: #efedff;
|
||||
--admin-bg: #f6f5f9;
|
||||
--admin-surface: #fff;
|
||||
--admin-surface-soft: #fbfaff;
|
||||
--admin-border: #e7e5ef;
|
||||
--admin-border-soft: #eeecf3;
|
||||
--admin-text: #302c49;
|
||||
--admin-muted: #817c94;
|
||||
--admin-danger: #b54e5b;
|
||||
--admin-success: #177349;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
html { background: var(--admin-bg); }
|
||||
|
||||
body {
|
||||
min-height: 100vh;
|
||||
background: var(--admin-bg);
|
||||
color: var(--admin-text);
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
a { color: var(--admin-accent-dark); }
|
||||
|
||||
/* Application shell */
|
||||
.admin-shell { padding-bottom: 4.35rem; }
|
||||
|
||||
.top-header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 30;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
min-height: 3.5rem;
|
||||
padding: .55rem 1rem;
|
||||
background: rgba(255,255,255,.94);
|
||||
border-bottom: 1px solid var(--admin-border);
|
||||
box-shadow: 0 1px 8px rgba(42,34,80,.035);
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.top-header .brand {
|
||||
flex: 0 0 auto;
|
||||
color: var(--admin-text);
|
||||
font-size: 1.05rem;
|
||||
font-weight: 800;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.brand-version {
|
||||
color: #aaa5b6;
|
||||
font-size: .66rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.top-header-right {
|
||||
display: flex;
|
||||
flex: 0 0 auto;
|
||||
align-items: center;
|
||||
gap: .7rem;
|
||||
font-size: .8rem;
|
||||
}
|
||||
|
||||
.top-header-right a { color: #777184; text-decoration: none; }
|
||||
.top-header-right a:hover { color: var(--admin-accent-dark); }
|
||||
.top-header-right .admin-name { color: #aaa5b6; }
|
||||
|
||||
.desktop-nav { display: none; }
|
||||
|
||||
.bottom-tabs {
|
||||
position: fixed;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 30;
|
||||
display: flex;
|
||||
height: 3.65rem;
|
||||
overflow-x: auto;
|
||||
background: rgba(255,255,255,.96);
|
||||
border-top: 1px solid var(--admin-border);
|
||||
box-shadow: 0 -4px 18px rgba(42,34,80,.06);
|
||||
scrollbar-width: none;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.bottom-tabs::-webkit-scrollbar { display: none; }
|
||||
|
||||
.bottom-tabs a {
|
||||
display: flex;
|
||||
flex: 1 0 3.2rem;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 3.2rem;
|
||||
padding: 0 .42rem;
|
||||
color: #9993a8;
|
||||
font-size: .59rem;
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.bottom-tabs a .tab-icon { font-size: 1.2rem; line-height: 1; }
|
||||
.bottom-tabs a .tab-label { display: block; margin-top: .12rem; }
|
||||
.bottom-tabs a.is-active { color: var(--admin-accent); }
|
||||
|
||||
.main-content {
|
||||
width: 100%;
|
||||
max-width: 980px;
|
||||
margin: 0 auto;
|
||||
padding: 1.25rem 1rem 2rem;
|
||||
}
|
||||
|
||||
/* Typography and page chrome */
|
||||
.page-head {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
justify-content: space-between;
|
||||
gap: .8rem;
|
||||
margin-bottom: 1.25rem;
|
||||
}
|
||||
|
||||
.page-head h1 {
|
||||
margin: 0;
|
||||
color: var(--admin-text);
|
||||
font-size: 1.55rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: -.02em;
|
||||
}
|
||||
|
||||
.page-head p,
|
||||
.page-description {
|
||||
margin: .25rem 0 0;
|
||||
color: var(--admin-muted);
|
||||
font-size: .86rem;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.page-head-actions,
|
||||
.toolbar,
|
||||
.action-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .5rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin: 1.55rem 0 .75rem;
|
||||
color: #514b69;
|
||||
font-size: .82rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: .04em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.section-inline-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; }
|
||||
.section-inline-head .label { margin: 0; }
|
||||
.form-card hr { height: 1px; margin: 1rem 0; background: var(--admin-border-soft); border: 0; }
|
||||
|
||||
.empty-state {
|
||||
padding: 2rem 1rem;
|
||||
color: var(--admin-muted);
|
||||
text-align: center;
|
||||
background: rgba(255,255,255,.65);
|
||||
border: 1px dashed #dcd8e8;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.button {
|
||||
border-radius: 8px;
|
||||
box-shadow: none !important;
|
||||
font-weight: 700;
|
||||
transition: transform .12s, border-color .15s, background .15s;
|
||||
}
|
||||
|
||||
.button:hover { transform: translateY(-1px); }
|
||||
.button:active { transform: none; }
|
||||
.button.is-primary { background: var(--admin-accent); border-color: var(--admin-accent); }
|
||||
.button.is-primary:not(.is-outlined):not(.is-light),
|
||||
.button.is-link:not(.is-outlined):not(.is-light),
|
||||
.button.is-info:not(.is-outlined):not(.is-light),
|
||||
.button.is-success:not(.is-outlined):not(.is-light),
|
||||
.button.is-danger:not(.is-outlined):not(.is-light) { color: #fff !important; }
|
||||
.button.is-primary:hover { color: #fff !important; background: var(--admin-accent-dark); border-color: var(--admin-accent-dark); }
|
||||
.button.is-primary.is-outlined { color: var(--admin-accent-dark) !important; background: transparent; border-color: #a49bea; }
|
||||
.button.is-primary.is-outlined:hover { color: #fff !important; background: var(--admin-accent); border-color: var(--admin-accent); }
|
||||
.button.is-light { background: #f3f1f8; color: #5f5971; }
|
||||
.button[disabled] { color: #8d8798 !important; background: #eceaf0 !important; border-color: #e0dde7 !important; opacity: 1; transform: none; }
|
||||
.button.is-small,
|
||||
.btn-sm { height: auto !important; padding: .32rem .65rem !important; font-size: .75rem !important; }
|
||||
|
||||
/* Reusable cards and sections */
|
||||
.admin-section,
|
||||
.form-card {
|
||||
overflow: hidden;
|
||||
background: var(--admin-surface);
|
||||
border: 1px solid var(--admin-border);
|
||||
border-radius: 14px;
|
||||
box-shadow: 0 2px 10px rgba(42,34,80,.035);
|
||||
}
|
||||
|
||||
.form-card { padding: 1.2rem; }
|
||||
|
||||
.admin-section-head {
|
||||
display: grid;
|
||||
grid-template-columns: 42px minmax(0,1fr);
|
||||
gap: .8rem;
|
||||
padding: 1rem 1.15rem;
|
||||
background: linear-gradient(180deg,#fff,var(--admin-surface-soft));
|
||||
border-bottom: 1px solid #eceaf2;
|
||||
}
|
||||
|
||||
.admin-section-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
background: var(--admin-accent-soft);
|
||||
border-radius: 11px;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.admin-section-head h2 {
|
||||
margin: 0;
|
||||
color: var(--admin-text);
|
||||
font-size: 1.05rem;
|
||||
font-weight: 750;
|
||||
}
|
||||
|
||||
.admin-section-head p {
|
||||
max-width: 680px;
|
||||
margin: .2rem 0 0;
|
||||
color: var(--admin-muted);
|
||||
font-size: .82rem;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.admin-section-body { padding: 1.15rem; }
|
||||
|
||||
.admin-title-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .55rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.status-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: .12rem .48rem;
|
||||
color: #777184;
|
||||
background: #eeedf2;
|
||||
border-radius: 99px;
|
||||
font-size: .67rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.status-pill.is-enabled { color: var(--admin-success); background: #dcf7e8; }
|
||||
|
||||
.admin-grid,
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2,minmax(0,1fr));
|
||||
gap: 1rem 1.1rem;
|
||||
}
|
||||
.form-grid > .field { margin: 0; }
|
||||
.page-head .button.is-primary { min-height: 2.25rem; padding: .42rem .8rem !important; }
|
||||
|
||||
.admin-field { min-width: 0; margin: 0 !important; }
|
||||
.admin-field-wide { grid-column: 1 / -1; }
|
||||
|
||||
.admin-subsection {
|
||||
margin-top: 1.1rem;
|
||||
padding-top: 1.1rem;
|
||||
border-top: 1px solid var(--admin-border-soft);
|
||||
}
|
||||
|
||||
.admin-subsection h2,
|
||||
.admin-subsection h3,
|
||||
.form-card > h2 {
|
||||
margin: 0 0 .75rem;
|
||||
color: #514b69;
|
||||
font-size: .82rem;
|
||||
font-weight: 800;
|
||||
letter-spacing: .04em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.item-card {
|
||||
display: block;
|
||||
margin-bottom: .65rem;
|
||||
padding: .9rem 1rem;
|
||||
color: inherit;
|
||||
background: var(--admin-surface);
|
||||
border: 1px solid var(--admin-border);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 1px 6px rgba(42,34,80,.025);
|
||||
transition: border-color .15s, box-shadow .15s, transform .15s;
|
||||
}
|
||||
|
||||
.item-card:hover {
|
||||
border-color: #dcd8eb;
|
||||
box-shadow: 0 5px 18px rgba(42,34,80,.055);
|
||||
}
|
||||
|
||||
.item-card-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: .75rem;
|
||||
margin-bottom: .35rem;
|
||||
}
|
||||
|
||||
.item-card-header .name {
|
||||
min-width: 0;
|
||||
color: var(--admin-text);
|
||||
font-size: .95rem;
|
||||
font-weight: 750;
|
||||
}
|
||||
|
||||
.item-card-meta {
|
||||
display: flex;
|
||||
gap: .25rem 1rem;
|
||||
flex-wrap: wrap;
|
||||
color: var(--admin-muted);
|
||||
font-size: .79rem;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.item-card-meta a { color: inherit; text-decoration: none; }
|
||||
|
||||
.item-card-actions {
|
||||
display: flex;
|
||||
gap: .4rem;
|
||||
flex-wrap: wrap;
|
||||
margin-top: .65rem;
|
||||
padding-top: .6rem;
|
||||
border-top: 1px solid var(--admin-border-soft);
|
||||
}
|
||||
|
||||
.item-card-actions form { margin: 0; }
|
||||
.color-dot { display: inline-block; width: 11px; height: 11px; margin-right: 6px; border-radius: 50%; vertical-align: middle; }
|
||||
.card-link { color: inherit; text-decoration: none; }
|
||||
.card-note { margin-top: .35rem; color: var(--admin-muted); font-size: .78rem; line-height: 1.45; }
|
||||
.feedback-card { border-left: 3px solid var(--admin-accent); text-decoration: none; }
|
||||
.feedback-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .3rem; }
|
||||
.feedback-date { color: #9993a8; font-size: .75rem; white-space: nowrap; }
|
||||
.feedback-text { color: #4a4570; font-size: .82rem; line-height: 1.5; }
|
||||
.muted-detail { color: var(--admin-muted); font-weight: 450; }
|
||||
|
||||
/* Statuses */
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
flex: 0 0 auto;
|
||||
align-items: center;
|
||||
padding: .16rem .58rem;
|
||||
border-radius: 99px;
|
||||
font-size: .69rem;
|
||||
font-weight: 750;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.badge-new,
|
||||
.badge-visit-scheduled { color: #1e40af; background: #dbeafe; }
|
||||
.badge-in_progress { color: #92400e; background: #fef3c7; }
|
||||
.badge-converted,
|
||||
.badge-active,
|
||||
.badge-visit-completed { color: #065f46; background: #d1fae5; }
|
||||
.badge-rejected { color: #991b1b; background: #fee2e2; }
|
||||
.badge-archived,
|
||||
.badge-visit-cancelled { color: #554f61; background: #ebe9ef; }
|
||||
|
||||
/* Forms */
|
||||
.field:not(:last-child) { margin-bottom: 1rem; }
|
||||
.field .label,
|
||||
.admin-field .label {
|
||||
margin-bottom: .38rem;
|
||||
color: #514c66 !important;
|
||||
font-size: .76rem;
|
||||
font-weight: 750;
|
||||
}
|
||||
|
||||
input,
|
||||
textarea,
|
||||
select,
|
||||
.input,
|
||||
.textarea,
|
||||
.select select {
|
||||
color: var(--admin-text) !important;
|
||||
background-color: #fff !important;
|
||||
border-color: #dcd9e5 !important;
|
||||
border-radius: 8px !important;
|
||||
box-shadow: none !important;
|
||||
font-size: .86rem;
|
||||
}
|
||||
|
||||
.input,
|
||||
.select select { min-height: 2.45rem; }
|
||||
.textarea { min-height: 76px; resize: vertical; }
|
||||
|
||||
input:focus,
|
||||
textarea:focus,
|
||||
select:focus,
|
||||
.input:focus,
|
||||
.textarea:focus,
|
||||
.select select:focus {
|
||||
border-color: #7c6cff !important;
|
||||
box-shadow: 0 0 0 2px rgba(124,108,255,.12) !important;
|
||||
}
|
||||
|
||||
input[readonly],
|
||||
.input[readonly] { color: #716b81 !important; background: #f8f7fa !important; }
|
||||
|
||||
input[type="file"].input { padding: .36rem .55rem; }
|
||||
input[type="color"] { width: 3rem; height: 2.35rem; padding: 2px; cursor: pointer; }
|
||||
input[type="checkbox"] { accent-color: var(--admin-accent); }
|
||||
|
||||
.field-help {
|
||||
margin-top: .35rem;
|
||||
color: #8b869b;
|
||||
font-size: .72rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.secret-control { position: relative; }
|
||||
.secret-control::after { position: absolute; top: 50%; right: .75rem; content: "🔒"; transform: translateY(-50%); opacity: .48; font-size: .78rem; pointer-events: none; }
|
||||
.secret-control .input { padding-right: 2.25rem; letter-spacing: .05em; }
|
||||
.admin-form { display: flex; flex-direction: column; gap: 1rem; }
|
||||
.admin-toggle-list { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .7rem; margin-bottom: 1rem; }
|
||||
.admin-toggle { position: relative; display: flex; align-items: flex-start; gap: .7rem; padding: .75rem .85rem; color: inherit !important; background: var(--admin-surface-soft); border: 1px solid #e8e5f2; border-radius: 10px; cursor: pointer; transition: border-color .15s,background .15s; }
|
||||
.admin-toggle:hover { background: #f8f6ff; border-color: #dcd7ef; }
|
||||
.admin-toggle > input { position: absolute; opacity: 0; pointer-events: none; }
|
||||
.admin-toggle-track { flex: 0 0 auto; width: 38px; height: 22px; padding: 2px; background: #ccc8d6; border-radius: 99px; transition: .18s; }
|
||||
.admin-toggle-track span { display: block; width: 18px; height: 18px; background: #fff; border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.2); transition: .18s; }
|
||||
.admin-toggle > input:checked + .admin-toggle-track { background: var(--admin-accent); }
|
||||
.admin-toggle > input:checked + .admin-toggle-track span { transform: translateX(16px); }
|
||||
.admin-toggle > input:focus-visible + .admin-toggle-track { outline: 2px solid #7c6cff; outline-offset: 2px; }
|
||||
.admin-toggle strong { display: block; color: #3e3956; font-size: .82rem; line-height: 1.35; }
|
||||
.admin-toggle small { display: block; margin-top: .15rem; color: #8a849c; font-size: .7rem; line-height: 1.35; }
|
||||
.admin-toggle-compact { align-items: center; padding: .55rem .65rem; }
|
||||
|
||||
.admin-check { position: relative; display: inline-flex; align-items: center; gap: .45rem; color: #716b81 !important; font-size: .72rem; line-height: 1.35; cursor: pointer; }
|
||||
.admin-check > input { position: absolute; opacity: 0; pointer-events: none; }
|
||||
.admin-check-box { display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center; width: 18px; height: 18px; color: transparent; background: #fff; border: 1.5px solid #cfcad9; border-radius: 5px; font-size: .68rem; font-weight: 900; transition: .15s; }
|
||||
.admin-check > input:checked + .admin-check-box { color: #fff; background: var(--admin-accent); border-color: var(--admin-accent); }
|
||||
.admin-check > input:focus-visible + .admin-check-box { outline: 2px solid #7c6cff; outline-offset: 2px; }
|
||||
.admin-check-danger { color: #a04e58 !important; }
|
||||
.admin-check-danger > input:checked + .admin-check-box { background: var(--admin-danger); border-color: var(--admin-danger); }
|
||||
|
||||
.admin-note { margin: .9rem 0 1rem; padding: .75rem .9rem; border: 1px solid; border-radius: 9px; font-size: .76rem; line-height: 1.5; }
|
||||
.admin-note p + p { margin-top: .35rem; }
|
||||
.admin-note-info { color: #42627f; background: #f1f7ff; border-color: #d7e8fa; }
|
||||
.admin-note-warning { color: #785f28; background: #fff8e8; border-color: #f1dfb4; }
|
||||
.admin-note code { display: inline-block; margin: .2rem 0 0; padding: .12rem .35rem; color: inherit; background: rgba(255,255,255,.7); border-radius: 4px; user-select: all; }
|
||||
|
||||
.admin-details { margin-top: 1rem; overflow: hidden; background: #fcfbff; border: 1px solid #e8e5f2; border-radius: 9px; }
|
||||
.admin-details summary { display: flex; align-items: center; justify-content: space-between; padding: .7rem .85rem; color: #514b69; font-size: .78rem; font-weight: 700; cursor: pointer; }
|
||||
.admin-details summary span { min-width: 24px; padding: .05rem .4rem; color: #6257bb; text-align: center; background: #ece9ff; border-radius: 99px; }
|
||||
.admin-details-body { padding: 0 .85rem .85rem; }
|
||||
|
||||
.sticky-actions {
|
||||
position: sticky;
|
||||
bottom: 4.3rem;
|
||||
z-index: 10;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding: .65rem;
|
||||
background: rgba(255,255,255,.92);
|
||||
border: 1px solid rgba(222,218,238,.9);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 28px rgba(46,38,86,.12);
|
||||
backdrop-filter: blur(8px);
|
||||
}
|
||||
.sticky-actions .button { min-width: 150px; }
|
||||
|
||||
.danger-zone { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid #f1dfe2; }
|
||||
.inline-control { display: flex; align-items: center; gap: .5rem; }
|
||||
.inline-control > .input,
|
||||
.inline-control > .select { flex: 1; min-width: 0; }
|
||||
.color-control { display: flex; align-items: center; gap: .6rem; }
|
||||
.portal-panel { margin-top: 1.1rem; padding-top: 1.1rem; border-top: 1px solid var(--admin-border-soft); }
|
||||
.portal-qr { margin-top: .8rem; text-align: center; }
|
||||
.portal-qr canvas { max-width: 180px; padding: .4rem; background: #fff; border: 1px solid var(--admin-border); border-radius: 10px; }
|
||||
.inline-admin-form { margin-top: .7rem; padding-top: .7rem; border-top: 1px solid var(--admin-border-soft); }
|
||||
.inline-admin-grid { display: grid; grid-template-columns: minmax(180px,1fr) minmax(180px,.8fr) auto; align-items: end; gap: .75rem; }
|
||||
.inline-admin-grid .field { margin: 0; }
|
||||
.testimonial-content { display: flex; align-items: flex-start; gap: .75rem; min-width: 0; }
|
||||
.testimonial-avatar { flex: 0 0 auto; width: 48px; height: 48px; border-radius: 12px; object-fit: cover; }
|
||||
.testimonial-text { color: #49435d; font-size: .88rem; line-height: 1.5; }
|
||||
.testimonial-note { margin-top: .2rem; color: var(--admin-muted); font-size: .76rem; }
|
||||
|
||||
/* Messages and tables */
|
||||
.notification { color: var(--admin-text) !important; border-radius: 10px; }
|
||||
.table-wrap { overflow-x: auto; }
|
||||
.table-wrap .table { margin: 0; background: transparent; font-size: .75rem; }
|
||||
.table th { color: #696278 !important; font-size: .7rem; text-transform: uppercase; letter-spacing: .03em; }
|
||||
.is-nowrap { white-space: nowrap; }
|
||||
.seo-preview { min-height: 2rem; margin-top: .5rem; padding: .5rem .65rem; background: #fafafa; border: 1px solid #ebe9ef; border-radius: 7px; font-size: .78rem; line-height: 2; }
|
||||
|
||||
.pagination-row,
|
||||
.media-pagination { display: flex; justify-content: center; gap: .35rem; flex-wrap: wrap; margin-top: 1.25rem; }
|
||||
|
||||
/* Media */
|
||||
.filter-bar { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; padding: .65rem .75rem; background: #fff; border: 1px solid var(--admin-border); border-radius: 10px; }
|
||||
.media-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(200px,1fr)); gap: .8rem; }
|
||||
.media-card { overflow: hidden; background: #fff; border: 1px solid var(--admin-border); border-radius: 12px; box-shadow: 0 1px 6px rgba(42,34,80,.025); transition: transform .15s, box-shadow .15s; }
|
||||
.media-card:hover { transform: translateY(-2px); box-shadow: 0 7px 20px rgba(42,34,80,.08); }
|
||||
.media-card img { display: block; width: 100%; height: 160px; object-fit: cover; }
|
||||
.media-card .photo-thumb { width: 100%; height: 160px; }
|
||||
.media-card .video-thumb { position: relative; width: 100%; height: 160px; background: #17151e; }
|
||||
.media-card .video-play,
|
||||
.visit-media-item .video-play { position: absolute; top: 50%; left: 50%; color: #fff; line-height: 1; text-shadow: 0 1px 5px #000; transform: translate(-50%,-50%); pointer-events: none; }
|
||||
.media-card .video-play { font-size: 2.5rem; }
|
||||
.media-info { padding: .7rem .8rem; }
|
||||
.media-meta { display: flex; align-items: center; justify-content: space-between; gap: .5rem; color: var(--admin-text); font-size: .82rem; }
|
||||
.media-caption { margin-top: .25rem; color: #746e82; font-size: .78rem; }
|
||||
|
||||
.visit-media-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(105px,1fr)); gap: .55rem; margin-bottom: 1rem; }
|
||||
.visit-media-item { overflow: hidden; background: #faf9fc; border: 1px solid var(--admin-border); border-radius: 9px; }
|
||||
.visit-media-item img,
|
||||
.visit-media-item .photo-thumb,
|
||||
.visit-media-item .video-thumb-sm { display: block; width: 100%; height: 82px; object-fit: cover; }
|
||||
.visit-media-item .video-thumb-sm { position: relative; background: #17151e; }
|
||||
.visit-media-item .video-play { font-size: 1.6rem; }
|
||||
.visit-media-item .media-cap { padding: .25rem .4rem; overflow: hidden; color: var(--admin-muted); font-size: .69rem; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.visit-media-delete { padding: .25rem .4rem .4rem; }
|
||||
.visit-media-delete .button { width: 100%; min-height: 1.65rem; font-size: .66rem; }
|
||||
|
||||
/* Upload queue */
|
||||
.upload-context { margin-bottom: 1rem; padding: .7rem .8rem; color: #686276; background: var(--admin-surface-soft); border: 1px solid var(--admin-border-soft); border-radius: 9px; font-size: .82rem; }
|
||||
.upload-queue { display: flex; flex-direction: column; gap: .4rem; margin-top: .65rem; }
|
||||
.upload-queue:empty { display: none; }
|
||||
.upload-queue-item { display: grid; grid-template-columns: 34px minmax(0,1fr); align-items: center; gap: .55rem; padding: .45rem .55rem; background: #f7f6ff; border-radius: 8px; }
|
||||
.upload-queue-icon { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; background: #ebe8ff; border-radius: 7px; font-size: 1.05rem; }
|
||||
.upload-queue-name { overflow: hidden; color: #494467; font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.upload-queue-state { color: #8a84a5; font-size: .68rem; }
|
||||
.upload-queue-track { height: 3px; margin-top: .25rem; overflow: hidden; background: #dedbea; border-radius: 99px; }
|
||||
.upload-queue-bar { width: 0; height: 100%; background: var(--admin-accent); transition: width .2s; }
|
||||
.upload-progress { display: none; margin-bottom: 1rem; }
|
||||
.upload-progress-head { display: flex; justify-content: space-between; margin-bottom: .3rem; color: #5f596d; font-size: .78rem; }
|
||||
.upload-progress-track { height: 7px; overflow: hidden; background: #e8e6ed; border-radius: 99px; }
|
||||
.upload-progress-bar { width: 0; height: 100%; background: linear-gradient(90deg,#6c63ff,#b06cff); border-radius: 99px; transition: width .2s; }
|
||||
#uploadBar.is-processing,
|
||||
.upload-queue-bar.is-processing { width: 35% !important; animation: upload-processing 1.15s ease-in-out infinite; }
|
||||
@keyframes upload-processing { from { transform: translateX(-110%); } to { transform: translateX(300%); } }
|
||||
|
||||
/* Schedule */
|
||||
#calendar-wrap { padding: .75rem; overflow: hidden; }
|
||||
.fc { color: var(--admin-text); font-size: .82rem; }
|
||||
.fc .fc-daygrid-day-number,
|
||||
.fc .fc-col-header-cell-cushion,
|
||||
.fc .fc-list-day-text,
|
||||
.fc .fc-list-day-side-text,
|
||||
.fc .fc-toolbar-title,
|
||||
.fc th,
|
||||
.fc td { color: var(--admin-text) !important; }
|
||||
.fc .fc-toolbar { gap: .55rem; flex-wrap: nowrap; }
|
||||
.fc .fc-toolbar-chunk { min-width: 0; }
|
||||
.fc .fc-toolbar-chunk:first-child,
|
||||
.fc .fc-toolbar-chunk:last-child { display: flex; align-items: center; }
|
||||
.fc .fc-button-group { display: flex; flex-wrap: nowrap; gap: .35rem; }
|
||||
.fc .fc-button-group > .fc-button { margin-left: 0 !important; border-radius: 7px !important; }
|
||||
.fc .fc-toolbar-title { font-size: 1.05rem !important; white-space: nowrap; }
|
||||
.fc .fc-button { padding: .28rem .52rem !important; color: #fff !important; background: var(--admin-accent) !important; border-color: var(--admin-accent) !important; border-radius: 7px !important; font-size: .76rem !important; }
|
||||
.fc-event { padding: 2px 5px; border: none !important; border-radius: 5px; cursor: pointer; }
|
||||
.fc-event.ev-completed .fc-event-title,
|
||||
.fc-event.ev-completed .fc-list-event-title,
|
||||
.fc-event.ev-cancelled .fc-event-title,
|
||||
.fc-event.ev-cancelled .fc-list-event-title { text-decoration: line-through; opacity: .75; }
|
||||
.fc .fc-day-today { background: #f0eeff !important; }
|
||||
.fc .fc-day.day-weekend { background: #fdf9f6; }
|
||||
.fc .fc-day-today.day-weekend { background: #f0eeff !important; }
|
||||
|
||||
.time-row { display: flex; align-items: center; gap: .5rem; }
|
||||
.time-block { display: flex; flex: 1; flex-direction: column; }
|
||||
.time-lbl { margin-bottom: .2rem; color: var(--admin-muted); font-size: .72rem; }
|
||||
.time-sep { padding-top: 1.2rem; color: #aaa5b6; font-size: 1.1rem; }
|
||||
.cal-toolbar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .55rem; }
|
||||
.sched-cal { overflow: hidden; background: #faf9fc; border: 1px solid var(--admin-border); border-radius: 11px; }
|
||||
.cal-nav { display: flex; align-items: center; justify-content: space-between; padding: .65rem .75rem; background: #fff; border-bottom: 1px solid var(--admin-border-soft); }
|
||||
.cal-nav button { padding: .2rem .5rem; color: var(--admin-accent); background: none; border: 0; border-radius: 6px; font-size: 1.05rem; cursor: pointer; }
|
||||
.cal-nav button:hover { background: #f0eeff; }
|
||||
.cal-nav span { color: var(--admin-text); font-size: .95rem; font-weight: 750; }
|
||||
.cal-grid { display: grid; grid-template-columns: repeat(7,1fr); }
|
||||
.cal-wday { padding: .42rem 0; color: #aaa5b6; background: #faf9fc; font-size: .69rem; font-weight: 750; text-align: center; }
|
||||
.cal-wday.is-weekend { color: #d98a91; }
|
||||
.cal-day { position: relative; padding: .55rem .2rem; color: var(--admin-text); border-radius: 0; font-size: .86rem; text-align: center; cursor: pointer; transition: background .1s; user-select: none; }
|
||||
.cal-day:hover { background: #f0eeff; }
|
||||
.cal-day.is-empty { cursor: default; }
|
||||
.cal-day.is-empty:hover { background: none; }
|
||||
.cal-day.is-today { color: var(--admin-accent); font-weight: 750; }
|
||||
.cal-day.is-selected { color: #fff !important; background: var(--admin-accent) !important; }
|
||||
.cal-day.is-range-start { color: #fff !important; background: #a89cff !important; }
|
||||
.cal-day.is-past { color: #ccc8d3; }
|
||||
.day-row { display: flex; align-items: center; gap: .4rem; padding: .5rem 0; border-bottom: 1px solid #f2f0f5; }
|
||||
.day-row:last-child { border-bottom: 0; }
|
||||
.day-date { flex: 1; min-width: 0; overflow: hidden; font-size: .82rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.day-times { display: flex; flex-shrink: 0; align-items: center; gap: .25rem; }
|
||||
.day-times .time-sep { padding: 0; font-size: .78rem; }
|
||||
.day-rm { flex-shrink: 0; padding: .15rem .25rem; color: #bbb6c5; background: none; border: 0; font-size: 1rem; line-height: 1; cursor: pointer; }
|
||||
.day-rm:hover { color: var(--admin-danger); }
|
||||
.time-badge-wrap { position: relative; display: inline-flex; align-items: center; justify-content: center; min-width: 3.6rem; padding: .15rem .5rem; color: #5b52d6; background: #ede9ff; border: 1.5px solid #c4beff; border-radius: 20px; font-size: .76rem; font-weight: 750; white-space: nowrap; cursor: pointer; }
|
||||
.time-badge-wrap:focus-within { background: #f0eeff; border-color: var(--admin-accent); }
|
||||
.time-badge-label { z-index: 1; pointer-events: none; }
|
||||
.time-badge-input { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; margin: 0; opacity: 0; background: transparent; border: 0; font-size: 16px; cursor: pointer; }
|
||||
|
||||
.status-picker { display: flex; gap: .5rem; }
|
||||
.status-btn { display: flex; flex: 1; flex-direction: column; align-items: center; gap: .3rem; padding: .6rem .4rem; color: #777184; background: #f5f4f7; border: 2px solid transparent; border-radius: 10px; font-size: .79rem; font-weight: 650; line-height: 1.2; cursor: pointer; transition: all .15s; }
|
||||
.status-btn-icon { font-size: 1.3rem; line-height: 1; }
|
||||
.status-btn:hover { filter: brightness(.97); }
|
||||
.status-btn-scheduled.is-active { color: #1e40af; background: #dbeafe; border-color: #3b82f6; }
|
||||
.status-btn-completed.is-active { color: #15803d; background: #d1fae5; border-color: #22c55e; }
|
||||
.status-btn-cancelled.is-active { color: #b91c1c; background: #fee2e2; border-color: #ef4444; }
|
||||
|
||||
/* Dialogs */
|
||||
.visit-modal-bg,
|
||||
.upload-modal-bg { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; padding: 1rem; background: rgba(31,27,48,.38); backdrop-filter: blur(3px); }
|
||||
.visit-modal-bg.is-open,
|
||||
.upload-modal-bg.is-open { display: flex; }
|
||||
.visit-modal,
|
||||
.upload-modal { width: 100%; max-width: 420px; padding: 1.25rem; background: #fff; border: 1px solid var(--admin-border); border-radius: 14px; box-shadow: 0 18px 50px rgba(31,27,48,.18); }
|
||||
.visit-modal { max-width: 380px; }
|
||||
.visit-modal h3 { margin: 0 0 .75rem; color: var(--admin-text); font-size: 1.05rem; font-weight: 750; }
|
||||
.visit-modal .meta { margin-bottom: .75rem; color: var(--admin-muted); font-size: .82rem; line-height: 1.6; }
|
||||
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
|
||||
.modal-head h3 { margin: 0; color: var(--admin-text); font-size: 1.05rem; font-weight: 750; }
|
||||
.modal-close { padding: .25rem; color: var(--admin-muted); background: none; border: 0; font-size: 1.15rem; cursor: pointer; }
|
||||
|
||||
/* Authentication screens */
|
||||
.auth-shell { display: flex; align-items: center; justify-content: center; padding: 1.5rem 0; }
|
||||
.login-box { width: 100%; max-width: 410px; padding: 0 1rem; }
|
||||
.auth-language { margin-bottom: .7rem; text-align: right; }
|
||||
.auth-language a { color: var(--admin-muted); font-size: .75rem; }
|
||||
.login-card { padding: 1.6rem 1.4rem; background: #fff; border: 1px solid var(--admin-border); border-radius: 16px; box-shadow: 0 12px 38px rgba(42,34,80,.08); }
|
||||
.auth-head { margin-bottom: 1.1rem; text-align: center; }
|
||||
.auth-icon { display: flex; align-items: center; justify-content: center; width: 48px; height: 48px; margin: 0 auto .65rem; background: var(--admin-accent-soft); border-radius: 13px; font-size: 1.55rem; }
|
||||
.auth-head h1 { margin: 0; color: var(--admin-text); font-size: 1.25rem; font-weight: 800; }
|
||||
.auth-head p { margin-top: .2rem; color: var(--admin-muted); font-size: .84rem; }
|
||||
.auth-divider { height: 1px; margin: 1rem 0; background: var(--admin-border-soft); border: 0; }
|
||||
.turnstile-wrap { margin-top: .75rem; }
|
||||
.time-columns { margin-bottom: 0 !important; }
|
||||
|
||||
@media (min-width: 1080px) {
|
||||
.admin-shell { padding-bottom: 0; }
|
||||
.bottom-tabs { display: none; }
|
||||
.desktop-nav { display: flex; align-items: center; justify-content: center; gap: .2rem; }
|
||||
.desktop-nav a { padding: .36rem .62rem; color: #625d70; border-radius: 7px; font-size: .78rem; font-weight: 650; text-decoration: none; transition: background .15s,color .15s; }
|
||||
.desktop-nav a:hover { background: #f2f0f7; }
|
||||
.desktop-nav a.is-active { color: #fff; background: var(--admin-accent); }
|
||||
.sticky-actions { bottom: .75rem; }
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.top-header .brand { font-size: .95rem; }
|
||||
.brand-version,
|
||||
.top-header-right .admin-name { display: none; }
|
||||
.main-content { padding: 1rem .75rem 1.5rem; }
|
||||
.page-head { align-items: flex-start; }
|
||||
.page-head h1 { font-size: 1.35rem; }
|
||||
.admin-grid,
|
||||
.form-grid,
|
||||
.admin-toggle-list { grid-template-columns: 1fr; }
|
||||
.admin-field-wide { grid-column: auto; }
|
||||
.admin-section-head { grid-template-columns: 36px minmax(0,1fr); padding: .9rem; }
|
||||
.admin-section-icon { width: 36px; height: 36px; }
|
||||
.admin-section-body,
|
||||
.form-card { padding: .9rem; }
|
||||
.sticky-actions .button { width: 100%; }
|
||||
.fc .fc-toolbar { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: .55rem; font-size: .72rem; }
|
||||
.fc .fc-toolbar-chunk:first-child { grid-column: 1; grid-row: 1; justify-self: start; }
|
||||
.fc .fc-toolbar-chunk:nth-child(2) { grid-column: 2; grid-row: 1; justify-self: end; }
|
||||
.fc .fc-toolbar-chunk:last-child { grid-column: 1 / -1; grid-row: 2; width: 100%; overflow-x: auto; }
|
||||
.fc .fc-toolbar-chunk:last-child .fc-button-group { width: 100%; }
|
||||
.fc .fc-toolbar-chunk:last-child .fc-button { flex: 1 0 auto; }
|
||||
.fc .fc-toolbar-title { font-size: .92rem !important; }
|
||||
.fc .fc-button { padding: .22rem .35rem !important; font-size: .68rem !important; }
|
||||
}
|
||||
|
||||
@media (max-width: 520px) {
|
||||
.page-head { flex-direction: column; }
|
||||
.page-head-actions { width: 100%; }
|
||||
.page-head-actions .button { flex: 1; }
|
||||
.item-card-header { align-items: flex-start; }
|
||||
.media-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: .55rem; }
|
||||
.media-card img,
|
||||
.media-card .photo-thumb,
|
||||
.media-card .video-thumb { height: 122px; }
|
||||
.media-meta { align-items: flex-start; flex-direction: column; gap: .1rem; }
|
||||
.status-picker { flex-direction: column; }
|
||||
.status-btn { flex-direction: row; justify-content: flex-start; }
|
||||
.inline-control { align-items: stretch; flex-direction: column; }
|
||||
.inline-admin-grid { grid-template-columns: 1fr; align-items: stretch; }
|
||||
}
|
||||
|
||||
@media (max-width: 400px) {
|
||||
.bottom-tabs a .tab-label { display: none; }
|
||||
.bottom-tabs a { min-width: 2.8rem; padding: 0 .3rem; }
|
||||
}
|
||||
@@ -5,12 +5,17 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="page-head">
|
||||
<h1>{{ title }}</h1>
|
||||
<h1>{{ t.clients_title }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="form-card">
|
||||
<form method="post" action="{{ action_url }}">
|
||||
<div class="field">
|
||||
<section class="admin-section">
|
||||
<header class="admin-section-head">
|
||||
<span class="admin-section-icon" aria-hidden="true">👤</span>
|
||||
<div><h2>{{ title }}</h2></div>
|
||||
</header>
|
||||
<div class="admin-section-body">
|
||||
<form method="post" action="{{ action_url }}" class="form-grid">
|
||||
<div class="field admin-field-wide">
|
||||
<label class="label">{{ t.clients_name }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="name" value="{{ client_name }}" required>
|
||||
@@ -28,41 +33,42 @@
|
||||
<input class="input" type="email" name="email" value="{{ client_email }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field admin-field-wide">
|
||||
<label class="label">{{ t.clients_address }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="address" value="{{ client_address }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field admin-field-wide">
|
||||
<label class="label">{{ t.clients_notes }}</label>
|
||||
<div class="control">
|
||||
<textarea class="textarea" name="notes" rows="3">{{ client_notes }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field admin-field-wide">
|
||||
<label class="label">{{ t.clients_color }}</label>
|
||||
<div class="control" style="display:flex;align-items:center;gap:0.5rem;">
|
||||
<input type="color" name="color" value="{{ client_color }}" style="width:3rem;height:2.2rem;padding:0;border:1px solid #ddd;border-radius:6px;cursor:pointer;">
|
||||
<div class="control color-control">
|
||||
<input type="color" name="color" value="{{ client_color }}">
|
||||
<span class="has-text-grey is-size-7">{{ client_color }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field admin-field-wide">
|
||||
<button type="submit" class="button is-primary is-fullwidth">{{ submit_label }}</button>
|
||||
</div>
|
||||
</form>
|
||||
{% if is_edit %}
|
||||
<hr>
|
||||
<div class="portal-panel">
|
||||
<div class="field">
|
||||
<label class="label">{{ t.portal_link }}</label>
|
||||
<div class="control" style="display:flex;align-items:center;gap:0.5rem;">
|
||||
<input class="input is-small" type="text" readonly id="portalUrl" value="" style="flex:1;">
|
||||
<div class="control inline-control">
|
||||
<input class="input is-small" type="text" readonly id="portalUrl" value="">
|
||||
<button type="button" class="button is-small is-info is-outlined" onclick="navigator.clipboard.writeText(document.getElementById('portalUrl').value)">📋</button>
|
||||
</div>
|
||||
<div style="margin-top:0.75rem;text-align:center;">
|
||||
<canvas id="qrCanvas" style="max-width:180px;"></canvas>
|
||||
<div class="portal-qr">
|
||||
<canvas id="qrCanvas"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/qrious@4.0.2/dist/qrious.min.js"></script>
|
||||
<script>
|
||||
(function() {
|
||||
@@ -71,7 +77,7 @@
|
||||
new QRious({ element: document.getElementById('qrCanvas'), value: url, size: 180, level: 'M' });
|
||||
})();
|
||||
</script>
|
||||
<hr>
|
||||
<div class="danger-zone">
|
||||
{% if client_status == "active" %}
|
||||
<form method="post" action="/admin/clients/{{ client_id }}/archive">
|
||||
<button type="submit" class="button is-warning is-outlined is-fullwidth">{{ t.action_archive }}</button>
|
||||
@@ -82,10 +88,12 @@
|
||||
</form>
|
||||
{% endif %}
|
||||
{% if client_status != "deleted" %}
|
||||
<form method="post" action="/admin/clients/{{ client_id }}/delete" onsubmit="return confirm('{{ t.clients_delete_confirm }}');" style="margin-top:0.75rem;">
|
||||
<form method="post" action="/admin/clients/{{ client_id }}/delete" onsubmit="return confirm('{{ t.clients_delete_confirm }}');" class="mt-3">
|
||||
<button type="submit" class="button is-danger is-outlined is-fullwidth">{{ t.clients_delete }}</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
{% block content %}
|
||||
<div class="page-head">
|
||||
<h1>{{ t.clients_title }}</h1>
|
||||
<div>
|
||||
<div class="page-head-actions">
|
||||
{% if show_all %}
|
||||
<a href="/admin/clients?lang={{ lang.code() }}" class="button is-small is-light">{{ t.filter_show_active }}</a>
|
||||
{% else %}
|
||||
@@ -17,19 +17,19 @@
|
||||
</div>
|
||||
|
||||
{% if clients.is_empty() %}
|
||||
<p class="has-text-grey">{{ t.clients_empty }}</p>
|
||||
<p class="empty-state">{{ t.clients_empty }}</p>
|
||||
{% else %}
|
||||
{% for client in &clients %}
|
||||
<div class="item-card">
|
||||
<div class="item-card-header">
|
||||
<a href="/admin/clients/{{ client.id }}/edit?lang={{ lang.code() }}" class="name" style="text-decoration:none;color:inherit;">
|
||||
<span style="display:inline-block;width:12px;height:12px;border-radius:50%;background:{{ client.color.as_deref().unwrap_or("#7c6ed4") }};margin-right:6px;vertical-align:middle;"></span>{{ client.name }}
|
||||
<a href="/admin/clients/{{ client.id }}/edit?lang={{ lang.code() }}" class="name card-link">
|
||||
<span class="color-dot" style="background:{{ client.color.as_deref().unwrap_or("#7c6ed4") }}"></span>{{ client.name }}
|
||||
</a>
|
||||
<span class="badge badge-{{ client.status }}">{{ t.client_status(&client.status) }}</span>
|
||||
</div>
|
||||
<div class="item-card-meta">
|
||||
{% if let Some(phone) = client.phone.as_deref() %}
|
||||
<span><a href="tel:{{ phone }}" style="color:inherit;text-decoration:none;">📞 {{ phone }}</a></span>
|
||||
<span><a href="tel:{{ phone }}" class="card-link">📞 {{ phone }}</a></span>
|
||||
{% endif %}
|
||||
{% if let Some(email) = client.email.as_deref() %}
|
||||
<span>✉️ {{ email }}</span>
|
||||
|
||||
@@ -10,27 +10,27 @@
|
||||
</div>
|
||||
|
||||
{% if today_visits.is_empty() %}
|
||||
<p class="has-text-grey">{{ t.dashboard_no_visits }}</p>
|
||||
<p class="empty-state">{{ t.dashboard_no_visits }}</p>
|
||||
{% else %}
|
||||
{% for tv in &today_visits %}
|
||||
<div class="item-card">
|
||||
<div class="item-card-header">
|
||||
<a href="/admin/schedule/{{ tv.visit.id }}/edit?lang={{ lang.code() }}" class="name" style="text-decoration:none;color:inherit;">
|
||||
<span style="display:inline-block;width:12px;height:12px;border-radius:50%;background:{{ tv.client_color }};margin-right:6px;vertical-align:middle;"></span>{{ tv.client_name }}
|
||||
<a href="/admin/schedule/{{ tv.visit.id }}/edit?lang={{ lang.code() }}" class="name card-link">
|
||||
<span class="color-dot" style="background:{{ tv.client_color }}"></span>{{ tv.client_name }}
|
||||
</a>
|
||||
<span class="badge badge-visit-{{ tv.visit.status }}">{{ t.visit_status(&tv.visit.status) }}</span>
|
||||
</div>
|
||||
<div class="item-card-meta">
|
||||
<span>🕐 {{ tv.visit.time_start }} — {{ tv.visit.time_end }}</span>
|
||||
{% if !tv.client_phone.is_empty() %}
|
||||
<span><a href="tel:{{ tv.client_phone }}" style="color:inherit;text-decoration:none;">📞 {{ tv.client_phone }}</a></span>
|
||||
<span><a href="tel:{{ tv.client_phone }}" class="card-link">📞 {{ tv.client_phone }}</a></span>
|
||||
{% endif %}
|
||||
{% if !tv.client_address.is_empty() %}
|
||||
<span>📍 {{ tv.client_address }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if let Some(notes) = tv.visit.notes.as_deref() %}
|
||||
<div style="color:#888;font-size:0.82rem;margin-top:0.3rem;">{{ notes }}</div>
|
||||
<div class="card-note">{{ notes }}</div>
|
||||
{% endif %}
|
||||
<div class="item-card-actions">
|
||||
{% if tv.visit.status == "scheduled" %}
|
||||
@@ -48,22 +48,22 @@
|
||||
{% endif %}
|
||||
|
||||
<!-- Feedbacks -->
|
||||
<h2 style="font-size:1.15rem;font-weight:700;margin:1.5rem 0 0.75rem;">{{ t.dashboard_recent_feedbacks }}</h2>
|
||||
<h2 class="section-title">{{ t.dashboard_recent_feedbacks }}</h2>
|
||||
{% if feedbacks.is_empty() %}
|
||||
<p class="has-text-grey">{{ t.dashboard_no_feedbacks }}</p>
|
||||
<p class="empty-state">{{ t.dashboard_no_feedbacks }}</p>
|
||||
{% else %}
|
||||
{% for fb in &feedbacks %}
|
||||
<a href="/admin/schedule/{{ fb.visit_id }}/edit?lang={{ lang.code() }}" class="item-card" style="border-left:3px solid #7c6cff;display:block;text-decoration:none;color:inherit;">
|
||||
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:0.25rem;">
|
||||
<strong style="font-size:0.9rem;">{{ fb.client_name }}</strong>
|
||||
<span style="color:#999;font-size:0.8rem;">{{ fb.visit_date }}</span>
|
||||
<a href="/admin/schedule/{{ fb.visit_id }}/edit?lang={{ lang.code() }}" class="item-card feedback-card">
|
||||
<div class="feedback-head">
|
||||
<strong>{{ fb.client_name }}</strong>
|
||||
<span class="feedback-date">{{ fb.visit_date }}</span>
|
||||
</div>
|
||||
<div style="font-size:0.85rem;color:#4a4570;">{{ fb.feedback }}</div>
|
||||
<div class="feedback-text">{{ fb.feedback }}</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
|
||||
{% if feedback_total_pages > 1 %}
|
||||
<div style="display:flex;justify-content:center;gap:0.5rem;margin-top:1rem;">
|
||||
<div class="pagination-row">
|
||||
{% if feedback_page > 1 %}
|
||||
<a href="/admin/?lang={{ lang.code() }}&page={{ feedback_page - 1 }}" class="button is-small is-light">«</a>
|
||||
{% endif %}
|
||||
|
||||
+3
-109
@@ -6,119 +6,13 @@
|
||||
<title>{{ t.nav_title }} — {% block title %}{% endblock %}</title>
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1/css/bulma.min.css">
|
||||
<style>
|
||||
:root { --accent: #6c63ff; color-scheme: light; }
|
||||
body { padding-bottom: 4rem; min-height: 100vh; background: #f5f5f5; color: #333; }
|
||||
|
||||
/* ── Top bar ── */
|
||||
.top-header {
|
||||
background: #fff; border-bottom: 1px solid #e8e8e8;
|
||||
padding: 0.5rem 1rem; display: flex; align-items: center;
|
||||
justify-content: space-between; position: sticky; top: 0; z-index: 30;
|
||||
}
|
||||
.top-header .brand { font-weight: 700; font-size: 1.1rem; color: #333; text-decoration: none; }
|
||||
.top-header-right { display: flex; align-items: center; gap: 0.75rem; font-size: 0.85rem; }
|
||||
.top-header-right a { color: #888; text-decoration: none; }
|
||||
.top-header-right .admin-name { color: #aaa; }
|
||||
|
||||
/* ── Bottom tabs (mobile nav) ── */
|
||||
.bottom-tabs {
|
||||
position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
|
||||
background: #fff; border-top: 1px solid #e8e8e8;
|
||||
display: flex; height: 3.5rem;
|
||||
overflow-x: auto; -webkit-overflow-scrolling: touch;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
.bottom-tabs::-webkit-scrollbar { display: none; }
|
||||
.bottom-tabs a {
|
||||
flex: 0 0 auto; min-width: 3.2rem; padding: 0 0.45rem;
|
||||
display: flex; flex-direction: column; align-items: center;
|
||||
justify-content: center; text-decoration: none; color: #999;
|
||||
font-size: 0.6rem; font-weight: 600; gap: 0.1rem;
|
||||
transition: color 0.15s; white-space: nowrap;
|
||||
}
|
||||
.bottom-tabs a .tab-icon { font-size: 1.25rem; line-height: 1; }
|
||||
.bottom-tabs a .tab-label { display: block; }
|
||||
.bottom-tabs a.is-active { color: var(--accent); }
|
||||
@media (max-width: 400px) {
|
||||
.bottom-tabs a .tab-label { display: none; }
|
||||
.bottom-tabs a { min-width: 2.8rem; padding: 0 0.3rem; }
|
||||
}
|
||||
|
||||
/* ── Desktop: hide bottom tabs, show top nav ── */
|
||||
.desktop-nav { display: none; }
|
||||
@media (min-width: 769px) {
|
||||
body { padding-bottom: 0; }
|
||||
.bottom-tabs { display: none; }
|
||||
.desktop-nav { display: flex; gap: 0.25rem; }
|
||||
.desktop-nav a {
|
||||
padding: 0.3rem 0.75rem; border-radius: 6px; font-size: 0.9rem;
|
||||
color: #555; text-decoration: none; transition: background 0.15s;
|
||||
}
|
||||
.desktop-nav a:hover { background: #f0f0f0; }
|
||||
.desktop-nav a.is-active { background: var(--accent); color: #fff; }
|
||||
}
|
||||
|
||||
/* ── Content ── */
|
||||
.main-content { padding: 1rem; max-width: 900px; margin: 0 auto; }
|
||||
|
||||
/* ── Status badges ── */
|
||||
.badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 99px; font-size: 0.75rem; font-weight: 600; }
|
||||
.badge-new { background: #dbeafe; color: #1e40af; }
|
||||
.badge-in_progress { background: #fef3c7; color: #92400e; }
|
||||
.badge-converted { background: #d1fae5; color: #065f46; }
|
||||
.badge-rejected { background: #fee2e2; color: #991b1b; }
|
||||
.badge-active { background: #d1fae5; color: #065f46; }
|
||||
.badge-archived { background: #e5e7eb; color: #374151; }
|
||||
.badge-visit-scheduled { background: #dbeafe; color: #1e40af; }
|
||||
.badge-visit-completed { background: #d1fae5; color: #065f46; }
|
||||
.badge-visit-cancelled { background: #e5e7eb; color: #374151; }
|
||||
|
||||
/* ── Item cards ── */
|
||||
.item-card {
|
||||
background: #fff; border-radius: 10px; padding: 0.85rem 1rem;
|
||||
margin-bottom: 0.6rem; border: 1px solid #eee;
|
||||
}
|
||||
.item-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.3rem; }
|
||||
.item-card-header .name { font-weight: 700; font-size: 1rem; }
|
||||
.item-card-meta { color: #888; font-size: 0.82rem; line-height: 1.5; }
|
||||
.item-card-meta span { margin-right: 1rem; }
|
||||
.item-card-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.5rem; }
|
||||
.item-card-actions form { margin: 0; }
|
||||
|
||||
/* ── Small buttons ── */
|
||||
.btn-sm { font-size: 0.78rem !important; padding: 0.25rem 0.6rem !important; height: auto !important; }
|
||||
|
||||
/* ── Page header ── */
|
||||
.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
|
||||
.page-head h1 { font-size: 1.3rem; font-weight: 700; margin: 0; }
|
||||
|
||||
/* ── Forms ── */
|
||||
.form-card { background: #fff; border-radius: 10px; padding: 1.25rem; border: 1px solid #eee; }
|
||||
input, textarea, select,
|
||||
.input, .textarea, .select select {
|
||||
background-color: #fff !important;
|
||||
color: #333 !important;
|
||||
border-color: #dbdbdb !important;
|
||||
}
|
||||
.label, label {
|
||||
color: #363636 !important;
|
||||
}
|
||||
h1, h2, h3, h4, h5, h6, strong, b, p, span, div, a, td, th, li {
|
||||
color: inherit;
|
||||
}
|
||||
.title, .subtitle, .content, .has-text-dark {
|
||||
color: #363636 !important;
|
||||
}
|
||||
.has-text-grey { color: #7a7a7a !important; }
|
||||
.notification { color: #333 !important; }
|
||||
</style>
|
||||
<link rel="stylesheet" href="/static/admin.css?v={{ t.app_version() }}">
|
||||
</head>
|
||||
<body>
|
||||
<body class="admin-shell">
|
||||
|
||||
<!-- Top header -->
|
||||
<div class="top-header">
|
||||
<a class="brand" href="/admin/?lang={{ lang.code() }}">🐾 {{ t.nav_title }} <span style="font-size:0.7rem;font-weight:400;color:#aaa;">v{{ t.app_version() }}</span></a>
|
||||
<a class="brand" href="/admin/?lang={{ lang.code() }}">🐾 {{ t.nav_title }} <span class="brand-version">v{{ t.app_version() }}</span></a>
|
||||
<nav class="desktop-nav">
|
||||
<a href="/admin/?lang={{ lang.code() }}" {% if active_page == "dashboard" %}class="is-active"{% endif %}>{{ t.dashboard_title }}</a>
|
||||
<a href="/admin/leads?lang={{ lang.code() }}" {% if active_page == "leads" %}class="is-active"{% endif %}>{{ t.nav_leads }}</a>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
</div>
|
||||
|
||||
{% if leads.is_empty() %}
|
||||
<p class="has-text-grey">{{ t.leads_empty }}</p>
|
||||
<p class="empty-state">{{ t.leads_empty }}</p>
|
||||
{% else %}
|
||||
{% for lead in &leads %}
|
||||
<div class="item-card">
|
||||
@@ -24,7 +24,7 @@
|
||||
</div>
|
||||
<div class="item-card-meta">
|
||||
{% if let Some(phone) = lead.phone.as_deref() %}
|
||||
<span><a href="tel:{{ phone }}" style="color:inherit;text-decoration:none;">📞 {{ phone }}</a></span>
|
||||
<span><a href="tel:{{ phone }}" class="card-link">📞 {{ phone }}</a></span>
|
||||
{% endif %}
|
||||
{% if let Some(comment) = lead.comment.as_deref() %}
|
||||
<span>💬 {{ comment }}</span>
|
||||
|
||||
+10
-20
@@ -6,31 +6,21 @@
|
||||
<title>{{ t.nav_title }} — {{ t.login_title }}</title>
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1/css/bulma.min.css">
|
||||
<link rel="stylesheet" href="/static/admin.css?v={{ t.app_version() }}">
|
||||
{% if !turnstile_site_key.is_empty() %}
|
||||
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
|
||||
{% endif %}
|
||||
<style>
|
||||
:root { color-scheme: light; }
|
||||
body { background: #f5f5f5; display: flex; align-items: center; justify-content: center; min-height: 100vh; color: #333; }
|
||||
.login-box { width: 100%; max-width: 380px; padding: 0 1rem; }
|
||||
.login-card { background: #fff; border-radius: 12px; padding: 2rem 1.5rem; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
|
||||
input, textarea, select, .input, .textarea, .select select {
|
||||
background-color: #fff !important; color: #333 !important; border-color: #dbdbdb !important;
|
||||
}
|
||||
.label, label { color: #363636 !important; }
|
||||
.notification { color: #333 !important; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<body class="auth-shell">
|
||||
<div class="login-box">
|
||||
<div class="has-text-right mb-3">
|
||||
<a href="?lang={{ lang.other().code() }}" class="has-text-grey is-size-7">{{ lang.other().label() }}</a>
|
||||
<div class="auth-language">
|
||||
<a href="?lang={{ lang.other().code() }}">{{ lang.other().label() }}</a>
|
||||
</div>
|
||||
<div class="login-card">
|
||||
<div class="has-text-centered mb-4">
|
||||
<p class="is-size-3">🐾</p>
|
||||
<h1 class="is-size-4 has-text-weight-bold">{{ t.nav_title }}</h1>
|
||||
<p class="has-text-grey">{{ t.login_title }}</p>
|
||||
<div class="auth-head">
|
||||
<span class="auth-icon">🐾</span>
|
||||
<h1>{{ t.nav_title }}</h1>
|
||||
<p>{{ t.login_title }}</p>
|
||||
</div>
|
||||
{% if let Some(err) = error.as_ref() %}
|
||||
<div class="notification is-danger is-light">{{ err }}</div>
|
||||
@@ -39,7 +29,7 @@
|
||||
<a href="/admin/oidc/start" class="button is-primary is-fullwidth mt-3">{{ t.login_sso_button }}</a>
|
||||
{% endif %}
|
||||
{% if auth_password_enabled %}
|
||||
{% if auth_sso_enabled %}<hr style="margin:1rem 0;">{% endif %}
|
||||
{% if auth_sso_enabled %}<hr class="auth-divider">{% endif %}
|
||||
<form method="post" action="/admin/login/submit">
|
||||
<div class="field">
|
||||
<label class="label">{{ t.users_login }}</label>
|
||||
@@ -50,7 +40,7 @@
|
||||
<div class="control"><input class="input" type="password" name="password" required></div>
|
||||
</div>
|
||||
{% if !turnstile_site_key.is_empty() %}
|
||||
<div class="cf-turnstile" data-sitekey="{{ turnstile_site_key }}" data-theme="light" style="margin-top:0.75rem;"></div>
|
||||
<div class="cf-turnstile turnstile-wrap" data-sitekey="{{ turnstile_site_key }}" data-theme="light"></div>
|
||||
{% endif %}
|
||||
<button type="submit" class="button is-primary is-fullwidth mt-3">{{ t.login_button }}</button>
|
||||
</form>
|
||||
|
||||
+27
-70
@@ -9,7 +9,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Client filter -->
|
||||
<div style="margin-bottom:1rem;">
|
||||
<div class="filter-bar">
|
||||
<div class="select is-small">
|
||||
<select onchange="window.location.href='/admin/media?lang={{ lang.code() }}' + (this.value ? '&client_id=' + this.value : '')">
|
||||
<option value="">{{ t.media_all_clients }}</option>
|
||||
@@ -21,19 +21,23 @@
|
||||
</div>
|
||||
|
||||
{% if items.is_empty() %}
|
||||
<p class="has-text-grey">{{ t.media_empty }}</p>
|
||||
<p class="empty-state">{{ t.media_empty }}</p>
|
||||
{% else %}
|
||||
<div class="media-grid">
|
||||
{% for item in &items %}
|
||||
<div class="media-card">
|
||||
{% if item.media.file_type == "photo" %}
|
||||
<a href="/admin/uploads/{{ item.media.id.unwrap() }}" data-lightbox="photo">
|
||||
<img src="/admin/uploads/{{ item.media.id.unwrap() }}" alt="" loading="lazy">
|
||||
<a href="{{ item.media.url }}" data-lightbox="photo">
|
||||
<span class="photo-thumb media-loading-frame is-loading">
|
||||
<img src="{{ item.media.thumbnail_url }}" alt="" loading="lazy" data-media-load>
|
||||
</span>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="/admin/uploads/{{ item.media.id.unwrap() }}" data-lightbox="video">
|
||||
<div class="video-thumb">
|
||||
<video src="/admin/uploads/{{ item.media.id.unwrap() }}#t=0.1" preload="metadata" muted playsinline></video>
|
||||
<a href="{{ item.media.url }}" data-lightbox="video">
|
||||
<div class="video-thumb media-loading-frame{% if !item.media.thumbnail_url.is_empty() %} is-loading{% endif %}" data-video-preview>
|
||||
{% if !item.media.thumbnail_url.is_empty() %}
|
||||
<img class="video-preview-sprite" src="{{ item.media.thumbnail_url }}" alt="" loading="lazy" data-media-load data-preview-frames="4">
|
||||
{% endif %}
|
||||
<span class="video-play">▶</span>
|
||||
</div>
|
||||
</a>
|
||||
@@ -42,79 +46,32 @@
|
||||
<div class="media-meta">
|
||||
<strong>{{ item.client_name }}</strong>
|
||||
{% if let Some(d) = item.visit_date.as_deref() %}
|
||||
<span style="color:#999;">{{ d }}</span>
|
||||
<span class="feedback-date">{{ d }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if let Some(cap) = item.media.caption.as_deref() %}
|
||||
<div style="font-size:0.82rem;color:#666;margin-top:0.2rem;">{{ cap }}</div>
|
||||
<div class="media-caption">{{ cap }}</div>
|
||||
{% endif %}
|
||||
<form method="post" action="/admin/media/{{ item.media.id.unwrap() }}/delete" onsubmit="return confirm('{{ t.media_delete_confirm }}');" style="margin-top:0.3rem;">
|
||||
<form method="post" action="/admin/media/{{ item.media.id.unwrap() }}/delete" onsubmit="return confirm('{{ t.media_delete_confirm }}');" class="mt-2">
|
||||
<button class="button is-small is-danger is-outlined btn-sm">{{ t.media_delete }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% if total_pages > 1 %}
|
||||
<nav class="media-pagination" aria-label="Pagination">
|
||||
{% if page > 1 %}
|
||||
<a class="button is-small" href="/admin/media?lang={{ lang.code() }}&page={{ page - 1 }}{% if filter_client_id > 0 %}&client_id={{ filter_client_id }}{% endif %}">←</a>
|
||||
{% endif %}
|
||||
{% for p in 1..=total_pages %}
|
||||
<a class="button is-small{% if p == page %} is-link{% endif %}" href="/admin/media?lang={{ lang.code() }}&page={{ p }}{% if filter_client_id > 0 %}&client_id={{ filter_client_id }}{% endif %}">{{ p }}</a>
|
||||
{% endfor %}
|
||||
{% if page < total_pages %}
|
||||
<a class="button is-small" href="/admin/media?lang={{ lang.code() }}&page={{ page + 1 }}{% if filter_client_id > 0 %}&client_id={{ filter_client_id }}{% endif %}">→</a>
|
||||
{% endif %}
|
||||
</nav>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<style>
|
||||
.media-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 0.75rem;
|
||||
}
|
||||
.media-card {
|
||||
background: #fff;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #eee;
|
||||
overflow: hidden;
|
||||
}
|
||||
.media-card img {
|
||||
width: 100%;
|
||||
height: 160px;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
.media-card .video-thumb {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 160px;
|
||||
background: #111;
|
||||
}
|
||||
.media-card .video-thumb video {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
object-fit: cover;
|
||||
}
|
||||
.media-card .video-play {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-size: 2.5rem;
|
||||
line-height: 1;
|
||||
text-shadow: 0 1px 5px #000;
|
||||
pointer-events: none;
|
||||
}
|
||||
.media-info {
|
||||
padding: 0.6rem 0.75rem;
|
||||
}
|
||||
.media-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 0.85rem;
|
||||
color: #333;
|
||||
}
|
||||
@media (max-width: 480px) {
|
||||
.media-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
||||
}
|
||||
.media-card img, .media-card .video-thumb {
|
||||
height: 120px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
@@ -5,14 +5,18 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="page-head">
|
||||
<h1>{{ t.media_upload_title }}</h1>
|
||||
<h1>{{ t.media_title }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="form-card">
|
||||
<div style="margin-bottom:1rem;font-size:0.9rem;color:#666;">
|
||||
<div><strong>{{ t.schedule_client }}:</strong> {{ client_name }}</div>
|
||||
<div><strong>{{ t.schedule_date }}:</strong> {{ visit_label }}</div>
|
||||
</div>
|
||||
<section class="admin-section">
|
||||
<header class="admin-section-head">
|
||||
<span class="admin-section-icon" aria-hidden="true">📤</span>
|
||||
<div>
|
||||
<h2>{{ t.media_upload_title }}</h2>
|
||||
<p>{{ client_name }} · {{ visit_label }}</p>
|
||||
</div>
|
||||
</header>
|
||||
<div class="admin-section-body">
|
||||
|
||||
<form id="uploadForm" action="/admin/media/{{ visit_id }}/upload/submit" enctype="multipart/form-data">
|
||||
<div class="field">
|
||||
@@ -20,7 +24,8 @@
|
||||
<div class="control">
|
||||
<input class="input" type="file" id="uploadFiles" name="files" multiple accept="image/*,video/*" required>
|
||||
</div>
|
||||
<p id="fileCount" style="font-size:0.8rem;color:#888;margin-top:0.3rem;"></p>
|
||||
<p id="fileCount" class="field-help"></p>
|
||||
<div id="uploadQueue" class="upload-queue"></div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
@@ -31,13 +36,13 @@
|
||||
</div>
|
||||
|
||||
<!-- Progress -->
|
||||
<div id="uploadProgress" style="display:none;margin-bottom:1rem;">
|
||||
<div style="display:flex;justify-content:space-between;font-size:0.82rem;color:#555;margin-bottom:0.3rem;">
|
||||
<div id="uploadProgress" class="upload-progress">
|
||||
<div class="upload-progress-head">
|
||||
<span id="uploadStatusText">{{ t.media_upload }}...</span>
|
||||
<span id="uploadPercent">0%</span>
|
||||
</div>
|
||||
<div style="background:#e8e8e8;border-radius:99px;height:8px;overflow:hidden;">
|
||||
<div id="uploadBar" style="height:100%;width:0%;background:linear-gradient(90deg,#6c63ff,#b06cff);border-radius:99px;transition:width 0.2s;"></div>
|
||||
<div class="upload-progress-track">
|
||||
<div id="uploadBar" class="upload-progress-bar"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -49,6 +54,7 @@
|
||||
var form = document.getElementById('uploadForm');
|
||||
var filesInput = document.getElementById('uploadFiles');
|
||||
var fileCount = document.getElementById('fileCount');
|
||||
var queue = document.getElementById('uploadQueue');
|
||||
var progress = document.getElementById('uploadProgress');
|
||||
var bar = document.getElementById('uploadBar');
|
||||
var percent = document.getElementById('uploadPercent');
|
||||
@@ -57,9 +63,41 @@
|
||||
|
||||
filesInput.addEventListener('change', function() {
|
||||
var n = this.files.length;
|
||||
fileCount.textContent = n > 0 ? ('Выбрано файлов: ' + n) : '';
|
||||
fileCount.textContent = n > 0 ? ('{{ t.media_files_selected }}: ' + n) : '';
|
||||
queue.replaceChildren();
|
||||
Array.from(this.files).forEach(function(file) {
|
||||
var item = document.createElement('div');
|
||||
item.className = 'upload-queue-item';
|
||||
var icon = document.createElement('span');
|
||||
icon.className = 'upload-queue-icon';
|
||||
icon.textContent = file.type.indexOf('video/') === 0 ? '🎬' : '🖼️';
|
||||
var details = document.createElement('div');
|
||||
var name = document.createElement('div');
|
||||
name.className = 'upload-queue-name';
|
||||
name.textContent = file.name;
|
||||
var state = document.createElement('div');
|
||||
state.className = 'upload-queue-state';
|
||||
state.textContent = '0%';
|
||||
var track = document.createElement('div');
|
||||
track.className = 'upload-queue-track';
|
||||
var itemBar = document.createElement('div');
|
||||
itemBar.className = 'upload-queue-bar';
|
||||
track.appendChild(itemBar);
|
||||
details.append(name, state, track);
|
||||
item.append(icon, details);
|
||||
queue.appendChild(item);
|
||||
});
|
||||
});
|
||||
|
||||
function updateQueue(state, progressValue, processing) {
|
||||
queue.querySelectorAll('.upload-queue-item').forEach(function(item) {
|
||||
item.querySelector('.upload-queue-state').textContent = state;
|
||||
var itemBar = item.querySelector('.upload-queue-bar');
|
||||
itemBar.classList.toggle('is-processing', processing);
|
||||
if (!processing) itemBar.style.width = progressValue + '%';
|
||||
});
|
||||
}
|
||||
|
||||
form.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
if (!filesInput.files.length) return;
|
||||
@@ -69,7 +107,9 @@
|
||||
|
||||
progress.style.display = 'block';
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.textContent = 'Загрузка...';
|
||||
submitBtn.textContent = '{{ t.media_upload_sending }}';
|
||||
statusText.textContent = '{{ t.media_upload_sending }}';
|
||||
bar.classList.remove('is-processing');
|
||||
bar.style.width = '0%';
|
||||
percent.textContent = '0%';
|
||||
|
||||
@@ -78,24 +118,42 @@
|
||||
var pct = Math.round(ev.loaded / ev.total * 100);
|
||||
bar.style.width = pct + '%';
|
||||
percent.textContent = pct + '%';
|
||||
if (pct === 100) statusText.textContent = 'Обработка...';
|
||||
updateQueue(pct + '%', pct, false);
|
||||
if (pct === 100) {
|
||||
statusText.textContent = '{{ t.media_upload_processing }}';
|
||||
percent.textContent = '•••';
|
||||
bar.classList.add('is-processing');
|
||||
updateQueue('{{ t.media_upload_processing }}', 100, true);
|
||||
}
|
||||
});
|
||||
xhr.upload.addEventListener('load', function() {
|
||||
statusText.textContent = '{{ t.media_upload_processing }}';
|
||||
percent.textContent = '•••';
|
||||
bar.classList.add('is-processing');
|
||||
updateQueue('{{ t.media_upload_processing }}', 100, true);
|
||||
});
|
||||
|
||||
xhr.addEventListener('load', function() {
|
||||
if (xhr.status >= 200 && xhr.status < 400) {
|
||||
bar.style.width = '100%';
|
||||
bar.classList.remove('is-processing');
|
||||
percent.textContent = '100%';
|
||||
statusText.textContent = 'Готово!';
|
||||
statusText.textContent = '{{ t.media_upload_done }}';
|
||||
updateQueue('{{ t.media_upload_done }}', 100, false);
|
||||
setTimeout(function() { window.location.href = xhr.responseURL || '/admin/media'; }, 300);
|
||||
} else {
|
||||
bar.classList.remove('is-processing');
|
||||
statusText.textContent = 'Ошибка загрузки (' + xhr.status + ')';
|
||||
updateQueue('Ошибка загрузки', 0, false);
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = '{{ t.media_upload }}';
|
||||
}
|
||||
});
|
||||
|
||||
xhr.addEventListener('error', function() {
|
||||
statusText.textContent = 'Ошибка соединения';
|
||||
bar.classList.remove('is-processing');
|
||||
statusText.textContent = '{{ t.media_upload_connection_error }}';
|
||||
updateQueue('{{ t.media_upload_connection_error }}', 0, false);
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = '{{ t.media_upload }}';
|
||||
});
|
||||
@@ -105,5 +163,7 @@
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<a href="/admin/schedule/new?lang={{ lang.code() }}" class="button is-primary is-small">+ {{ t.schedule_new }}</a>
|
||||
</div>
|
||||
|
||||
<div class="form-card" id="calendar-wrap" style="padding:0.5rem;">
|
||||
<div class="form-card" id="calendar-wrap">
|
||||
<div id="calendar"></div>
|
||||
</div>
|
||||
|
||||
@@ -18,40 +18,6 @@
|
||||
{% if lang == Lang::Ru %}
|
||||
<script src="https://cdn.jsdelivr.net/npm/@fullcalendar/core@6.1.17/locales/ru.global.min.js"></script>
|
||||
{% endif %}
|
||||
<style>
|
||||
#calendar-wrap { overflow: hidden; }
|
||||
.fc { font-size: 0.85rem; color: #333; }
|
||||
.fc .fc-daygrid-day-number,
|
||||
.fc .fc-col-header-cell-cushion,
|
||||
.fc .fc-list-day-text,
|
||||
.fc .fc-list-day-side-text { color: #333 !important; }
|
||||
.fc th, .fc td { color: #333; }
|
||||
.fc .fc-toolbar-title { color: #333 !important; }
|
||||
.fc .fc-button { color: #fff !important; }
|
||||
.fc .fc-toolbar { flex-wrap: wrap; gap: 0.3rem; }
|
||||
.fc .fc-toolbar-title { font-size: 1.1rem !important; }
|
||||
.fc .fc-button { padding: 0.25rem 0.5rem !important; font-size: 0.8rem !important; }
|
||||
.fc-event { cursor: pointer; border: none !important; padding: 2px 5px; border-radius: 4px; }
|
||||
.fc-event.ev-completed .fc-event-title,
|
||||
.fc-event.ev-completed .fc-list-event-title { text-decoration: line-through; opacity: 0.75; }
|
||||
.fc-event.ev-cancelled .fc-event-title,
|
||||
.fc-event.ev-cancelled .fc-list-event-title { text-decoration: line-through; }
|
||||
.fc .fc-day-today { background: #eef2ff !important; }
|
||||
.fc .fc-day.day-weekend { background: #faf5f0; }
|
||||
.fc .fc-day-today.day-weekend { background: #eef2ff !important; }
|
||||
@media (max-width: 768px) {
|
||||
.fc .fc-toolbar { font-size: 0.75rem; }
|
||||
.fc .fc-toolbar-title { font-size: 0.95rem !important; }
|
||||
.fc .fc-button { padding: 0.2rem 0.35rem !important; font-size: 0.72rem !important; }
|
||||
}
|
||||
.visit-modal-bg { display:none; position:fixed; inset:0; background:rgba(0,0,0,0.35); z-index:100; align-items:center; justify-content:center; }
|
||||
.visit-modal-bg.is-open { display:flex; }
|
||||
.visit-modal { background:#fff; border-radius:12px; padding:1.5rem; width:90%; max-width:380px; box-shadow:0 4px 24px rgba(0,0,0,0.15); }
|
||||
.visit-modal h3 { margin:0 0 0.75rem; font-size:1.1rem; }
|
||||
.visit-modal .meta { color:#888; font-size:0.85rem; margin-bottom:0.75rem; line-height:1.6; }
|
||||
.color-dot { display:inline-block; width:12px; height:12px; border-radius:50%; margin-right:6px; vertical-align:middle; }
|
||||
</style>
|
||||
|
||||
<div class="visit-modal-bg" id="visitModal">
|
||||
<div class="visit-modal">
|
||||
<h3><span class="color-dot" id="vmDot"></span><span id="vmTitle"></span></h3>
|
||||
@@ -60,10 +26,10 @@
|
||||
<div id="vmAddress"></div>
|
||||
<div id="vmAdmin"></div>
|
||||
<div id="vmTime"></div>
|
||||
<div id="vmNotes" style="margin-top:0.3rem;"></div>
|
||||
<div id="vmNotes" class="mt-2"></div>
|
||||
</div>
|
||||
<div id="vmStatus" style="margin-bottom:1rem;"></div>
|
||||
<a id="vmEditLink" href="#" class="button is-primary is-fullwidth" style="font-size:1rem;font-weight:700;padding:0.65rem;">📋 {{ t.schedule_edit_title }}</a>
|
||||
<div id="vmStatus" class="mb-4"></div>
|
||||
<a id="vmEditLink" href="#" class="button is-primary is-fullwidth">📋 {{ t.schedule_edit_title }}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -82,7 +48,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
timeZone: '{{ timezone }}',
|
||||
initialView: window.innerWidth < 768 ? 'listWeek' : 'dayGridMonth',
|
||||
headerToolbar: {
|
||||
left: 'prev,next today',
|
||||
left: 'prev,next,today',
|
||||
center: 'title',
|
||||
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
|
||||
},
|
||||
@@ -98,7 +64,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const p = ev.extendedProps;
|
||||
document.getElementById('vmDot').style.background = p.client_color || '#7c6ed4';
|
||||
document.getElementById('vmTitle').textContent = p.client_name;
|
||||
document.getElementById('vmClient').innerHTML = p.client_phone ? ('<a href="tel:' + p.client_phone + '" style="color:inherit;text-decoration:none;">📞 ' + p.client_phone + '</a>') : '';
|
||||
document.getElementById('vmClient').innerHTML = p.client_phone ? ('<a href="tel:' + p.client_phone + '" class="card-link">📞 ' + p.client_phone + '</a>') : '';
|
||||
document.getElementById('vmAddress').textContent = p.client_address ? ('📍 ' + p.client_address) : '';
|
||||
document.getElementById('vmAdmin').textContent = '👤 ' + p.admin_name;
|
||||
document.getElementById('vmTime').textContent = '🕐 ' + p.time_start + ' — ' + p.time_end;
|
||||
|
||||
@@ -5,10 +5,18 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="page-head">
|
||||
<h1>{{ t.schedule_edit_title }}</h1>
|
||||
<h1>{{ t.schedule_title }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="form-card">
|
||||
<section class="admin-section">
|
||||
<header class="admin-section-head">
|
||||
<span class="admin-section-icon" aria-hidden="true">📋</span>
|
||||
<div>
|
||||
<h2>{{ t.schedule_edit_title }}</h2>
|
||||
<p>{{ client.name }}</p>
|
||||
</div>
|
||||
</header>
|
||||
<div class="admin-section-body">
|
||||
<form method="post" action="/admin/schedule/{{ visit.id }}/save">
|
||||
<!-- Client -->
|
||||
<div class="field">
|
||||
@@ -45,7 +53,7 @@
|
||||
<!-- Time -->
|
||||
<div class="field">
|
||||
<label class="label">{{ t.schedule_default_time }}</label>
|
||||
<div class="columns is-mobile" style="margin-bottom:0;">
|
||||
<div class="columns is-mobile time-columns">
|
||||
<div class="column">
|
||||
<div class="control">
|
||||
<input class="input" type="time" name="time_start" value="{{ visit.time_start }}" required>
|
||||
@@ -93,33 +101,37 @@
|
||||
</div>
|
||||
|
||||
{% if let Some(fb) = visit.client_feedback.as_deref() %}
|
||||
<div style="margin-bottom:1rem;">
|
||||
<div class="mb-4">
|
||||
<label class="label">{{ t.schedule_client_feedback }}</label>
|
||||
<div style="background:#f0f0ff;border-radius:8px;padding:0.6rem 0.85rem;font-size:0.9rem;color:#4a4570;">{{ fb }}</div>
|
||||
<div class="admin-note admin-note-info">{{ fb }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<hr style="margin:1rem 0;">
|
||||
<hr>
|
||||
|
||||
<!-- Media -->
|
||||
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:0.75rem;">
|
||||
<label class="label" style="margin:0;">{{ t.nav_media }}</label>
|
||||
<div class="section-inline-head">
|
||||
<label class="label">{{ t.nav_media }}</label>
|
||||
<button type="button" class="button is-info is-small is-outlined" onclick="document.getElementById('uploadModal').classList.add('is-open')">+ {{ t.media_upload }}</button>
|
||||
</div>
|
||||
{% if media.is_empty() %}
|
||||
<p class="has-text-grey is-size-7" style="margin-bottom:1rem;">{{ t.media_empty }}</p>
|
||||
<p class="empty-state mb-4">{{ t.media_empty }}</p>
|
||||
{% else %}
|
||||
<div class="visit-media-grid">
|
||||
{% for m in &media %}
|
||||
<div class="visit-media-item">
|
||||
{% if m.file_type == "photo" %}
|
||||
<a href="/admin/uploads/{{ m.id.unwrap() }}" data-lightbox="photo">
|
||||
<img src="/admin/uploads/{{ m.id.unwrap() }}" alt="" loading="lazy">
|
||||
<a href="{{ m.url }}" data-lightbox="photo">
|
||||
<span class="photo-thumb media-loading-frame is-loading">
|
||||
<img src="{{ m.thumbnail_url }}" alt="" loading="lazy" data-media-load>
|
||||
</span>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="/admin/uploads/{{ m.id.unwrap() }}" data-lightbox="video">
|
||||
<div class="video-thumb-sm">
|
||||
<video src="/admin/uploads/{{ m.id.unwrap() }}#t=0.1" preload="metadata" muted playsinline></video>
|
||||
<a href="{{ m.url }}" data-lightbox="video">
|
||||
<div class="video-thumb-sm media-loading-frame{% if !m.thumbnail_url.is_empty() %} is-loading{% endif %}" data-video-preview>
|
||||
{% if !m.thumbnail_url.is_empty() %}
|
||||
<img class="video-preview-sprite" src="{{ m.thumbnail_url }}" alt="" loading="lazy" data-media-load data-preview-frames="4">
|
||||
{% endif %}
|
||||
<span class="video-play">▶</span>
|
||||
</div>
|
||||
</a>
|
||||
@@ -135,7 +147,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<hr style="margin:1rem 0;">
|
||||
<hr>
|
||||
|
||||
<button type="submit" class="button is-primary is-fullwidth">{{ t.schedule_save }}</button>
|
||||
</form>
|
||||
@@ -143,18 +155,19 @@
|
||||
<form id="visit-media-delete-{{ m.id.unwrap() }}" method="post" action="/admin/media/{{ m.id.unwrap() }}/delete" onsubmit="return confirm('{{ t.media_delete_confirm }}');"></form>
|
||||
{% endfor %}
|
||||
|
||||
<hr style="margin:1rem 0;">
|
||||
<hr>
|
||||
<form method="post" action="/admin/schedule/{{ visit.id }}/delete" onsubmit="return confirm('{{ t.schedule_delete_confirm }}');">
|
||||
<button type="submit" class="button is-danger is-outlined is-fullwidth is-small">{{ t.schedule_delete }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Upload Modal -->
|
||||
<div class="upload-modal-bg" id="uploadModal">
|
||||
<div class="upload-modal">
|
||||
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem;">
|
||||
<h3 style="font-size:1.1rem;font-weight:700;margin:0;">{{ t.media_upload_title }}</h3>
|
||||
<button type="button" id="uploadModalClose" style="background:none;border:none;font-size:1.2rem;cursor:pointer;color:#888;">✕</button>
|
||||
<div class="modal-head">
|
||||
<h3>{{ t.media_upload_title }}</h3>
|
||||
<button type="button" id="uploadModalClose" class="modal-close">✕</button>
|
||||
</div>
|
||||
<form id="uploadForm" action="/admin/media/{{ visit.id }}/upload/submit" enctype="multipart/form-data">
|
||||
<div class="field">
|
||||
@@ -162,7 +175,8 @@
|
||||
<div class="control">
|
||||
<input class="input" type="file" id="uploadFiles" name="files" multiple accept="image/*,video/*" required>
|
||||
</div>
|
||||
<p id="fileCount" style="font-size:0.8rem;color:#888;margin-top:0.3rem;"></p>
|
||||
<p id="fileCount" class="field-help"></p>
|
||||
<div id="uploadQueue" class="upload-queue"></div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.media_caption }}</label>
|
||||
@@ -172,13 +186,13 @@
|
||||
</div>
|
||||
|
||||
<!-- Progress -->
|
||||
<div id="uploadProgress" style="display:none;margin-bottom:1rem;">
|
||||
<div style="display:flex;justify-content:space-between;font-size:0.82rem;color:#555;margin-bottom:0.3rem;">
|
||||
<div id="uploadProgress" class="upload-progress">
|
||||
<div class="upload-progress-head">
|
||||
<span id="uploadStatusText">{{ t.media_upload }}...</span>
|
||||
<span id="uploadPercent">0%</span>
|
||||
</div>
|
||||
<div style="background:#e8e8e8;border-radius:99px;height:8px;overflow:hidden;">
|
||||
<div id="uploadBar" style="height:100%;width:0%;background:linear-gradient(90deg,#6c63ff,#b06cff);border-radius:99px;transition:width 0.2s;"></div>
|
||||
<div class="upload-progress-track">
|
||||
<div id="uploadBar" class="upload-progress-bar"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -187,118 +201,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.status-picker {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.status-btn {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
padding: 0.6rem 0.4rem;
|
||||
border-radius: 10px;
|
||||
border: 2px solid transparent;
|
||||
background: #f5f5f5;
|
||||
font-size: 0.82rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
color: #777;
|
||||
transition: all 0.15s;
|
||||
line-height: 1.2;
|
||||
}
|
||||
.status-btn-icon { font-size: 1.3rem; line-height: 1; }
|
||||
.status-btn:hover { filter: brightness(0.95); }
|
||||
|
||||
.status-btn-scheduled.is-active { background: #dbeafe; border-color: #3b82f6; color: #1e40af; }
|
||||
.status-btn-completed.is-active { background: #d1fae5; border-color: #22c55e; color: #15803d; }
|
||||
.status-btn-cancelled.is-active { background: #fee2e2; border-color: #ef4444; color: #b91c1c; }
|
||||
|
||||
.status-btn-scheduled:not(.is-active):hover { background: #eff6ff; color: #3b82f6; }
|
||||
.status-btn-completed:not(.is-active):hover { background: #f0fdf4; color: #22c55e; }
|
||||
.status-btn-cancelled:not(.is-active):hover { background: #fff5f5; color: #ef4444; }
|
||||
|
||||
.visit-media-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
.visit-media-item {
|
||||
background: #fafafa;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #eee;
|
||||
overflow: hidden;
|
||||
}
|
||||
.visit-media-item img {
|
||||
width: 100%;
|
||||
height: 80px;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
.visit-media-item .video-thumb-sm {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 80px;
|
||||
background: #111;
|
||||
}
|
||||
.visit-media-item .video-thumb-sm video {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
object-fit: cover;
|
||||
}
|
||||
.visit-media-item .video-play {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
color: white;
|
||||
font-size: 1.6rem;
|
||||
line-height: 1;
|
||||
text-shadow: 0 1px 4px #000;
|
||||
pointer-events: none;
|
||||
}
|
||||
.visit-media-item .media-cap {
|
||||
font-size: 0.7rem;
|
||||
color: #888;
|
||||
padding: 0.2rem 0.4rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.visit-media-delete {
|
||||
padding: 0.25rem 0.4rem 0.4rem;
|
||||
}
|
||||
.visit-media-delete .button {
|
||||
width: 100%;
|
||||
font-size: 0.68rem;
|
||||
min-height: 1.65rem;
|
||||
}
|
||||
.upload-modal-bg {
|
||||
display: none;
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0,0,0,0.35);
|
||||
z-index: 100;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.upload-modal-bg.is-open {
|
||||
display: flex;
|
||||
}
|
||||
.upload-modal {
|
||||
background: #fff;
|
||||
border-radius: 12px;
|
||||
padding: 1.5rem;
|
||||
width: 90%;
|
||||
max-width: 420px;
|
||||
box-shadow: 0 4px 24px rgba(0,0,0,0.15);
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
// Status picker
|
||||
document.querySelectorAll('.status-btn').forEach(function(btn) {
|
||||
@@ -316,6 +218,7 @@ document.querySelectorAll('.status-btn').forEach(function(btn) {
|
||||
var form = document.getElementById('uploadForm');
|
||||
var filesInput = document.getElementById('uploadFiles');
|
||||
var fileCount = document.getElementById('fileCount');
|
||||
var queue = document.getElementById('uploadQueue');
|
||||
var progress = document.getElementById('uploadProgress');
|
||||
var bar = document.getElementById('uploadBar');
|
||||
var percent = document.getElementById('uploadPercent');
|
||||
@@ -336,9 +239,41 @@ document.querySelectorAll('.status-btn').forEach(function(btn) {
|
||||
// Show selected file count
|
||||
filesInput.addEventListener('change', function() {
|
||||
var n = this.files.length;
|
||||
fileCount.textContent = n > 0 ? ('Выбрано файлов: ' + n) : '';
|
||||
fileCount.textContent = n > 0 ? ('{{ t.media_files_selected }}: ' + n) : '';
|
||||
queue.replaceChildren();
|
||||
Array.from(this.files).forEach(function(file) {
|
||||
var item = document.createElement('div');
|
||||
item.className = 'upload-queue-item';
|
||||
var icon = document.createElement('span');
|
||||
icon.className = 'upload-queue-icon';
|
||||
icon.textContent = file.type.indexOf('video/') === 0 ? '🎬' : '🖼️';
|
||||
var details = document.createElement('div');
|
||||
var name = document.createElement('div');
|
||||
name.className = 'upload-queue-name';
|
||||
name.textContent = file.name;
|
||||
var state = document.createElement('div');
|
||||
state.className = 'upload-queue-state';
|
||||
state.textContent = '0%';
|
||||
var track = document.createElement('div');
|
||||
track.className = 'upload-queue-track';
|
||||
var itemBar = document.createElement('div');
|
||||
itemBar.className = 'upload-queue-bar';
|
||||
track.appendChild(itemBar);
|
||||
details.append(name, state, track);
|
||||
item.append(icon, details);
|
||||
queue.appendChild(item);
|
||||
});
|
||||
});
|
||||
|
||||
function updateQueue(state, progressValue, processing) {
|
||||
queue.querySelectorAll('.upload-queue-item').forEach(function(item) {
|
||||
item.querySelector('.upload-queue-state').textContent = state;
|
||||
var itemBar = item.querySelector('.upload-queue-bar');
|
||||
itemBar.classList.toggle('is-processing', processing);
|
||||
if (!processing) itemBar.style.width = progressValue + '%';
|
||||
});
|
||||
}
|
||||
|
||||
// Submit via XHR for progress tracking
|
||||
form.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
@@ -350,7 +285,9 @@ document.querySelectorAll('.status-btn').forEach(function(btn) {
|
||||
// Show progress bar, disable submit
|
||||
progress.style.display = 'block';
|
||||
submitBtn.disabled = true;
|
||||
submitBtn.textContent = 'Загрузка...';
|
||||
submitBtn.textContent = '{{ t.media_upload_sending }}';
|
||||
statusText.textContent = '{{ t.media_upload_sending }}';
|
||||
bar.classList.remove('is-processing');
|
||||
bar.style.width = '0%';
|
||||
percent.textContent = '0%';
|
||||
|
||||
@@ -359,25 +296,43 @@ document.querySelectorAll('.status-btn').forEach(function(btn) {
|
||||
var pct = Math.round(ev.loaded / ev.total * 100);
|
||||
bar.style.width = pct + '%';
|
||||
percent.textContent = pct + '%';
|
||||
if (pct === 100) statusText.textContent = 'Обработка...';
|
||||
updateQueue(pct + '%', pct, false);
|
||||
if (pct === 100) {
|
||||
statusText.textContent = '{{ t.media_upload_processing }}';
|
||||
percent.textContent = '•••';
|
||||
bar.classList.add('is-processing');
|
||||
updateQueue('{{ t.media_upload_processing }}', 100, true);
|
||||
}
|
||||
});
|
||||
xhr.upload.addEventListener('load', function() {
|
||||
statusText.textContent = '{{ t.media_upload_processing }}';
|
||||
percent.textContent = '•••';
|
||||
bar.classList.add('is-processing');
|
||||
updateQueue('{{ t.media_upload_processing }}', 100, true);
|
||||
});
|
||||
|
||||
xhr.addEventListener('load', function() {
|
||||
if (xhr.status >= 200 && xhr.status < 400) {
|
||||
bar.style.width = '100%';
|
||||
bar.classList.remove('is-processing');
|
||||
percent.textContent = '100%';
|
||||
statusText.textContent = 'Готово!';
|
||||
statusText.textContent = '{{ t.media_upload_done }}';
|
||||
updateQueue('{{ t.media_upload_done }}', 100, false);
|
||||
// Reload page to show uploaded media
|
||||
setTimeout(function() { window.location.reload(); }, 300);
|
||||
} else {
|
||||
bar.classList.remove('is-processing');
|
||||
statusText.textContent = 'Ошибка загрузки (' + xhr.status + ')';
|
||||
updateQueue('Ошибка загрузки', 0, false);
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = '{{ t.media_upload }}';
|
||||
}
|
||||
});
|
||||
|
||||
xhr.addEventListener('error', function() {
|
||||
statusText.textContent = 'Ошибка соединения';
|
||||
bar.classList.remove('is-processing');
|
||||
statusText.textContent = '{{ t.media_upload_connection_error }}';
|
||||
updateQueue('{{ t.media_upload_connection_error }}', 0, false);
|
||||
submitBtn.disabled = false;
|
||||
submitBtn.textContent = '{{ t.media_upload }}';
|
||||
});
|
||||
|
||||
@@ -5,10 +5,15 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="page-head">
|
||||
<h1>{{ t.schedule_new_title }}</h1>
|
||||
<h1>{{ t.schedule_title }}</h1>
|
||||
</div>
|
||||
|
||||
<div class="form-card">
|
||||
<section class="admin-section">
|
||||
<header class="admin-section-head">
|
||||
<span class="admin-section-icon" aria-hidden="true">📅</span>
|
||||
<div><h2>{{ t.schedule_new_title }}</h2></div>
|
||||
</header>
|
||||
<div class="admin-section-body">
|
||||
<form method="post" action="/admin/schedule/create" id="visitForm">
|
||||
|
||||
<!-- Client -->
|
||||
@@ -94,85 +99,7 @@
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
/* Time row */
|
||||
.time-row { display:flex; align-items:center; gap:0.5rem; }
|
||||
.time-block { display:flex; flex-direction:column; flex:1; }
|
||||
.time-lbl { font-size:0.75rem; color:#888; margin-bottom:0.2rem; }
|
||||
.time-sep { font-size:1.2rem; color:#aaa; padding-top:1.2rem; }
|
||||
|
||||
/* Calendar toolbar */
|
||||
.cal-toolbar { display:flex; align-items:center; justify-content:space-between; margin-bottom:0.5rem; }
|
||||
|
||||
|
||||
/* Calendar container */
|
||||
.sched-cal { background:#fafafa; border:1px solid #eee; border-radius:10px; overflow:hidden; }
|
||||
|
||||
.cal-nav { display:flex; align-items:center; justify-content:space-between; padding:0.6rem 0.75rem; background:#fff; border-bottom:1px solid #eee; }
|
||||
.cal-nav button { background:none; border:none; font-size:1.1rem; cursor:pointer; color:#6c63ff; padding:0.2rem 0.5rem; border-radius:4px; }
|
||||
.cal-nav button:hover { background:#f0eeff; }
|
||||
.cal-nav span { font-weight:700; font-size:1rem; color:#333; }
|
||||
|
||||
.cal-grid { display:grid; grid-template-columns:repeat(7,1fr); }
|
||||
|
||||
.cal-wday { text-align:center; font-size:0.72rem; font-weight:700; color:#aaa; padding:0.4rem 0; background:#fafafa; }
|
||||
.cal-wday.is-weekend { color:#f0a0a0; }
|
||||
|
||||
.cal-day { text-align:center; padding:0.55rem 0.2rem; font-size:0.9rem; cursor:pointer; color:#333; border-radius:0; transition:background 0.1s; position:relative; user-select:none; -webkit-user-select:none; }
|
||||
.cal-day:hover { background:#f0eeff; }
|
||||
.cal-day.is-empty { cursor:default; }
|
||||
.cal-day.is-empty:hover { background:none; }
|
||||
.cal-day.is-today { font-weight:700; color:#6c63ff; }
|
||||
.cal-day.is-selected { background:#6c63ff !important; color:#fff !important; border-radius:0; }
|
||||
.cal-day.is-range-start { background:#a89cff !important; color:#fff !important; }
|
||||
.cal-day.is-past { color:#ccc; }
|
||||
|
||||
/* Selected days list */
|
||||
.day-row { display:flex; align-items:center; gap:0.4rem; padding:0.45rem 0; border-bottom:1px solid #f5f5f5; }
|
||||
.day-row:last-child { border-bottom:none; }
|
||||
.day-date { font-weight:600; font-size:0.85rem; flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
||||
.day-times { display:flex; align-items:center; gap:0.25rem; flex-shrink:0; }
|
||||
.day-times .time-sep { color:#bbb; font-size:0.8rem; }
|
||||
.day-rm { background:none; border:none; color:#ccc; cursor:pointer; font-size:1rem; padding:0.15rem 0.25rem; flex-shrink:0; line-height:1; }
|
||||
.day-rm:hover { color:#e55; }
|
||||
|
||||
/* Time badge */
|
||||
.time-badge-wrap {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #ede9ff;
|
||||
color: #5b52d6;
|
||||
border: 1.5px solid #c4beff;
|
||||
border-radius: 20px;
|
||||
padding: 0.15rem 0.5rem;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
min-width: 3.6rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.time-badge-wrap:focus-within {
|
||||
border-color: #6c63ff;
|
||||
background: #f0eeff;
|
||||
}
|
||||
.time-badge-label { pointer-events: none; z-index: 1; }
|
||||
.time-badge-input {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
opacity: 0;
|
||||
cursor: pointer;
|
||||
border: none;
|
||||
background: transparent;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
font-size: 16px; /* prevent iOS zoom */
|
||||
}
|
||||
</style>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
|
||||
+308
-134
@@ -5,168 +5,342 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="page-head">
|
||||
<h1>{{ t.settings_title }}</h1>
|
||||
<div>
|
||||
<h1>{{ t.settings_title }}</h1>
|
||||
<p>{{ t.settings_intro }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if saved %}
|
||||
<div class="notification is-success is-light">{{ t.settings_saved }}</div>
|
||||
<div class="notification is-success is-light admin-message">{{ t.settings_saved }}</div>
|
||||
{% endif %}
|
||||
{% if let Some(message) = error %}
|
||||
<div class="notification is-danger is-light admin-message">{{ message }}</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="form-card">
|
||||
<form method="post" action="/admin/settings/save">
|
||||
|
||||
<h2 class="subtitle is-5 mb-3" style="border-bottom:1px solid #eee;padding-bottom:0.5rem;">{{ t.settings_contact_info }}</h2>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.settings_contact_info }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="contact_info" placeholder="+7 999 123-45-67 / info@example.com" value="{% for s in &settings %}{% if s.key == "contact_info" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
<form id="settingsForm" class="admin-form" method="post" action="/admin/settings/save">
|
||||
<section class="admin-section">
|
||||
<header class="admin-section-head">
|
||||
<span class="admin-section-icon" aria-hidden="true">🌐</span>
|
||||
<div>
|
||||
<h2>{{ t.settings_section_general }}</h2>
|
||||
<p>{{ t.settings_section_general_help }}</p>
|
||||
</div>
|
||||
</header>
|
||||
<div class="admin-section-body">
|
||||
<div class="admin-grid">
|
||||
<div class="field admin-field admin-field-wide">
|
||||
<label class="label" for="contactInfo">{{ t.settings_contact_info }}</label>
|
||||
<div class="control">
|
||||
<input id="contactInfo" class="input" type="text" name="contact_info" placeholder="+7 999 123-45-67 / info@example.com" value="{% for s in &settings %}{% if s.key == "contact_info" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field admin-field">
|
||||
<label class="label" for="siteDomain">{{ t.settings_site_domain }}</label>
|
||||
<div class="control">
|
||||
<input id="siteDomain" class="input" type="url" name="site_domain" placeholder="https://example.com" value="{% for s in &settings %}{% if s.key == "site_domain" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field admin-field">
|
||||
<label class="label" for="timezone">{{ t.settings_timezone }}</label>
|
||||
<div class="control">
|
||||
<input id="timezone" class="input" type="text" name="timezone" placeholder="Asia/Vladivostok" value="{% for s in &settings %}{% if s.key == "timezone" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field admin-field admin-field-wide">
|
||||
<label class="label" for="pricingInfo">{{ t.settings_pricing_info }}</label>
|
||||
<div class="control">
|
||||
<textarea id="pricingInfo" class="textarea" name="pricing_info" rows="3" placeholder="от 600 рублей за визит">{% for s in &settings %}{% if s.key == "pricing_info" %}{{ s.value }}{% endif %}{% endfor %}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field admin-field admin-field-wide">
|
||||
<label class="label" for="seoKeywordsInput">{{ t.settings_seo_keywords }}</label>
|
||||
<div class="control">
|
||||
<textarea id="seoKeywordsInput" class="textarea" name="seo_keywords" rows="3" placeholder="зооняня Хабаровск, присмотр за питомцем Хабаровск, догситтер Хабаровск">{% for s in &settings %}{% if s.key == "seo_keywords" %}{{ s.value }}{% endif %}{% endfor %}</textarea>
|
||||
</div>
|
||||
<div id="seoPreview" class="seo-preview" hidden></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.settings_pricing_info }}</label>
|
||||
<div class="control">
|
||||
<textarea class="input" name="pricing_info" rows="3" style="min-height:70px;resize:vertical;" placeholder="от 600 рублей за визит">{% for s in &settings %}{% if s.key == "pricing_info" %}{{ s.value }}{% endif %}{% endfor %}</textarea>
|
||||
</section>
|
||||
|
||||
<section class="admin-section">
|
||||
<header class="admin-section-head">
|
||||
<span class="admin-section-icon" aria-hidden="true">☁️</span>
|
||||
<div>
|
||||
<div class="admin-title-row">
|
||||
<h2>{{ t.settings_section_storage }}</h2>
|
||||
<span class="status-pill{% if r2_enabled_checked %} is-enabled{% endif %}">
|
||||
{% if r2_enabled_checked %}{{ t.settings_status_enabled }}{% else %}{{ t.settings_status_disabled }}{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
<p>{{ t.settings_r2_help }}</p>
|
||||
</div>
|
||||
</header>
|
||||
<div class="admin-section-body">
|
||||
<label class="admin-toggle" for="r2Enabled">
|
||||
<input id="r2Enabled" type="checkbox" name="r2_enabled" value="true"{% if r2_enabled_checked %} checked{% endif %}>
|
||||
<span class="admin-toggle-track" aria-hidden="true"><span></span></span>
|
||||
<span>
|
||||
<strong>{{ t.settings_r2_enabled }}</strong>
|
||||
<small>{{ t.settings_r2_help }}</small>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div class="admin-note admin-note-info">{{ t.settings_r2_migration_help }}</div>
|
||||
|
||||
<div class="admin-grid">
|
||||
<div class="field admin-field">
|
||||
<label class="label" for="r2AccountId">{{ t.settings_r2_account_id }}</label>
|
||||
<div class="control">
|
||||
<input id="r2AccountId" class="input is-family-monospace" type="text" name="r2_account_id" maxlength="32" autocomplete="off" spellcheck="false" placeholder="0123456789abcdef0123456789abcdef" value="{% for s in &settings %}{% if s.key == "r2_account_id" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field admin-field">
|
||||
<label class="label" for="r2Bucket">{{ t.settings_r2_bucket }}</label>
|
||||
<div class="control">
|
||||
<input id="r2Bucket" class="input is-family-monospace" type="text" name="r2_bucket" autocomplete="off" spellcheck="false" placeholder="pet-media" value="{% for s in &settings %}{% if s.key == "r2_bucket" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field admin-field">
|
||||
<label class="label" for="r2AccessKey">{{ t.settings_r2_access_key_id }}</label>
|
||||
<div class="control">
|
||||
<input id="r2AccessKey" class="input is-family-monospace" type="text" name="r2_access_key_id" autocomplete="off" spellcheck="false" value="{% for s in &settings %}{% if s.key == "r2_access_key_id" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field admin-field">
|
||||
<label class="label" for="r2Secret">{{ t.settings_r2_secret_access_key }}</label>
|
||||
<div class="control secret-control">
|
||||
<input id="r2Secret" class="input is-family-monospace" type="password" name="r2_secret_access_key" autocomplete="new-password" placeholder="••••••••••••••••">
|
||||
</div>
|
||||
<p class="field-help">{% if r2_secret_configured %}{{ t.settings_secret_saved }}{% else %}{{ t.settings_secret_not_set }}{% endif %}</p>
|
||||
{% if r2_secret_configured %}
|
||||
<label class="admin-check admin-check-danger"><input type="checkbox" name="clear_r2_secret_access_key" value="true"><span class="admin-check-box">✓</span><span>{{ t.settings_secret_clear }}</span></label>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.settings_seo_keywords }}</label>
|
||||
<div class="control">
|
||||
<textarea id="seoKeywordsInput" class="textarea" name="seo_keywords" rows="3"
|
||||
style="resize:vertical;"
|
||||
placeholder="зооняня Хабаровск, присмотр за питомцем Хабаровск, догситтер Хабаровск">{% for s in &settings %}{% if s.key == "seo_keywords" %}{{ s.value }}{% endif %}{% endfor %}</textarea>
|
||||
</section>
|
||||
|
||||
<section class="admin-section">
|
||||
<header class="admin-section-head">
|
||||
<span class="admin-section-icon" aria-hidden="true">🔔</span>
|
||||
<div>
|
||||
<div class="admin-title-row">
|
||||
<h2>{{ t.settings_section_notifications }}</h2>
|
||||
<span class="status-pill{% if client_notifications_checked %} is-enabled{% endif %}">
|
||||
{% if client_notifications_checked %}{{ t.settings_status_enabled }}{% else %}{{ t.settings_status_disabled }}{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
<p>{{ t.settings_section_notifications_help }}</p>
|
||||
</div>
|
||||
</header>
|
||||
<div class="admin-section-body">
|
||||
<label class="admin-toggle" for="clientNotifications">
|
||||
<input id="clientNotifications" type="checkbox" name="client_notifications_enabled" value="true"{% if client_notifications_checked %} checked{% endif %}>
|
||||
<span class="admin-toggle-track" aria-hidden="true"><span></span></span>
|
||||
<span>
|
||||
<strong>{{ t.settings_client_notifications_enabled }}</strong>
|
||||
<small>{{ t.settings_client_notifications_help }}</small>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div class="admin-subsection">
|
||||
<h3>Web Push / VAPID</h3>
|
||||
<div class="admin-note admin-note-warning">
|
||||
<p>{{ t.settings_vapid_warning }}</p>
|
||||
<p>{{ t.settings_vapid_generate }} <code>cargo run --bin generate_vapid</code></p>
|
||||
</div>
|
||||
<div class="admin-grid">
|
||||
<div class="field admin-field admin-field-wide">
|
||||
<label class="label" for="vapidPublic">{{ t.settings_vapid_public_key }}</label>
|
||||
<div class="control">
|
||||
<input id="vapidPublic" class="input is-family-monospace" type="text" name="vapid_public_key" autocomplete="off" spellcheck="false" value="{% for s in &settings %}{% if s.key == "vapid_public_key" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field admin-field admin-field-wide">
|
||||
<label class="label" for="vapidPrivate">{{ t.settings_vapid_private_key }}</label>
|
||||
<div class="control secret-control">
|
||||
<input id="vapidPrivate" class="input is-family-monospace" type="password" name="vapid_private_key" autocomplete="new-password" placeholder="••••••••••••••••">
|
||||
</div>
|
||||
<p class="field-help">{% if vapid_private_key_configured %}{{ t.settings_secret_saved }}{% else %}{{ t.settings_secret_not_set }}{% endif %}</p>
|
||||
{% if vapid_private_key_configured %}
|
||||
<label class="admin-check admin-check-danger"><input type="checkbox" name="clear_vapid_private_key" value="true"><span class="admin-check-box">✓</span><span>{{ t.settings_secret_clear }}</span></label>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="field admin-field admin-field-wide">
|
||||
<label class="label" for="vapidSubject">{{ t.settings_vapid_subject }}</label>
|
||||
<div class="control">
|
||||
<input id="vapidSubject" class="input" type="text" name="vapid_subject" placeholder="mailto:admin@example.com" value="{% for s in &settings %}{% if s.key == "vapid_subject" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<details class="admin-details">
|
||||
<summary>{{ t.settings_push_subscribers }} <span>{{ push_subscribers.len() }}</span></summary>
|
||||
<div class="admin-details-body">
|
||||
{% if push_subscribers.is_empty() %}
|
||||
<p class="field-help">{{ t.settings_push_no_subscribers }}</p>
|
||||
{% else %}
|
||||
<div class="table-wrap">
|
||||
<table class="table is-fullwidth is-striped is-narrow">
|
||||
<thead><tr>
|
||||
<th>{{ t.settings_push_client }}</th>
|
||||
<th>{{ t.settings_push_devices }}</th>
|
||||
<th>{{ t.settings_push_language }}</th>
|
||||
<th>{{ t.settings_push_updated }}</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
{% for subscriber in &push_subscribers %}
|
||||
<tr>
|
||||
<td>{{ subscriber.client_name }}</td>
|
||||
<td>{{ subscriber.device_count }}</td>
|
||||
<td>{{ subscriber.languages }}</td>
|
||||
<td class="is-nowrap">{{ subscriber.last_updated }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<div class="admin-subsection">
|
||||
<h3>Telegram</h3>
|
||||
<div class="field admin-field admin-field-wide">
|
||||
<label class="label" for="telegramToken">{{ t.settings_telegram_bot_token }}</label>
|
||||
<div class="control secret-control">
|
||||
<input id="telegramToken" class="input is-family-monospace" type="password" name="telegram_bot_token" autocomplete="new-password" placeholder="••••••••••••••••">
|
||||
</div>
|
||||
<p class="field-help">{% if telegram_bot_token_configured %}{{ t.settings_secret_saved }}{% else %}{{ t.settings_secret_not_set }}{% endif %}</p>
|
||||
{% if telegram_bot_token_configured %}
|
||||
<label class="admin-check admin-check-danger"><input type="checkbox" name="clear_telegram_bot_token" value="true"><span class="admin-check-box">✓</span><span>{{ t.settings_secret_clear }}</span></label>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div id="seoPreview" style="margin-top:0.5rem;padding:0.5rem 0.75rem;background:#fafafa;border:1px solid #eee;border-radius:6px;min-height:2rem;line-height:2;font-size:0.85rem;display:none;"></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<details style="margin-top:1.5rem;">
|
||||
<summary class="subtitle is-5 mb-3" style="cursor:pointer;border-bottom:1px solid #eee;padding-bottom:0.5rem;">
|
||||
{{ t.settings_section_advanced }}
|
||||
</summary>
|
||||
|
||||
<div style="margin-top:1rem;">
|
||||
<h3 class="subtitle is-6 mb-2 has-text-grey">{{ t.settings_section_general }}</h3>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.settings_site_domain }}</label>
|
||||
<section class="admin-section">
|
||||
<header class="admin-section-head">
|
||||
<span class="admin-section-icon" aria-hidden="true">🛡️</span>
|
||||
<div>
|
||||
<h2>{{ t.settings_section_captcha }}</h2>
|
||||
<p>{{ t.settings_section_captcha_help }}</p>
|
||||
</div>
|
||||
</header>
|
||||
<div class="admin-section-body">
|
||||
<div class="admin-grid">
|
||||
<div class="field admin-field">
|
||||
<label class="label" for="turnstileSiteKey">{{ t.settings_turnstile_site_key }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="site_domain" placeholder="https://example.com" value="{% for s in &settings %}{% if s.key == "site_domain" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
<input id="turnstileSiteKey" class="input is-family-monospace" type="text" name="turnstile_site_key" autocomplete="off" spellcheck="false" value="{% for s in &settings %}{% if s.key == "turnstile_site_key" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.settings_timezone }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="timezone" placeholder="Asia/Vladivostok" value="{% for s in &settings %}{% if s.key == "timezone" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
<div class="field admin-field">
|
||||
<label class="label" for="turnstileSecret">{{ t.settings_turnstile_secret_key }}</label>
|
||||
<div class="control secret-control">
|
||||
<input id="turnstileSecret" class="input is-family-monospace" type="password" name="turnstile_secret_key" autocomplete="new-password" placeholder="••••••••••••••••">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 class="subtitle is-6 mb-2 has-text-grey" style="margin-top:1.25rem;">{{ t.settings_section_notifications }}</h3>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.settings_telegram_bot_token }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="telegram_bot_token" value="{% for s in &settings %}{% if s.key == "telegram_bot_token" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 class="subtitle is-6 mb-2 has-text-grey" style="margin-top:1.25rem;">{{ t.settings_section_captcha }}</h3>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.settings_turnstile_site_key }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="turnstile_site_key" value="{% for s in &settings %}{% if s.key == "turnstile_site_key" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.settings_turnstile_secret_key }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="turnstile_secret_key" value="{% for s in &settings %}{% if s.key == "turnstile_secret_key" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 class="subtitle is-6 mb-2 has-text-grey" style="margin-top:1.25rem;">{{ t.settings_section_oidc }}</h3>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.settings_oidc_issuer_url }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="oidc_issuer_url" placeholder="https://keycloak.example.com/realms/myrealm" value="{% for s in &settings %}{% if s.key == "oidc_issuer_url" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.settings_oidc_client_id }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="oidc_client_id" value="{% for s in &settings %}{% if s.key == "oidc_client_id" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.settings_oidc_client_secret }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="password" name="oidc_client_secret" value="{% for s in &settings %}{% if s.key == "oidc_client_secret" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">{{ t.settings_oidc_allowed_groups }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="oidc_allowed_groups" placeholder="admins, web-petting" value="{% for s in &settings %}{% if s.key == "oidc_allowed_groups" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" name="auth_password_enabled" value="true"{% if auth_password_checked %} checked{% endif %}>
|
||||
{{ t.settings_auth_password_enabled }}
|
||||
</label>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" name="auth_sso_enabled" value="true"{% if auth_sso_checked %} checked{% endif %}>
|
||||
{{ t.settings_auth_sso_enabled }}
|
||||
</label>
|
||||
<p class="field-help">{% if turnstile_secret_configured %}{{ t.settings_secret_saved }}{% else %}{{ t.settings_secret_not_set }}{% endif %}</p>
|
||||
{% if turnstile_secret_configured %}
|
||||
<label class="admin-check admin-check-danger"><input type="checkbox" name="clear_turnstile_secret_key" value="true"><span class="admin-check-box">✓</span><span>{{ t.settings_secret_clear }}</span></label>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<button type="submit" class="button is-primary" style="margin-top:1.5rem;">{{ t.settings_save }}</button>
|
||||
</form>
|
||||
</div>
|
||||
<section class="admin-section">
|
||||
<header class="admin-section-head">
|
||||
<span class="admin-section-icon" aria-hidden="true">🔐</span>
|
||||
<div>
|
||||
<h2>{{ t.settings_section_oidc }}</h2>
|
||||
<p>{{ t.settings_section_oidc_help }}</p>
|
||||
</div>
|
||||
</header>
|
||||
<div class="admin-section-body">
|
||||
<div class="admin-toggle-list">
|
||||
<label class="admin-toggle" for="passwordAuth">
|
||||
<input id="passwordAuth" type="checkbox" name="auth_password_enabled" value="true"{% if auth_password_checked %} checked{% endif %}>
|
||||
<span class="admin-toggle-track" aria-hidden="true"><span></span></span>
|
||||
<span><strong>{{ t.settings_auth_password_enabled }}</strong></span>
|
||||
</label>
|
||||
<label class="admin-toggle" for="ssoAuth">
|
||||
<input id="ssoAuth" type="checkbox" name="auth_sso_enabled" value="true"{% if auth_sso_checked %} checked{% endif %}>
|
||||
<span class="admin-toggle-track" aria-hidden="true"><span></span></span>
|
||||
<span><strong>{{ t.settings_auth_sso_enabled }}</strong></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="admin-grid">
|
||||
<div class="field admin-field admin-field-wide">
|
||||
<label class="label" for="oidcIssuer">{{ t.settings_oidc_issuer_url }}</label>
|
||||
<div class="control">
|
||||
<input id="oidcIssuer" class="input" type="url" name="oidc_issuer_url" placeholder="https://keycloak.example.com/realms/myrealm" value="{% for s in &settings %}{% if s.key == "oidc_issuer_url" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field admin-field">
|
||||
<label class="label" for="oidcClientId">{{ t.settings_oidc_client_id }}</label>
|
||||
<div class="control">
|
||||
<input id="oidcClientId" class="input is-family-monospace" type="text" name="oidc_client_id" autocomplete="off" spellcheck="false" value="{% for s in &settings %}{% if s.key == "oidc_client_id" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field admin-field">
|
||||
<label class="label" for="oidcClientSecret">{{ t.settings_oidc_client_secret }}</label>
|
||||
<div class="control secret-control">
|
||||
<input id="oidcClientSecret" class="input is-family-monospace" type="password" name="oidc_client_secret" autocomplete="new-password" placeholder="••••••••••••••••">
|
||||
</div>
|
||||
<p class="field-help">{% if oidc_client_secret_configured %}{{ t.settings_secret_saved }}{% else %}{{ t.settings_secret_not_set }}{% endif %}</p>
|
||||
{% if oidc_client_secret_configured %}
|
||||
<label class="admin-check admin-check-danger"><input type="checkbox" name="clear_oidc_client_secret" value="true"><span class="admin-check-box">✓</span><span>{{ t.settings_secret_clear }}</span></label>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="field admin-field admin-field-wide">
|
||||
<label class="label" for="oidcGroups">{{ t.settings_oidc_allowed_groups }}</label>
|
||||
<div class="control">
|
||||
<input id="oidcGroups" class="input" type="text" name="oidc_allowed_groups" placeholder="admins, web-petting" value="{% for s in &settings %}{% if s.key == "oidc_allowed_groups" %}{{ s.value }}{% endif %}{% endfor %}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="sticky-actions">
|
||||
<button type="submit" class="button is-primary">{{ t.settings_save }}</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
var COLORS = [
|
||||
'rgba(124,108,255,0.18)',
|
||||
'rgba(255,82,135,0.15)',
|
||||
'rgba(255,140,38,0.18)',
|
||||
'rgba(0,180,150,0.15)',
|
||||
'rgba(77,166,255,0.18)',
|
||||
'rgba(255,179,64,0.18)',
|
||||
'rgba(176,108,255,0.16)',
|
||||
'rgba(34,180,130,0.16)',
|
||||
var colors = [
|
||||
'rgba(124,108,255,.18)', 'rgba(255,82,135,.15)',
|
||||
'rgba(255,140,38,.18)', 'rgba(0,180,150,.15)',
|
||||
'rgba(77,166,255,.18)', 'rgba(255,179,64,.18)',
|
||||
'rgba(176,108,255,.16)', 'rgba(34,180,130,.16)'
|
||||
];
|
||||
|
||||
var ta = document.getElementById('seoKeywordsInput');
|
||||
var input = document.getElementById('seoKeywordsInput');
|
||||
var preview = document.getElementById('seoPreview');
|
||||
|
||||
function esc(s) {
|
||||
return s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
||||
}
|
||||
|
||||
function render() {
|
||||
var text = ta.value.trim();
|
||||
if (!text) { preview.style.display = 'none'; return; }
|
||||
|
||||
var parts = text.split(',');
|
||||
var html = '';
|
||||
parts.forEach(function(part, i) {
|
||||
var word = part.trim();
|
||||
if (word) {
|
||||
var color = COLORS[i % COLORS.length];
|
||||
html += '<span style="background:' + color + ';border-radius:4px;padding:2px 6px;margin:2px;">' + esc(word) + '</span>';
|
||||
}
|
||||
if (i < parts.length - 1) {
|
||||
html += '<span style="color:#ccc;font-size:0.8em;margin:0 1px">,</span>';
|
||||
}
|
||||
function renderSeoPreview() {
|
||||
var words = input.value.split(',').map(function(value) { return value.trim(); }).filter(Boolean);
|
||||
preview.replaceChildren();
|
||||
preview.hidden = words.length === 0;
|
||||
words.forEach(function(word, index) {
|
||||
var tag = document.createElement('span');
|
||||
tag.textContent = word;
|
||||
tag.style.background = colors[index % colors.length];
|
||||
tag.style.borderRadius = '4px';
|
||||
tag.style.padding = '2px 6px';
|
||||
tag.style.margin = '2px';
|
||||
preview.appendChild(tag);
|
||||
});
|
||||
|
||||
preview.innerHTML = html;
|
||||
preview.style.display = 'block';
|
||||
}
|
||||
|
||||
ta.addEventListener('input', render);
|
||||
render();
|
||||
input.addEventListener('input', renderSeoPreview);
|
||||
renderSeoPreview();
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
@@ -6,28 +6,18 @@
|
||||
<title>{{ t.nav_title }} — {{ t.setup_title }}</title>
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1/css/bulma.min.css">
|
||||
<style>
|
||||
:root { color-scheme: light; }
|
||||
body { background: #f5f5f5; display: flex; align-items: center; justify-content: center; min-height: 100vh; color: #333; }
|
||||
.login-box { width: 100%; max-width: 400px; padding: 0 1rem; }
|
||||
.login-card { background: #fff; border-radius: 12px; padding: 2rem 1.5rem; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
|
||||
input, textarea, select, .input, .textarea, .select select {
|
||||
background-color: #fff !important; color: #333 !important; border-color: #dbdbdb !important;
|
||||
}
|
||||
.label, label { color: #363636 !important; }
|
||||
.notification { color: #333 !important; }
|
||||
</style>
|
||||
<link rel="stylesheet" href="/static/admin.css?v={{ t.app_version() }}">
|
||||
</head>
|
||||
<body>
|
||||
<body class="auth-shell">
|
||||
<div class="login-box">
|
||||
<div class="has-text-right mb-3">
|
||||
<a href="?lang={{ lang.other().code() }}" class="has-text-grey is-size-7">{{ lang.other().label() }}</a>
|
||||
<div class="auth-language">
|
||||
<a href="?lang={{ lang.other().code() }}">{{ lang.other().label() }}</a>
|
||||
</div>
|
||||
<div class="login-card">
|
||||
<div class="has-text-centered mb-4">
|
||||
<p class="is-size-3">🐾</p>
|
||||
<h1 class="is-size-4 has-text-weight-bold">{{ t.nav_title }}</h1>
|
||||
<p class="has-text-grey">{{ t.setup_title }}</p>
|
||||
<div class="auth-head">
|
||||
<span class="auth-icon">🐾</span>
|
||||
<h1>{{ t.nav_title }}</h1>
|
||||
<p>{{ t.setup_title }}</p>
|
||||
</div>
|
||||
<p class="has-text-grey has-text-centered is-size-7 mb-4">{{ t.setup_description }}</p>
|
||||
{% if let Some(err) = error.as_ref() %}
|
||||
|
||||
@@ -9,13 +9,17 @@
|
||||
</div>
|
||||
|
||||
<!-- Add form -->
|
||||
<div class="form-card" style="margin-bottom:1.5rem;">
|
||||
<h2 style="font-size:1.1rem;font-weight:700;margin-bottom:0.75rem;">{{ t.testimonials_add_title }}</h2>
|
||||
<form method="post" action="/admin/testimonials/add" enctype="multipart/form-data">
|
||||
<div class="field">
|
||||
<section class="admin-section mb-5">
|
||||
<header class="admin-section-head">
|
||||
<span class="admin-section-icon" aria-hidden="true">💬</span>
|
||||
<div><h2>{{ t.testimonials_add_title }}</h2></div>
|
||||
</header>
|
||||
<div class="admin-section-body">
|
||||
<form method="post" action="/admin/testimonials/add" enctype="multipart/form-data" class="form-grid">
|
||||
<div class="field admin-field-wide">
|
||||
<label class="label">{{ t.testimonials_text }} *</label>
|
||||
<div class="control">
|
||||
<textarea class="input" name="text" rows="3" required style="min-height:80px;resize:vertical;"></textarea>
|
||||
<textarea class="textarea" name="text" rows="3" required></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
@@ -30,27 +34,28 @@
|
||||
<input class="input" type="file" name="image" accept="image/*">
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="button is-primary">{{ t.testimonials_add_button }}</button>
|
||||
<div class="admin-field-wide"><button type="submit" class="button is-primary">{{ t.testimonials_add_button }}</button></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- List -->
|
||||
{% if testimonials.is_empty() %}
|
||||
<p style="color:#888;">{{ t.testimonials_empty }}</p>
|
||||
<p class="empty-state">{{ t.testimonials_empty }}</p>
|
||||
{% else %}
|
||||
{% for item in &testimonials %}
|
||||
<div class="item-card" id="card-{{ item.id.unwrap() }}">
|
||||
<!-- View mode -->
|
||||
<div class="tm-view" id="view-{{ item.id.unwrap() }}">
|
||||
<div class="item-card-header">
|
||||
<div style="display:flex;align-items:center;gap:0.75rem;">
|
||||
{% if item.image_path.is_some() %}
|
||||
<img src="/admin/testimonials/{{ item.id.unwrap() }}/image" alt="" style="width:48px;height:48px;border-radius:50%;object-fit:cover;">
|
||||
<div class="testimonial-content">
|
||||
{% if let Some(image_url) = item.image_url.as_deref() %}
|
||||
<img src="{{ image_url }}" alt="" class="testimonial-avatar">
|
||||
{% endif %}
|
||||
<div>
|
||||
<div style="font-size:0.95rem;line-height:1.5;">{{ item.text }}</div>
|
||||
<div class="testimonial-text">{{ item.text }}</div>
|
||||
{% if let Some(note) = item.author_note.as_deref() %}
|
||||
<div style="font-size:0.8rem;color:#888;margin-top:0.2rem;">{{ note }}</div>
|
||||
<div class="testimonial-note">{{ note }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@@ -79,7 +84,7 @@
|
||||
<div class="field">
|
||||
<label class="label">{{ t.testimonials_text }}</label>
|
||||
<div class="control">
|
||||
<textarea class="input" name="text" rows="3" style="min-height:70px;resize:vertical;">{{ item.text }}</textarea>
|
||||
<textarea class="textarea" name="text" rows="3">{{ item.text }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
@@ -90,10 +95,12 @@
|
||||
</div>
|
||||
{% if item.image_path.is_some() %}
|
||||
<div class="field">
|
||||
<div style="display:flex;align-items:center;gap:0.75rem;margin-bottom:0.5rem;">
|
||||
<img src="/admin/testimonials/{{ item.id.unwrap() }}/image" alt="" style="width:48px;height:48px;border-radius:50%;object-fit:cover;">
|
||||
<label style="font-size:0.85rem;cursor:pointer;color:#888;">
|
||||
<input type="checkbox" name="remove_image" value="1"> {{ t.testimonials_remove_image }}
|
||||
<div class="testimonial-content mb-2">
|
||||
{% if let Some(image_url) = item.image_url.as_deref() %}<img src="{{ image_url }}" alt="" class="testimonial-avatar">{% endif %}
|
||||
<label class="admin-check admin-check-danger">
|
||||
<input type="checkbox" name="remove_image" value="1">
|
||||
<span class="admin-check-box">✓</span>
|
||||
<span>{{ t.testimonials_remove_image }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -104,7 +111,7 @@
|
||||
<input class="input" type="file" name="image" accept="image/*">
|
||||
</div>
|
||||
</div>
|
||||
<div style="display:flex;gap:0.5rem;">
|
||||
<div class="action-row">
|
||||
<button type="submit" class="button btn-sm is-primary">{{ t.testimonials_save }}</button>
|
||||
<button type="button" class="button btn-sm is-light" onclick="toggleEdit({{ item.id.unwrap() }})">✕</button>
|
||||
</div>
|
||||
|
||||
+38
-44
@@ -11,30 +11,29 @@
|
||||
{% for user in &users %}
|
||||
<div class="item-card">
|
||||
<div class="item-card-header">
|
||||
<span class="name">{{ user.login }}{% if let Some(dn) = user.display_name.as_deref() %} <span style="font-weight:400;color:#888;">— {{ dn }}</span>{% endif %}</span>
|
||||
<span class="name">{{ user.login }}{% if let Some(dn) = user.display_name.as_deref() %} <span class="muted-detail">— {{ dn }}</span>{% endif %}</span>
|
||||
<span class="badge badge-{{ user.status }}">{{ t.client_status(&user.status) }}</span>
|
||||
</div>
|
||||
<div class="item-card-meta">
|
||||
<span>🕐 {{ user.created_at.format("%d.%m.%Y %H:%M") }}</span>
|
||||
</div>
|
||||
{% if user.status == "active" %}
|
||||
<form method="post" action="/admin/users/{{ user.id }}/telegram" style="margin-top:0.5rem; padding-top:0.5rem; border-top:1px solid #eee;">
|
||||
<div class="columns is-mobile is-vcentered" style="margin-bottom:0;">
|
||||
<div class="column">
|
||||
<div class="field" style="margin-bottom:0;">
|
||||
<label class="label is-small">{{ t.users_telegram_chat_id }}</label>
|
||||
<div class="control">
|
||||
<input class="input is-small" type="text" name="telegram_chat_id" placeholder="123456789" value="{{ user.telegram_chat_id.as_deref().unwrap_or_default() }}">
|
||||
</div>
|
||||
<form method="post" action="/admin/users/{{ user.id }}/telegram" class="inline-admin-form">
|
||||
<div class="inline-admin-grid">
|
||||
<div class="field">
|
||||
<label class="label is-small">{{ t.users_telegram_chat_id }}</label>
|
||||
<div class="control">
|
||||
<input class="input is-small" type="text" name="telegram_chat_id" placeholder="123456789" value="{{ user.telegram_chat_id.as_deref().unwrap_or_default() }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="column is-narrow">
|
||||
<label class="checkbox is-small">
|
||||
<div>
|
||||
<label class="admin-toggle admin-toggle-compact">
|
||||
<input type="checkbox" name="telegram_notifications" value="true" {% if user.telegram_notifications == Some(true) %}checked{% endif %}>
|
||||
{{ t.users_telegram_enabled }}
|
||||
<span class="admin-toggle-track" aria-hidden="true"><span></span></span>
|
||||
<span><strong>{{ t.users_telegram_enabled }}</strong></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="column is-narrow">
|
||||
<div>
|
||||
<button type="submit" class="button is-small is-info is-outlined">💾</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -54,41 +53,36 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<div class="form-card" style="margin-top:1.5rem;">
|
||||
<h2 class="is-size-5 has-text-weight-bold mb-3">{{ t.users_add_title }}</h2>
|
||||
<section class="admin-section mt-5">
|
||||
<header class="admin-section-head">
|
||||
<span class="admin-section-icon" aria-hidden="true">➕</span>
|
||||
<div><h2>{{ t.users_add_title }}</h2></div>
|
||||
</header>
|
||||
<div class="admin-section-body">
|
||||
{% if let Some(err) = error.as_ref() %}
|
||||
<div class="notification is-danger is-light">{{ err }}</div>
|
||||
{% endif %}
|
||||
<form method="post" action="/admin/users/add">
|
||||
<div class="columns is-mobile">
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label class="label is-small">{{ t.users_login }}</label>
|
||||
<div class="control"><input class="input" type="text" name="login" required></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label class="label is-small">{{ t.users_display_name }}</label>
|
||||
<div class="control"><input class="input" type="text" name="display_name"></div>
|
||||
</div>
|
||||
</div>
|
||||
<form method="post" action="/admin/users/add" class="form-grid">
|
||||
<div class="field">
|
||||
<label class="label is-small">{{ t.users_login }}</label>
|
||||
<div class="control"><input class="input" type="text" name="login" required></div>
|
||||
</div>
|
||||
<div class="columns is-mobile">
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label class="label is-small">{{ t.users_password }}</label>
|
||||
<div class="control"><input class="input" type="password" name="password" required minlength="4"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="field">
|
||||
<label class="label is-small">{{ t.users_password_confirm }}</label>
|
||||
<div class="control"><input class="input" type="password" name="password_confirm" required minlength="4"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label is-small">{{ t.users_display_name }}</label>
|
||||
<div class="control"><input class="input" type="text" name="display_name"></div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label is-small">{{ t.users_password }}</label>
|
||||
<div class="control"><input class="input" type="password" name="password" required minlength="4"></div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label is-small">{{ t.users_password_confirm }}</label>
|
||||
<div class="control"><input class="input" type="password" name="password_confirm" required minlength="4"></div>
|
||||
</div>
|
||||
<div class="admin-field-wide">
|
||||
<button type="submit" class="button is-primary">{{ t.users_add_button }}</button>
|
||||
</div>
|
||||
<button type="submit" class="button is-primary">{{ t.users_add_button }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ t.portal_title }} — {{ client.name }}</title>
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
||||
<link rel="manifest" href="/client/{{ client.media_token }}/manifest.webmanifest">
|
||||
<meta name="theme-color" content="#7c6cff">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
{% if !turnstile_site_key.is_empty() %}
|
||||
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
|
||||
{% endif %}
|
||||
@@ -17,12 +20,15 @@
|
||||
padding: 0 0 2rem;
|
||||
}
|
||||
.portal-header {
|
||||
position: relative;
|
||||
background: linear-gradient(135deg, #7c6cff, #b06cff);
|
||||
color: #fff; padding: 2rem 1.5rem 1.5rem; text-align: center;
|
||||
}
|
||||
.portal-header h1 { font-size: 1.5rem; font-weight: 700; }
|
||||
.portal-header .sub { opacity: 0.85; font-size: 0.9rem; margin-top: 0.25rem; }
|
||||
.container { max-width: 700px; margin: 0 auto; padding: 0 1rem; }
|
||||
.container { max-width: 1100px; margin: 0 auto; padding: 0 1rem; }
|
||||
.portal-grid { display: grid; grid-template-columns: minmax(0, 700px) 320px; gap: 1.25rem; align-items: start; }
|
||||
.portal-settings { position: absolute; right: 1rem; bottom: 1rem; width: 38px; height: 38px; border: 0; border-radius: 50%; background: rgba(255,255,255,.2); color: #fff; font-size: 1.1rem; cursor: pointer; }
|
||||
.section-title {
|
||||
font-size: 1.15rem; font-weight: 700; margin: 1.5rem 0 0.75rem;
|
||||
padding-bottom: 0.4rem; border-bottom: 2px solid #ede7f6;
|
||||
@@ -51,6 +57,9 @@
|
||||
.media-row img {
|
||||
width: 80px; height: 60px; object-fit: cover; border-radius: 6px;
|
||||
}
|
||||
.media-row .media-thumb-frame {
|
||||
width: 80px; height: 60px; border-radius: 6px;
|
||||
}
|
||||
.media-row .vid-thumb {
|
||||
position: relative; width: 80px; height: 60px; border-radius: 6px;
|
||||
overflow: hidden; background: #111;
|
||||
@@ -110,6 +119,33 @@
|
||||
font-weight: 700; min-width: 5.5rem;
|
||||
}
|
||||
.upcoming-row .up-time { color: #7a7599; }
|
||||
.calendar-panel { position: sticky; top: 1rem; margin-top: 1.5rem; background: #fff; border: 1px solid #eee; border-radius: 12px; padding: .85rem; }
|
||||
.calendar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .65rem; }
|
||||
.calendar-head button { border: 0; background: #f0edff; color: #6255c7; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; }
|
||||
.calendar-title { font-size: .95rem; font-weight: 700; }
|
||||
.calendar-weekdays, .calendar-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; text-align: center; }
|
||||
.calendar-weekdays { color: #999; font-size: .68rem; margin-bottom: 3px; }
|
||||
.calendar-day { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border-radius: 7px; font-size: .78rem; color: #aaa; }
|
||||
.calendar-day.past { background: #ede9ff; color: #5145a6; font-weight: 700; text-decoration: none; }
|
||||
.calendar-day.past:hover { background: #dcd5ff; }
|
||||
.calendar-day.future { background: #f3f3f3; color: #bbb; border: 1px dashed #ddd; }
|
||||
.calendar-month[hidden] { display: none; }
|
||||
.calendar-legend { margin-top: .65rem; font-size: .72rem; color: #999; }
|
||||
.pagination { display: flex; justify-content: center; align-items: center; gap: .75rem; margin: 1rem 0; font-size: .85rem; }
|
||||
.pagination a { color: #6558c8; text-decoration: none; padding: .35rem .7rem; background: #fff; border: 1px solid #e5e1ff; border-radius: 8px; }
|
||||
.modal-bg { display: none; position: fixed; inset: 0; z-index: 1000; background: rgba(20,18,40,.55); align-items: center; justify-content: center; padding: 1rem; }
|
||||
.modal-bg.open { display: flex; }
|
||||
.notification-modal { width: min(420px, 100%); background: #fff; border-radius: 14px; padding: 1.2rem; box-shadow: 0 15px 50px rgba(0,0,0,.25); }
|
||||
.notification-modal h2 { font-size: 1.15rem; margin-bottom: .45rem; }
|
||||
.notification-modal p { font-size: .88rem; color: #777; }
|
||||
.notification-actions { display: flex; gap: .5rem; margin-top: 1rem; }
|
||||
.notification-actions button { border: 0; border-radius: 8px; padding: .55rem .9rem; cursor: pointer; }
|
||||
.notification-primary { background: #7567e8; color: #fff; }
|
||||
@media (max-width: 800px) {
|
||||
.portal-grid { display: flex; flex-direction: column; }
|
||||
.calendar-panel { position: static; order: -1; width: 100%; margin-top: 1rem; }
|
||||
.visits-column { width: 100%; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -121,6 +157,7 @@
|
||||
<div class="portal-header">
|
||||
<h1>{{ t.portal_title }}</h1>
|
||||
<div class="sub">{{ client.name }}</div>
|
||||
{% if notifications_enabled %}<button class="portal-settings" type="button" onclick="openNotificationSettings()" aria-label="{{ t.portal_notifications }}">⚙</button>{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
@@ -129,13 +166,15 @@
|
||||
<div class="success-msg">{{ t.portal_feedback_thanks }}</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="portal-grid">
|
||||
<main class="visits-column">
|
||||
<!-- Past visits with media first -->
|
||||
<h2 class="section-title">{{ t.portal_past }}</h2>
|
||||
{% if past.is_empty() %}
|
||||
<p class="empty-msg">{{ t.portal_no_past }}</p>
|
||||
{% else %}
|
||||
{% for pv in &past %}
|
||||
<div class="visit-card">
|
||||
<div class="visit-card" id="visit-{{ pv.visit.id.unwrap() }}">
|
||||
<div class="visit-card-head">
|
||||
<span class="date">{{ pv.visit.visit_date }}</span>
|
||||
<span class="badge-sm badge-{{ pv.visit.status }}">
|
||||
@@ -155,13 +194,17 @@
|
||||
<div class="media-row">
|
||||
{% for m in &pv.media %}
|
||||
{% if m.file_type == "photo" %}
|
||||
<a href="/client/{{ client.media_token }}/media/{{ m.id.unwrap() }}" data-lightbox="photo">
|
||||
<img src="/client/{{ client.media_token }}/media/{{ m.id.unwrap() }}" alt="" loading="lazy">
|
||||
<a href="{{ m.url }}" data-lightbox="photo">
|
||||
<span class="media-thumb-frame media-loading-frame is-loading">
|
||||
<img src="{{ m.thumbnail_url }}" alt="" loading="lazy" data-media-load>
|
||||
</span>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="/client/{{ client.media_token }}/media/{{ m.id.unwrap() }}" data-lightbox="video">
|
||||
<div class="vid-thumb">
|
||||
<video src="/client/{{ client.media_token }}/media/{{ m.id.unwrap() }}#t=0.1" preload="metadata" muted playsinline></video>
|
||||
<a href="{{ m.url }}" data-lightbox="video">
|
||||
<div class="vid-thumb media-loading-frame{% if !m.thumbnail_url.is_empty() %} is-loading{% endif %}" data-video-preview>
|
||||
{% if !m.thumbnail_url.is_empty() %}
|
||||
<img class="video-preview-sprite" src="{{ m.thumbnail_url }}" alt="" loading="lazy" data-media-load data-preview-frames="4">
|
||||
{% endif %}
|
||||
<span class="video-play">▶</span>
|
||||
</div>
|
||||
</a>
|
||||
@@ -200,6 +243,13 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% if total_pages > 1 %}
|
||||
<nav class="pagination">
|
||||
{% if has_previous_page %}<a href="?page={{ page - 1 }}">← {{ t.portal_previous }}</a>{% endif %}
|
||||
<span>{{ page }} / {{ total_pages }}</span>
|
||||
{% if has_next_page %}<a href="?page={{ page + 1 }}">{{ t.portal_next }} →</a>{% endif %}
|
||||
</nav>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<!-- Compact upcoming schedule -->
|
||||
@@ -209,14 +259,56 @@
|
||||
{% for pv in &upcoming %}
|
||||
<div class="upcoming-row">
|
||||
<span class="up-date">{{ pv.visit.visit_date }}</span>
|
||||
<span class="up-time">{{ pv.visit.time_start }} — {{ pv.visit.time_end }}</span>
|
||||
<span class="up-time">{{ t.portal_future_visit }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</main>
|
||||
|
||||
{% if !calendar_months.is_empty() %}
|
||||
<aside class="calendar-panel">
|
||||
<div class="calendar-head">
|
||||
<button type="button" onclick="moveCalendar(1)" aria-label="{{ t.portal_previous }}">‹</button>
|
||||
<span class="calendar-title" id="calendarTitle">{{ t.portal_calendar }}</span>
|
||||
<button type="button" onclick="moveCalendar(-1)" aria-label="{{ t.portal_next }}">›</button>
|
||||
</div>
|
||||
<div class="calendar-weekdays"><span>Пн</span><span>Вт</span><span>Ср</span><span>Чт</span><span>Пт</span><span>Сб</span><span>Вс</span></div>
|
||||
{% for month in &calendar_months %}
|
||||
<div class="calendar-month" data-label="{{ month.label }}"{% if !loop.first %} hidden{% endif %}>
|
||||
<div class="calendar-days">
|
||||
{% for _blank in &month.leading_blanks %}<span></span>{% endfor %}
|
||||
{% for day in &month.days %}
|
||||
{% if let Some(href) = day.href.as_deref() %}
|
||||
<a class="calendar-day {{ day.class_name }}" href="{{ href }}" title="{{ day.title }}">{{ day.number }}</a>
|
||||
{% else %}
|
||||
<span class="calendar-day {{ day.class_name }}" title="{{ day.title }}">{{ day.number }}</span>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="calendar-legend">{{ t.portal_future_visit }} — ···</div>
|
||||
</aside>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{% if notifications_enabled %}
|
||||
<div class="modal-bg" id="notificationModal" onclick="if(event.target===this) closeNotificationSettings()">
|
||||
<div class="notification-modal">
|
||||
<h2>{{ t.portal_notifications }}</h2>
|
||||
<p id="notificationText">{{ t.portal_notifications_text }}</p>
|
||||
<p id="notificationStatus" style="display:none;margin-top:0.65rem;font-weight:600;"></p>
|
||||
<div class="notification-actions">
|
||||
<button type="button" class="notification-primary" id="notificationToggle">{{ t.portal_notifications_enable }}</button>
|
||||
<button type="button" onclick="closeNotificationSettings()">✕</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
function showFbEdit(id) {
|
||||
document.getElementById('fb-view-' + id).style.display = 'none';
|
||||
@@ -226,6 +318,120 @@ function hideFbEdit(id) {
|
||||
document.getElementById('fb-form-' + id).style.display = 'none';
|
||||
document.getElementById('fb-view-' + id).style.display = '';
|
||||
}
|
||||
var calendarIndex = 0;
|
||||
function renderCalendar() {
|
||||
var months = document.querySelectorAll('.calendar-month');
|
||||
if (!months.length) return;
|
||||
months.forEach(function(month, index) { month.hidden = index !== calendarIndex; });
|
||||
document.getElementById('calendarTitle').textContent = months[calendarIndex].dataset.label;
|
||||
}
|
||||
function moveCalendar(delta) {
|
||||
var months = document.querySelectorAll('.calendar-month');
|
||||
calendarIndex = Math.max(0, Math.min(months.length - 1, calendarIndex + delta));
|
||||
renderCalendar();
|
||||
}
|
||||
renderCalendar();
|
||||
{% if notifications_enabled %}
|
||||
(function() {
|
||||
var toggle = document.getElementById('notificationToggle');
|
||||
var registration;
|
||||
var subscription;
|
||||
var status = document.getElementById('notificationStatus');
|
||||
function decodeKey(value) {
|
||||
var padding = '='.repeat((4 - value.length % 4) % 4);
|
||||
var raw = atob((value + padding).replace(/-/g, '+').replace(/_/g, '/'));
|
||||
return Uint8Array.from(raw, function(char) { return char.charCodeAt(0); });
|
||||
}
|
||||
function sameKey(left, right) {
|
||||
if (!left || left.byteLength !== right.byteLength) return false;
|
||||
var a = new Uint8Array(left), b = new Uint8Array(right);
|
||||
return a.every(function(value, index) { return value === b[index]; });
|
||||
}
|
||||
function showStatus(message, error) {
|
||||
status.textContent = message;
|
||||
status.style.display = '';
|
||||
status.style.color = error ? '#b42318' : '#067647';
|
||||
}
|
||||
async function saveSubscription(value) {
|
||||
var payload = value.toJSON();
|
||||
payload.language = '{{ lang.code() }}';
|
||||
var response = await fetch('/client/{{ client.media_token }}/push/subscribe', {
|
||||
method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(payload)
|
||||
});
|
||||
if (!response.ok) throw new Error('Subscription API returned HTTP ' + response.status);
|
||||
}
|
||||
async function refresh() {
|
||||
if (!('serviceWorker' in navigator) || !('PushManager' in window) || !('Notification' in window)) {
|
||||
toggle.disabled = true;
|
||||
showStatus('{{ t.portal_notifications_unsupported }}', true);
|
||||
return;
|
||||
}
|
||||
if (!'{{ vapid_public_key }}') {
|
||||
toggle.disabled = true;
|
||||
showStatus('{{ t.portal_notifications_error }}', true);
|
||||
return;
|
||||
}
|
||||
registration = await navigator.serviceWorker.register('/service-worker.js');
|
||||
await registration.update();
|
||||
await navigator.serviceWorker.ready;
|
||||
subscription = await registration.pushManager.getSubscription();
|
||||
var expectedKey = decodeKey('{{ vapid_public_key }}');
|
||||
if (subscription && !sameKey(subscription.options.applicationServerKey, expectedKey)) {
|
||||
await subscription.unsubscribe();
|
||||
subscription = null;
|
||||
}
|
||||
if (subscription) {
|
||||
await saveSubscription(subscription);
|
||||
showStatus('{{ t.portal_notifications_active }}', false);
|
||||
}
|
||||
toggle.textContent = subscription ? '{{ t.portal_notifications_disable }}' : '{{ t.portal_notifications_enable }}';
|
||||
}
|
||||
window.openNotificationSettings = function() {
|
||||
document.getElementById('notificationModal').classList.add('open');
|
||||
refresh().catch(function(error) {
|
||||
console.error(error);
|
||||
showStatus('{{ t.portal_notifications_error }}', true);
|
||||
});
|
||||
};
|
||||
window.closeNotificationSettings = function() { document.getElementById('notificationModal').classList.remove('open'); };
|
||||
toggle.addEventListener('click', async function() {
|
||||
toggle.disabled = true;
|
||||
try {
|
||||
if (!registration) await refresh();
|
||||
if (subscription) {
|
||||
await fetch('/client/{{ client.media_token }}/push/unsubscribe', {
|
||||
method: 'POST', headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({endpoint: subscription.endpoint})
|
||||
});
|
||||
await subscription.unsubscribe();
|
||||
subscription = null;
|
||||
} else {
|
||||
var permission = await Notification.requestPermission();
|
||||
if (permission !== 'granted') {
|
||||
document.getElementById('notificationText').textContent = '{{ t.portal_notifications_denied }}';
|
||||
return;
|
||||
}
|
||||
subscription = await registration.pushManager.subscribe({
|
||||
userVisibleOnly: true,
|
||||
applicationServerKey: decodeKey('{{ vapid_public_key }}')
|
||||
});
|
||||
await saveSubscription(subscription);
|
||||
showStatus('{{ t.portal_notifications_active }}', false);
|
||||
}
|
||||
toggle.textContent = subscription ? '{{ t.portal_notifications_disable }}' : '{{ t.portal_notifications_enable }}';
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
showStatus('{{ t.portal_notifications_error }}', true);
|
||||
} finally {
|
||||
toggle.disabled = false;
|
||||
}
|
||||
});
|
||||
refresh().catch(function(error) {
|
||||
console.error(error);
|
||||
showStatus('{{ t.portal_notifications_error }}', true);
|
||||
});
|
||||
})();
|
||||
{% endif %}
|
||||
</script>
|
||||
{% include "partials/lightbox.html" %}
|
||||
</body>
|
||||
|
||||
@@ -426,8 +426,8 @@
|
||||
<div class="testimonial-text">{{ item.text }}</div>
|
||||
{% if item.image_path.is_some() || item.author_note.is_some() %}
|
||||
<div class="testimonial-footer">
|
||||
{% if item.image_path.is_some() %}
|
||||
<img class="testimonial-avatar" src="/testimonial-image/{{ item.id.unwrap() }}" alt="">
|
||||
{% if let Some(image_url) = item.image_url.as_deref() %}
|
||||
<img class="testimonial-avatar" src="{{ image_url }}" alt="">
|
||||
{% endif %}
|
||||
{% if let Some(note) = item.author_note.as_deref() %}
|
||||
<span class="testimonial-note">{{ note }}</span>
|
||||
|
||||
@@ -1,49 +1,164 @@
|
||||
<div class="lightbox-overlay" id="lightbox" onclick="closeLightbox(event)">
|
||||
<button class="lightbox-close" onclick="closeLightbox(event)">×</button>
|
||||
<img id="lightboxImg" src="" alt="">
|
||||
<video id="lightboxVideo" controls style="display:none;"></video>
|
||||
<button class="lightbox-close" type="button" onclick="closeLightbox(event)">×</button>
|
||||
<div class="lightbox-stage" id="lightboxStage">
|
||||
<span class="lightbox-loader" aria-hidden="true"></span>
|
||||
<img id="lightboxImg" src="" alt="">
|
||||
<video id="lightboxVideo" controls playsinline preload="auto" style="display:none;"></video>
|
||||
</div>
|
||||
</div>
|
||||
<style>
|
||||
.media-loading-frame {
|
||||
position: relative; display: block; overflow: hidden; background: #eceaf5;
|
||||
}
|
||||
.media-loading-frame::after, .lightbox-loader {
|
||||
content: ""; position: absolute; z-index: 3; top: 50%; left: 50%;
|
||||
width: 22px; height: 22px; margin: -11px 0 0 -11px;
|
||||
border: 3px solid rgba(124,108,255,.22); border-top-color: #7c6cff;
|
||||
border-radius: 50%; animation: media-spinner .75s linear infinite;
|
||||
}
|
||||
.media-loading-frame:not(.is-loading)::after { display: none; }
|
||||
.media-loading-frame img[data-media-load] { opacity: 0; transition: opacity .18s ease; }
|
||||
.media-loading-frame.is-loaded img[data-media-load] { opacity: 1; }
|
||||
.media-loading-frame.is-error::after {
|
||||
display: block; content: "!"; width: 24px; height: 24px; margin: -12px 0 0 -12px;
|
||||
border: 0; animation: none; color: #9b93bb; font-weight: 700; text-align: center;
|
||||
}
|
||||
.video-preview-sprite {
|
||||
display: block !important; width: 400% !important; max-width: none !important;
|
||||
height: 100% !important; object-fit: fill !important;
|
||||
transform: translateX(0); transition: transform .08s linear;
|
||||
}
|
||||
@keyframes media-spinner { to { transform: rotate(360deg); } }
|
||||
|
||||
.lightbox-overlay {
|
||||
display:none; position:fixed; inset:0; z-index:200;
|
||||
background:rgba(0,0,0,0.85); align-items:center; justify-content:center;
|
||||
background:rgba(9,8,18,.9); align-items:center; justify-content:center;
|
||||
padding: 1rem;
|
||||
}
|
||||
.lightbox-overlay.is-open { display:flex; }
|
||||
.lightbox-overlay img, .lightbox-overlay video {
|
||||
max-width:92vw; max-height:88vh; border-radius:8px; object-fit:contain;
|
||||
.lightbox-stage {
|
||||
position: relative; display: flex; align-items: center; justify-content: center;
|
||||
min-width: 96px; min-height: 96px; max-width: 94vw; max-height: 90vh;
|
||||
}
|
||||
.lightbox-stage img, .lightbox-stage video {
|
||||
max-width:92vw; max-height:88vh; border-radius:10px; object-fit:contain;
|
||||
background:#090909; box-shadow:0 18px 60px rgba(0,0,0,.42);
|
||||
}
|
||||
.lightbox-stage.is-loading img, .lightbox-stage.is-loading video { opacity: .18; }
|
||||
.lightbox-stage:not(.is-loading) .lightbox-loader { display: none; }
|
||||
.lightbox-stage.is-error .lightbox-loader {
|
||||
display: block; animation: none; border: 0; color: white;
|
||||
}
|
||||
.lightbox-stage.is-error .lightbox-loader::after { content: "!"; font-size: 2rem; }
|
||||
.lightbox-close {
|
||||
position:absolute; top:0.75rem; right:1rem; background:none; border:none;
|
||||
position:absolute; top:0.75rem; right:1rem; background:rgba(0,0,0,.25); border:none;
|
||||
color:#fff; font-size:2.2rem; cursor:pointer; line-height:1; z-index:201;
|
||||
width:44px; height:44px; border-radius:50%;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
(function() {
|
||||
function finishThumbnail(image, loaded) {
|
||||
var frame = image.closest('.media-loading-frame');
|
||||
if (!frame) return;
|
||||
frame.classList.remove('is-loading');
|
||||
frame.classList.add(loaded ? 'is-loaded' : 'is-error');
|
||||
}
|
||||
|
||||
document.querySelectorAll('img[data-media-load]').forEach(function(image) {
|
||||
image.addEventListener('load', function() { finishThumbnail(image, true); });
|
||||
image.addEventListener('error', function() { finishThumbnail(image, false); });
|
||||
if (image.complete) finishThumbnail(image, image.naturalWidth > 0);
|
||||
});
|
||||
|
||||
document.querySelectorAll('[data-video-preview]').forEach(function(preview) {
|
||||
var sprite = preview.querySelector('[data-preview-frames]');
|
||||
if (!sprite) return;
|
||||
var timer;
|
||||
var frame = 0;
|
||||
var frames = Number(sprite.dataset.previewFrames) || 4;
|
||||
function showFrame() {
|
||||
sprite.style.transform = 'translateX(-' + (frame * 100 / frames) + '%)';
|
||||
}
|
||||
function start() {
|
||||
if (timer || !preview.classList.contains('is-loaded')) return;
|
||||
frame = 1;
|
||||
showFrame();
|
||||
timer = window.setInterval(function() {
|
||||
frame = (frame + 1) % frames;
|
||||
showFrame();
|
||||
}, 650);
|
||||
}
|
||||
function stop() {
|
||||
window.clearInterval(timer);
|
||||
timer = null;
|
||||
frame = 0;
|
||||
showFrame();
|
||||
}
|
||||
preview.addEventListener('pointerenter', start);
|
||||
preview.addEventListener('pointerleave', stop);
|
||||
preview.closest('a').addEventListener('focus', start);
|
||||
preview.closest('a').addEventListener('blur', stop);
|
||||
});
|
||||
})();
|
||||
|
||||
function setLightboxState(state) {
|
||||
var stage = document.getElementById('lightboxStage');
|
||||
stage.classList.remove('is-loading', 'is-error');
|
||||
if (state) stage.classList.add(state);
|
||||
}
|
||||
function openLightbox(url, isVideo) {
|
||||
var lb = document.getElementById('lightbox');
|
||||
var img = document.getElementById('lightboxImg');
|
||||
var vid = document.getElementById('lightboxVideo');
|
||||
setLightboxState('is-loading');
|
||||
lb.classList.add('is-open');
|
||||
if (isVideo) {
|
||||
img.style.display = 'none';
|
||||
img.removeAttribute('src');
|
||||
vid.style.display = '';
|
||||
vid.src = url;
|
||||
vid.load();
|
||||
var playback = vid.play();
|
||||
if (playback) playback.catch(function() {});
|
||||
} else {
|
||||
vid.style.display = 'none';
|
||||
vid.pause && vid.pause(); vid.src = '';
|
||||
vid.pause();
|
||||
vid.removeAttribute('src');
|
||||
vid.load();
|
||||
img.style.display = '';
|
||||
img.src = url;
|
||||
}
|
||||
lb.classList.add('is-open');
|
||||
}
|
||||
function closeLightbox(e) {
|
||||
if (e && e.target !== document.getElementById('lightbox') && e.target.className !== 'lightbox-close') return;
|
||||
function closeLightbox(event) {
|
||||
var lb = document.getElementById('lightbox');
|
||||
if (event && event.target !== lb && !event.target.closest('.lightbox-close')) return;
|
||||
lb.classList.remove('is-open');
|
||||
var vid = document.getElementById('lightboxVideo');
|
||||
vid.pause && vid.pause(); vid.src = '';
|
||||
vid.pause();
|
||||
vid.removeAttribute('src');
|
||||
vid.load();
|
||||
var img = document.getElementById('lightboxImg');
|
||||
img.removeAttribute('src');
|
||||
setLightboxState(null);
|
||||
}
|
||||
document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeLightbox(null); });
|
||||
document.addEventListener('click', function(e) {
|
||||
var a = e.target.closest('[data-lightbox]');
|
||||
if (a) { e.preventDefault(); openLightbox(a.href, a.dataset.lightbox === 'video'); }
|
||||
document.getElementById('lightboxImg').addEventListener('load', function() { setLightboxState(null); });
|
||||
document.getElementById('lightboxImg').addEventListener('error', function() { setLightboxState('is-error'); });
|
||||
var lightboxVideo = document.getElementById('lightboxVideo');
|
||||
['loadeddata', 'canplay', 'playing'].forEach(function(name) {
|
||||
lightboxVideo.addEventListener(name, function() { setLightboxState(null); });
|
||||
});
|
||||
['waiting', 'stalled', 'seeking'].forEach(function(name) {
|
||||
lightboxVideo.addEventListener(name, function() { setLightboxState('is-loading'); });
|
||||
});
|
||||
lightboxVideo.addEventListener('error', function() { setLightboxState('is-error'); });
|
||||
document.addEventListener('keydown', function(event) {
|
||||
if (event.key === 'Escape') closeLightbox(null);
|
||||
});
|
||||
document.addEventListener('click', function(event) {
|
||||
var link = event.target.closest('[data-lightbox]');
|
||||
if (!link) return;
|
||||
event.preventDefault();
|
||||
openLightbox(link.href, link.dataset.lightbox === 'video');
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user