Skip to content

Commit

Permalink
feat(platform): offline banner gql api
Browse files Browse the repository at this point in the history
  • Loading branch information
lennartkloock committed Jan 19, 2024
1 parent ae0f78d commit 7404cdc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
28 changes: 26 additions & 2 deletions platform/api/src/api/v1/gql/models/channel.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,11 +24,15 @@ pub struct Channel<G: ApiGlobal> {
pub description: Option<String>,
pub links: Vec<database::ChannelLink>,
pub custom_thumbnail_id: Option<GqlUlid>,
pub offline_banner_id: Option<GqlUlid>,
pub pending_offline_banner_id: Option<GqlUlid>,
pub category_id: Option<GqlUlid>,
pub live: Option<ChannelLive<G>>,
pub last_live_at: Option<DateRFC3339>,

// Custom resolver
#[graphql(skip)]
pub offline_banner_id_: Option<Ulid>,

// Private fields
#[graphql(skip)]
stream_key_: Option<String>,
Expand All @@ -50,6 +56,23 @@ impl<G: ApiGlobal> Channel<G> {
Ok(category.map(Into::into))
}

async fn offline_banner_id(&self, ctx: &Context<'_>) -> Result<Option<ImageUpload<G>>> {
let Some(offline_banner_id) = self.offline_banner_id_ else {
return Ok(None);
};

let global = ctx.get_global::<G>();

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<Option<&str>> {
auth_guard::<_, G>(ctx, "streamKey", self.stream_key_.as_deref(), self.id.into()).await
}
Expand Down Expand Up @@ -203,7 +226,7 @@ impl<G: ApiGlobal> From<database::Channel> for Channel<G> {
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(),
Expand All @@ -212,6 +235,7 @@ impl<G: ApiGlobal> From<database::Channel> for Channel<G> {
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_,
}
Expand Down
3 changes: 3 additions & 0 deletions platform/api/src/database/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ulid>,
/// The offline banner of the channel
#[from_row(rename = "channel_pending_offline_banner_id")]
pub pending_offline_banner_id: Option<Ulid>,
/// The current stream's category
#[from_row(rename = "channel_category_id")]
pub category_id: Option<Ulid>,
Expand Down
3 changes: 2 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ type Channel {
lastLiveAt: DateRFC3339
links: [ChannelLink!]!
live: ChannelLive
offlineBannerId: ULID
offlineBannerId: ImageUpload
pendingOfflineBannerId: ULID
streamKey: String
title: String
}
Expand Down

0 comments on commit 7404cdc

Please sign in to comment.