diff --git a/platform/api/src/api/v1/gql/models/channel.rs b/platform/api/src/api/v1/gql/models/channel.rs index 1e53f1b5..e8c14f22 100644 --- a/platform/api/src/api/v1/gql/models/channel.rs +++ b/platform/api/src/api/v1/gql/models/channel.rs @@ -1,9 +1,11 @@ use async_graphql::{ComplexObject, Context, SimpleObject}; use chrono::Utc; use jwt_next::SignWithKey; +use ulid::Ulid; use super::category::Category; use super::date::DateRFC3339; +use super::image_upload::ImageUpload; use super::ulid::GqlUlid; use crate::api::v1::gql::error::ext::*; use crate::api::v1::gql::error::Result; @@ -22,11 +24,15 @@ pub struct Channel { pub description: Option, pub links: Vec, pub custom_thumbnail_id: Option, - pub offline_banner_id: Option, + pub pending_offline_banner_id: Option, pub category_id: Option, pub live: Option>, pub last_live_at: Option, + // Custom resolver + #[graphql(skip)] + pub offline_banner_id_: Option, + // Private fields #[graphql(skip)] stream_key_: Option, @@ -50,6 +56,23 @@ impl Channel { Ok(category.map(Into::into)) } + async fn offline_banner_id(&self, ctx: &Context<'_>) -> Result>> { + let Some(offline_banner_id) = self.offline_banner_id_ else { + return Ok(None); + }; + + let global = ctx.get_global::(); + + Ok(global + .uploaded_file_by_id_loader() + .load(offline_banner_id) + .await + .map_err_ignored_gql("failed to fetch offline banner")? + .map(ImageUpload::from_uploaded_file) + .transpose()? + .flatten()) + } + async fn stream_key(&self, ctx: &Context<'_>) -> Result> { auth_guard::<_, G>(ctx, "streamKey", self.stream_key_.as_deref(), self.id.into()).await } @@ -203,7 +226,7 @@ impl From for Channel { description: value.description, links: value.links, custom_thumbnail_id: value.custom_thumbnail_id.map(Into::into), - offline_banner_id: value.offline_banner_id.map(Into::into), + pending_offline_banner_id: value.pending_offline_banner_id.map(Into::into), category_id: value.category_id.map(Into::into), live: value.active_connection_id.map(|_| ChannelLive { room_id: value.room_id.into(), @@ -212,6 +235,7 @@ impl From for Channel { channel_id: value.id, _phantom: std::marker::PhantomData, }), + offline_banner_id_: value.offline_banner_id, last_live_at: value.last_live_at.map(DateRFC3339), stream_key_, } diff --git a/platform/api/src/database/channel.rs b/platform/api/src/database/channel.rs index 597a46fe..d92c6ccf 100644 --- a/platform/api/src/database/channel.rs +++ b/platform/api/src/database/channel.rs @@ -34,6 +34,9 @@ pub struct Channel { /// The offline banner of the channel #[from_row(rename = "channel_offline_banner_id")] pub offline_banner_id: Option, + /// The offline banner of the channel + #[from_row(rename = "channel_pending_offline_banner_id")] + pub pending_offline_banner_id: Option, /// The current stream's category #[from_row(rename = "channel_category_id")] pub category_id: Option, diff --git a/schema.graphql b/schema.graphql index c0253123..d5fccf93 100644 --- a/schema.graphql +++ b/schema.graphql @@ -149,7 +149,8 @@ type Channel { lastLiveAt: DateRFC3339 links: [ChannelLink!]! live: ChannelLive - offlineBannerId: ULID + offlineBannerId: ImageUpload + pendingOfflineBannerId: ULID streamKey: String title: String }