Skip to content

Commit

Permalink
Merge branch 'development' into feat/stream-rar-and-zip-stream-creation
Browse files Browse the repository at this point in the history
  • Loading branch information
elpiel committed Nov 29, 2024
2 parents fc7f410 + 4a6cfe8 commit d1868dd
Show file tree
Hide file tree
Showing 40 changed files with 540 additions and 1,643 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub const LIBRARY_STORAGE_KEY: &str = "library";
pub const LIBRARY_RECENT_STORAGE_KEY: &str = "library_recent";
pub const STREAMS_STORAGE_KEY: &str = "streams";
pub const SEARCH_HISTORY_STORAGE_KEY: &str = "search_history";
pub const STREAMING_SERVER_URLS_STORAGE_KEY: &str = "streaming_server_urls";
pub const NOTIFICATIONS_STORAGE_KEY: &str = "notifications";
pub const CALENDAR_STORAGE_KEY: &str = "calendar";
pub const DISMISSED_EVENTS_STORAGE_KEY: &str = "dismissed_events";
Expand All @@ -38,7 +39,7 @@ pub const CALENDAR_ITEMS_COUNT: usize = 100;
pub const WATCHED_THRESHOLD_COEF: f64 = 0.7;
pub const CREDITS_THRESHOLD_COEF: f64 = 0.9;
/// The latest migration scheme version
pub const SCHEMA_VERSION: u32 = 14;
pub const SCHEMA_VERSION: u32 = 15;
pub const IMDB_LINK_CATEGORY: &str = "imdb";
pub const GENRES_LINK_CATEGORY: &str = "Genres";
pub const CINEMETA_TOP_CATALOG_ID: &str = "top";
Expand Down
26 changes: 25 additions & 1 deletion src/models/ctx/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use crate::{
common::{DescriptorLoadable, Loadable, ResourceLoadable},
ctx::{
update_events, update_library, update_notifications, update_profile,
update_search_history, update_streams, update_trakt_addon, CtxError, OtherError,
update_search_history, update_streaming_server_urls, update_streams,
update_trakt_addon, CtxError, OtherError,
},
},
runtime::{
Expand All @@ -22,6 +23,7 @@ use crate::{
profile::{Auth, AuthKey, Profile},
resource::MetaItem,
search_history::SearchHistoryBucket,
server_urls::ServerUrlsBucket,
streams::StreamsBucket,
},
};
Expand Down Expand Up @@ -54,6 +56,8 @@ pub struct Ctx {
#[serde(skip)]
pub streams: StreamsBucket,
#[serde(skip)]
pub streaming_server_urls: ServerUrlsBucket,
#[serde(skip)]
pub search_history: SearchHistoryBucket,
#[serde(skip)]
pub dismissed_events: DismissedEventsBucket,
Expand All @@ -78,6 +82,7 @@ impl Ctx {
profile: Profile,
library: LibraryBucket,
streams: StreamsBucket,
streaming_server_urls: ServerUrlsBucket,
notifications: NotificationsBucket,

search_history: SearchHistoryBucket,
Expand All @@ -87,6 +92,7 @@ impl Ctx {
profile,
library,
streams,
streaming_server_urls,
search_history,
dismissed_events,
notifications,
Expand Down Expand Up @@ -119,6 +125,11 @@ impl<E: Env + 'static> Update<E> for Ctx {
let library_effects =
update_library::<E>(&mut self.library, &self.profile, &self.status, msg);
let streams_effects = update_streams::<E>(&mut self.streams, &self.status, msg);
let server_urls_effects = update_streaming_server_urls::<E>(
&mut self.streaming_server_urls,
&self.status,
msg,
);
let search_history_effects =
update_search_history::<E>(&mut self.search_history, &self.status, msg);
let events_effects =
Expand All @@ -144,6 +155,7 @@ impl<E: Env + 'static> Update<E> for Ctx {
.join(profile_effects)
.join(library_effects)
.join(streams_effects)
.join(server_urls_effects)
.join(search_history_effects)
.join(events_effects)
.join(trakt_addon_effects)
Expand All @@ -169,6 +181,11 @@ impl<E: Env + 'static> Update<E> for Ctx {
msg,
);
let streams_effects = update_streams::<E>(&mut self.streams, &self.status, msg);
let server_urls_effects = update_streaming_server_urls::<E>(
&mut self.streaming_server_urls,
&self.status,
msg,
);
let search_history_effects =
update_search_history::<E>(&mut self.search_history, &self.status, msg);
let events_effects =
Expand Down Expand Up @@ -237,6 +254,7 @@ impl<E: Env + 'static> Update<E> for Ctx {
profile_effects
.join(library_effects)
.join(streams_effects)
.join(server_urls_effects)
.join(trakt_addon_effects)
.join(notifications_effects)
.join(search_history_effects)
Expand All @@ -249,6 +267,11 @@ impl<E: Env + 'static> Update<E> for Ctx {
let library_effects =
update_library::<E>(&mut self.library, &self.profile, &self.status, msg);
let streams_effects = update_streams::<E>(&mut self.streams, &self.status, msg);
let server_urls_effects = update_streaming_server_urls::<E>(
&mut self.streaming_server_urls,
&self.status,
msg,
);
let trakt_addon_effects = update_trakt_addon::<E>(
&mut self.trakt_addon,
&self.profile,
Expand All @@ -270,6 +293,7 @@ impl<E: Env + 'static> Update<E> for Ctx {
profile_effects
.join(library_effects)
.join(streams_effects)
.join(server_urls_effects)
.join(trakt_addon_effects)
.join(notifications_effects)
.join(search_history_effects)
Expand Down
3 changes: 3 additions & 0 deletions src/models/ctx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ use update_search_history::*;
mod update_trakt_addon;
use update_trakt_addon::*;

mod update_streaming_server_urls;
use update_streaming_server_urls::*;

mod error;
pub use error::*;

Expand Down
64 changes: 64 additions & 0 deletions src/models/ctx/update_streaming_server_urls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use futures::FutureExt;

use crate::constants::STREAMING_SERVER_URLS_STORAGE_KEY;
use crate::runtime::msg::{Action, ActionCtx, CtxAuthResponse};
use crate::runtime::{
msg::{Event, Internal, Msg},
Effect, EffectFuture, Effects, Env, EnvFutureExt,
};
use crate::types::server_urls::ServerUrlsBucket;

use super::{CtxError, CtxStatus};

pub fn update_streaming_server_urls<E: Env + 'static>(
streaming_server_urls: &mut ServerUrlsBucket,
status: &CtxStatus,
msg: &Msg,
) -> Effects {
match msg {
Msg::Action(Action::Ctx(ActionCtx::AddServerUrl(url))) => {
streaming_server_urls.add_url::<E>(url.clone());
Effects::msg(Msg::Internal(Internal::StreamingServerUrlsBucketChanged))
}
Msg::Action(Action::Ctx(ActionCtx::DeleteServerUrl(url))) => {
streaming_server_urls.delete_url(url);
Effects::msg(Msg::Internal(Internal::StreamingServerUrlsBucketChanged))
}
Msg::Internal(Internal::CtxAuthResult(auth_request, result)) => match (status, result) {
(CtxStatus::Loading(loading_auth_request), Ok(CtxAuthResponse { auth, .. }))
if loading_auth_request == auth_request =>
{
let next_server_urls = ServerUrlsBucket::new::<E>(Some(auth.user.id.to_owned()));
*streaming_server_urls = next_server_urls;
Effects::msg(Msg::Internal(Internal::StreamingServerUrlsBucketChanged))
}
_ => Effects::none().unchanged(),
},
Msg::Internal(Internal::StreamingServerUrlsBucketChanged) => {
Effects::one(push_server_urls_to_storage::<E>(streaming_server_urls)).unchanged()
}
_ => Effects::none().unchanged(),
}
}

fn push_server_urls_to_storage<E: Env + 'static>(
streaming_server_urls: &ServerUrlsBucket,
) -> Effect {
let uid: Option<String> = streaming_server_urls.uid.clone();

EffectFuture::Sequential(
E::set_storage(
STREAMING_SERVER_URLS_STORAGE_KEY,
Some(streaming_server_urls),
)
.map(move |result| match result {
Ok(_) => Msg::Event(Event::StreamingServerUrlsPushedToStorage { uid: uid.clone() }),
Err(error) => Msg::Event(Event::Error {
error: CtxError::from(error),
source: Box::new(Event::StreamingServerUrlsPushedToStorage { uid: uid.clone() }),
}),
})
.boxed_env(),
)
.into()
}
Loading

0 comments on commit d1868dd

Please sign in to comment.