Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/Stremio/stremio-core
Browse files Browse the repository at this point in the history
…into feat/streaming-server-remote-endpoint
  • Loading branch information
tymmesyde committed Dec 12, 2023
2 parents 4689a61 + 15e540e commit 729b649
Show file tree
Hide file tree
Showing 21 changed files with 526 additions and 38 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ chrono = { version = "0.4", features = ["serde"] }
semver = { version = "1", features = ["serde"] }
base64 = "0.21"
sha1 = "0.10"
sha2 = "0.10"

either = "1.6"
enclose = "1.1"
derivative = "2.2"
Expand Down
3 changes: 3 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ pub const URI_COMPONENT_ENCODE_SET: &AsciiSet = &NON_ALPHANUMERIC
.remove(b'(')
.remove(b')');

/// In milliseconds
pub const PLAYER_IGNORE_SEEK_AFTER: u64 = 600_000;

pub static BASE64: base64::engine::general_purpose::GeneralPurpose =
base64::engine::general_purpose::STANDARD;

Expand Down
17 changes: 17 additions & 0 deletions src/deep_links/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,3 +539,20 @@ impl From<(&String, &LibraryRequest)> for LibraryDeepLinks {
}
}
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SearchHistoryItemDeepLinks {
pub search: String,
}

impl From<&String> for SearchHistoryItemDeepLinks {
fn from(query: &String) -> Self {
SearchHistoryItemDeepLinks {
search: format!(
"stremio:///search?query={}",
utf8_percent_encode(query, URI_COMPONENT_ENCODE_SET),
),
}
}
}
18 changes: 13 additions & 5 deletions src/models/ctx/ctx.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use crate::constants::LIBRARY_COLLECTION_NAME;
use crate::models::common::{DescriptorLoadable, ResourceLoadable};
use crate::models::common::{DescriptorLoadable, Loadable, ResourceLoadable};
use crate::models::ctx::{
update_library, update_notifications, update_profile, update_search_history, update_streams,
update_trakt_addon, CtxError,
update_events, update_library, update_notifications, update_profile, update_search_history,
update_streams, update_trakt_addon, CtxError,
};
use crate::runtime::msg::{Action, ActionCtx, Event, Internal, Msg};
use crate::runtime::{Effect, EffectFuture, Effects, Env, EnvFutureExt, Update};
use crate::types::api::{
fetch_api, APIRequest, APIResult, AuthRequest, AuthResponse, CollectionResponse,
DatastoreCommand, DatastoreRequest, LibraryItemsResponse, SuccessResponse,
};
use crate::types::events::Events;
use crate::types::library::LibraryBucket;
use crate::types::notifications::NotificationsBucket;
use crate::types::profile::{Auth, AuthKey, Profile};
Expand All @@ -21,7 +22,7 @@ use crate::types::streams::StreamsBucket;
use derivative::Derivative;
use enclose::enclose;
use futures::{future, FutureExt, TryFutureExt};
use serde::{Deserialize, Serialize};
use serde::Serialize;

use tracing::{event, trace, Level};

Expand All @@ -32,7 +33,7 @@ pub enum CtxStatus {
Ready,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[derive(Serialize, Clone, Debug)]
#[cfg_attr(test, derive(Derivative))]
#[cfg_attr(test, derivative(Default))]
pub struct Ctx {
Expand All @@ -54,6 +55,7 @@ pub struct Ctx {
pub trakt_addon: Option<DescriptorLoadable>,
#[serde(skip)]
pub notification_catalogs: Vec<ResourceLoadable<Vec<MetaItem>>>,
pub events: Events,
}

impl Ctx {
Expand All @@ -73,6 +75,10 @@ impl Ctx {
trakt_addon: None,
notification_catalogs: vec![],
status: CtxStatus::Ready,
events: Events {
modal: Loadable::Loading,
notification: Loadable::Loading,
},
}
}
}
Expand Down Expand Up @@ -195,12 +201,14 @@ impl<E: Env + 'static> Update<E> for Ctx {
);
let search_history_effects =
update_search_history::<E>(&mut self.search_history, &self.status, msg);
let events_effects = update_events::<E>(&mut self.events, msg);
profile_effects
.join(library_effects)
.join(streams_effects)
.join(trakt_addon_effects)
.join(notifications_effects)
.join(search_history_effects)
.join(events_effects)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/models/ctx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mod update_events;
use update_events::*;

mod update_library;
use update_library::*;

Expand Down
73 changes: 73 additions & 0 deletions src/models/ctx/update_events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use chrono::DateTime;
use futures::{future, FutureExt, TryFutureExt};

use crate::models::common::{eq_update, Loadable};
use crate::models::ctx::CtxError;
use crate::runtime::msg::{Action, ActionCtx, Internal, Msg};
use crate::runtime::{Effect, EffectFuture, Effects, Env, EnvFutureExt};
use crate::types::api::{
fetch_api, APIRequest, APIResult, GetModalResponse, GetNotificationResponse,
};
use crate::types::events::Events;

pub fn update_events<E: Env + 'static>(events: &mut Events, msg: &Msg) -> Effects {
match msg {
Msg::Action(Action::Ctx(ActionCtx::GetEvents)) => {
let modal_effects = eq_update(&mut events.modal, Loadable::Loading);
let notification_effects = eq_update(&mut events.notification, Loadable::Loading);
let requests_effects = Effects::many(vec![get_modal::<E>(), get_notification::<E>()]);

modal_effects
.join(notification_effects)
.join(requests_effects)
}
Msg::Internal(Internal::GetModalResult(_, result)) => match result {
Ok(response) => eq_update(&mut events.modal, Loadable::Ready(response.to_owned())),
Err(error) => eq_update(&mut events.modal, Loadable::Err(error.to_owned())),
},
Msg::Internal(Internal::GetNotificationResult(_, result)) => match result {
Ok(response) => eq_update(
&mut events.notification,
Loadable::Ready(response.to_owned()),
),
Err(error) => eq_update(&mut events.notification, Loadable::Err(error.to_owned())),
},
_ => Effects::none().unchanged(),
}
}

fn get_modal<E: Env + 'static>() -> Effect {
let request = APIRequest::GetModal {
date: DateTime::from(E::now()),
};

EffectFuture::Concurrent(
fetch_api::<E, _, _, Option<GetModalResponse>>(&request)
.map_err(CtxError::from)
.and_then(|result| match result {
APIResult::Ok { result } => future::ok(result),
APIResult::Err { error } => future::err(CtxError::from(error)),
})
.map(move |result| Msg::Internal(Internal::GetModalResult(request, result)))
.boxed_env(),
)
.into()
}

fn get_notification<E: Env + 'static>() -> Effect {
let request = APIRequest::GetNotification {
date: DateTime::from(E::now()),
};

EffectFuture::Concurrent(
fetch_api::<E, _, _, Option<GetNotificationResponse>>(&request)
.map_err(CtxError::from)
.and_then(|result| match result {
APIResult::Ok { result } => future::ok(result),
APIResult::Err { error } => future::err(CtxError::from(error)),
})
.map(move |result| Msg::Internal(Internal::GetNotificationResult(request, result)))
.boxed_env(),
)
.into()
}
Loading

0 comments on commit 729b649

Please sign in to comment.