feat(channel): add logo support with position and opacity settings

This commit is contained in:
2026-03-14 02:27:16 +01:00
parent e610c23fea
commit da714840ee
11 changed files with 204 additions and 6 deletions

View File

@@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
use sqlx::FromRow;
use uuid::Uuid;
use domain::{AccessMode, Channel, ChannelId, DomainError, RecyclePolicy, ScheduleConfig, UserId};
use domain::{AccessMode, Channel, ChannelId, DomainError, LogoPosition, RecyclePolicy, ScheduleConfig, UserId};
#[derive(Debug, FromRow)]
pub(super) struct ChannelRow {
@@ -16,6 +16,9 @@ pub(super) struct ChannelRow {
pub auto_schedule: i64,
pub access_mode: String,
pub access_password_hash: Option<String>,
pub logo: Option<String>,
pub logo_position: String,
pub logo_opacity: f32,
pub created_at: String,
pub updated_at: String,
}
@@ -51,6 +54,11 @@ impl TryFrom<ChannelRow> for Channel {
)
.unwrap_or_default();
let logo_position: LogoPosition = serde_json::from_value(
serde_json::Value::String(row.logo_position),
)
.unwrap_or_default();
Ok(Channel {
id,
owner_id,
@@ -62,6 +70,9 @@ impl TryFrom<ChannelRow> for Channel {
auto_schedule: row.auto_schedule != 0,
access_mode,
access_password_hash: row.access_password_hash,
logo: row.logo,
logo_position,
logo_opacity: row.logo_opacity,
created_at: parse_dt(&row.created_at)?,
updated_at: parse_dt(&row.updated_at)?,
})
@@ -69,4 +80,4 @@ impl TryFrom<ChannelRow> for Channel {
}
pub(super) const SELECT_COLS: &str =
"id, owner_id, name, description, timezone, schedule_config, recycle_policy, auto_schedule, access_mode, access_password_hash, created_at, updated_at";
"id, owner_id, name, description, timezone, schedule_config, recycle_policy, auto_schedule, access_mode, access_password_hash, logo, logo_position, logo_opacity, created_at, updated_at";

View File

@@ -63,11 +63,16 @@ impl ChannelRepository for SqliteChannelRepository {
.and_then(|v| v.as_str().map(str::to_owned))
.unwrap_or_else(|| "public".to_owned());
let logo_position = serde_json::to_value(&channel.logo_position)
.ok()
.and_then(|v| v.as_str().map(str::to_owned))
.unwrap_or_else(|| "top_right".to_owned());
sqlx::query(
r#"
INSERT INTO channels
(id, owner_id, name, description, timezone, schedule_config, recycle_policy, auto_schedule, access_mode, access_password_hash, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
(id, owner_id, name, description, timezone, schedule_config, recycle_policy, auto_schedule, access_mode, access_password_hash, logo, logo_position, logo_opacity, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET
name = excluded.name,
description = excluded.description,
@@ -77,6 +82,9 @@ impl ChannelRepository for SqliteChannelRepository {
auto_schedule = excluded.auto_schedule,
access_mode = excluded.access_mode,
access_password_hash = excluded.access_password_hash,
logo = excluded.logo,
logo_position = excluded.logo_position,
logo_opacity = excluded.logo_opacity,
updated_at = excluded.updated_at
"#,
)
@@ -90,6 +98,9 @@ impl ChannelRepository for SqliteChannelRepository {
.bind(channel.auto_schedule as i64)
.bind(&access_mode)
.bind(&channel.access_password_hash)
.bind(&channel.logo)
.bind(&logo_position)
.bind(channel.logo_opacity)
.bind(channel.created_at.to_rfc3339())
.bind(channel.updated_at.to_rfc3339())
.execute(&self.pool)