feat: Update to latest iced

This commit is contained in:
uttarayan21
2025-11-18 23:54:27 +05:30
parent a6ef6ba9c0
commit 3222c26bb6
15 changed files with 1231 additions and 4918 deletions

View File

@@ -40,7 +40,7 @@ pub struct ActivityLogEntry {
pub item_id: Option<String>,
/// Gets or sets the date.
#[serde(rename = "Date")]
pub date: jiff::Zoned,
pub date: jiff::Timestamp,
/// Gets or sets the user identifier.
#[serde(rename = "UserId")]
pub user_id: uuid::Uuid,
@@ -130,7 +130,7 @@ pub struct AlbumInfo {
#[serde(rename = "ParentIndexNumber")]
pub parent_index_number: Option<i32>,
#[serde(rename = "PremiereDate")]
pub premiere_date: Option<jiff::Zoned>,
pub premiere_date: Option<jiff::Timestamp>,
#[serde(rename = "IsAutomated")]
pub is_automated: bool,
/// Gets or sets the album artist.
@@ -195,7 +195,7 @@ pub struct ArtistInfo {
#[serde(rename = "ParentIndexNumber")]
pub parent_index_number: Option<i32>,
#[serde(rename = "PremiereDate")]
pub premiere_date: Option<jiff::Zoned>,
pub premiere_date: Option<jiff::Timestamp>,
#[serde(rename = "IsAutomated")]
pub is_automated: bool,
#[serde(rename = "SongInfos")]
@@ -252,12 +252,12 @@ pub struct AuthenticationInfo {
pub is_active: bool,
/// Gets or sets the date created.
#[serde(rename = "DateCreated")]
pub date_created: jiff::Zoned,
pub date_created: jiff::Timestamp,
/// Gets or sets the date revoked.
#[serde(rename = "DateRevoked")]
pub date_revoked: Option<jiff::Zoned>,
pub date_revoked: Option<jiff::Timestamp>,
#[serde(rename = "DateLastActivity")]
pub date_last_activity: jiff::Zoned,
pub date_last_activity: jiff::Timestamp,
#[serde(rename = "UserName")]
pub user_name: Option<String>,
}
@@ -316,9 +316,9 @@ pub struct BaseItemDto {
pub playlist_item_id: Option<String>,
/// Gets or sets the date created.
#[serde(rename = "DateCreated")]
pub date_created: Option<jiff::Zoned>,
pub date_created: Option<jiff::Timestamp>,
#[serde(rename = "DateLastMediaAdded")]
pub date_last_media_added: Option<jiff::Zoned>,
pub date_last_media_added: Option<jiff::Timestamp>,
#[serde(rename = "ExtraType")]
pub extra_type: Option<ExtraType>,
#[serde(rename = "AirsBeforeSeasonNumber")]
@@ -351,7 +351,7 @@ pub struct BaseItemDto {
pub video3_d_format: Option<Video3DFormat>,
/// Gets or sets the premiere date.
#[serde(rename = "PremiereDate")]
pub premiere_date: Option<jiff::Zoned>,
pub premiere_date: Option<jiff::Timestamp>,
/// Gets or sets the external urls.
#[serde(rename = "ExternalUrls")]
pub external_urls: Option<Vec<ExternalUrl>>,
@@ -568,7 +568,7 @@ pub struct BaseItemDto {
/** Gets or sets the blurhashes for the image tags.
Maps image type to dictionary mapping image tag to blurhash value.*/
#[serde(rename = "ImageBlurHashes")]
pub image_blur_hashes: Option<std::collections::HashMap<String, serde_json::Value>>,
pub image_blur_hashes: BaseItemDtoImageBlurHashes,
/// Gets or sets the series studio.
#[serde(rename = "SeriesStudio")]
pub series_studio: Option<String>,
@@ -606,7 +606,7 @@ Maps image type to dictionary mapping image tag to blurhash value.*/
pub media_type: MediaType,
/// Gets or sets the end date.
#[serde(rename = "EndDate")]
pub end_date: Option<jiff::Zoned>,
pub end_date: Option<jiff::Timestamp>,
/// Gets or sets the locked fields.
#[serde(rename = "LockedFields")]
pub locked_fields: Option<Vec<MetadataField>>,
@@ -677,7 +677,7 @@ Maps image type to dictionary mapping image tag to blurhash value.*/
pub channel_primary_image_tag: Option<String>,
/// Gets or sets the start date of the recording, in UTC.
#[serde(rename = "StartDate")]
pub start_date: Option<jiff::Zoned>,
pub start_date: Option<jiff::Timestamp>,
/// Gets or sets the completion percentage.
#[serde(rename = "CompletionPercentage")]
pub completion_percentage: Option<f64>,
@@ -724,6 +724,37 @@ Maps image type to dictionary mapping image tag to blurhash value.*/
#[serde(rename = "CurrentProgram")]
pub current_program: Option<Box<BaseItemDto>>,
}
/** Gets or sets the blurhashes for the image tags.
Maps image type to dictionary mapping image tag to blurhash value.*/
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct BaseItemDtoImageBlurHashes {
#[serde(rename = "Primary")]
pub primary: std::collections::HashMap<String, String>,
#[serde(rename = "Art")]
pub art: std::collections::HashMap<String, String>,
#[serde(rename = "Backdrop")]
pub backdrop: std::collections::HashMap<String, String>,
#[serde(rename = "Banner")]
pub banner: std::collections::HashMap<String, String>,
#[serde(rename = "Logo")]
pub logo: std::collections::HashMap<String, String>,
#[serde(rename = "Thumb")]
pub thumb: std::collections::HashMap<String, String>,
#[serde(rename = "Disc")]
pub disc: std::collections::HashMap<String, String>,
#[serde(rename = "Box")]
pub _box: std::collections::HashMap<String, String>,
#[serde(rename = "Screenshot")]
pub screenshot: std::collections::HashMap<String, String>,
#[serde(rename = "Menu")]
pub menu: std::collections::HashMap<String, String>,
#[serde(rename = "Chapter")]
pub chapter: std::collections::HashMap<String, String>,
#[serde(rename = "BoxRear")]
pub box_rear: std::collections::HashMap<String, String>,
#[serde(rename = "Profile")]
pub profile: std::collections::HashMap<String, String>,
}
/// Query result container.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct BaseItemDtoQueryResult {
@@ -757,7 +788,37 @@ pub struct BaseItemPerson {
pub primary_image_tag: Option<String>,
/// Gets or sets the primary image blurhash.
#[serde(rename = "ImageBlurHashes")]
pub image_blur_hashes: Option<std::collections::HashMap<String, serde_json::Value>>,
pub image_blur_hashes: BaseItemPersonImageBlurHashes,
}
/// Gets or sets the primary image blurhash.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct BaseItemPersonImageBlurHashes {
#[serde(rename = "Primary")]
pub primary: std::collections::HashMap<String, String>,
#[serde(rename = "Art")]
pub art: std::collections::HashMap<String, String>,
#[serde(rename = "Backdrop")]
pub backdrop: std::collections::HashMap<String, String>,
#[serde(rename = "Banner")]
pub banner: std::collections::HashMap<String, String>,
#[serde(rename = "Logo")]
pub logo: std::collections::HashMap<String, String>,
#[serde(rename = "Thumb")]
pub thumb: std::collections::HashMap<String, String>,
#[serde(rename = "Disc")]
pub disc: std::collections::HashMap<String, String>,
#[serde(rename = "Box")]
pub _box: std::collections::HashMap<String, String>,
#[serde(rename = "Screenshot")]
pub screenshot: std::collections::HashMap<String, String>,
#[serde(rename = "Menu")]
pub menu: std::collections::HashMap<String, String>,
#[serde(rename = "Chapter")]
pub chapter: std::collections::HashMap<String, String>,
#[serde(rename = "BoxRear")]
pub box_rear: std::collections::HashMap<String, String>,
#[serde(rename = "Profile")]
pub profile: std::collections::HashMap<String, String>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct BookInfo {
@@ -787,7 +848,7 @@ pub struct BookInfo {
#[serde(rename = "ParentIndexNumber")]
pub parent_index_number: Option<i32>,
#[serde(rename = "PremiereDate")]
pub premiere_date: Option<jiff::Zoned>,
pub premiere_date: Option<jiff::Timestamp>,
#[serde(rename = "IsAutomated")]
pub is_automated: bool,
#[serde(rename = "SeriesName")]
@@ -834,7 +895,7 @@ pub struct BoxSetInfo {
#[serde(rename = "ParentIndexNumber")]
pub parent_index_number: Option<i32>,
#[serde(rename = "PremiereDate")]
pub premiere_date: Option<jiff::Zoned>,
pub premiere_date: Option<jiff::Timestamp>,
#[serde(rename = "IsAutomated")]
pub is_automated: bool,
}
@@ -869,7 +930,7 @@ pub struct BrandingOptions {
pub struct BufferRequestDto {
/// Gets or sets when the request has been made by the client.
#[serde(rename = "When")]
pub when: jiff::Zoned,
pub when: jiff::Timestamp,
/// Gets or sets the position ticks.
#[serde(rename = "PositionTicks")]
pub position_ticks: i64,
@@ -958,7 +1019,7 @@ pub struct ChapterInfo {
#[serde(rename = "ImagePath")]
pub image_path: Option<String>,
#[serde(rename = "ImageDateModified")]
pub image_date_modified: jiff::Zoned,
pub image_date_modified: jiff::Timestamp,
#[serde(rename = "ImageTag")]
pub image_tag: Option<String>,
}
@@ -1183,7 +1244,7 @@ pub struct DeviceInfoDto {
pub last_user_id: Option<uuid::Uuid>,
/// Gets or sets the date last modified.
#[serde(rename = "DateLastActivity")]
pub date_last_activity: Option<jiff::Zoned>,
pub date_last_activity: Option<jiff::Timestamp>,
/// Gets or sets the capabilities.
#[serde(rename = "Capabilities")]
pub capabilities: ClientCapabilitiesDto,
@@ -1527,10 +1588,10 @@ pub struct FontFile {
pub size: i64,
/// Gets or sets the date created.
#[serde(rename = "DateCreated")]
pub date_created: jiff::Zoned,
pub date_created: jiff::Timestamp,
/// Gets or sets the date modified.
#[serde(rename = "DateModified")]
pub date_modified: jiff::Zoned,
pub date_modified: jiff::Timestamp,
}
/// Force keep alive websocket messages.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
@@ -1569,7 +1630,7 @@ pub struct ForgotPasswordResult {
pub pin_file: Option<String>,
/// Gets or sets the pin expiration date.
#[serde(rename = "PinExpirationDate")]
pub pin_expiration_date: Option<jiff::Zoned>,
pub pin_expiration_date: Option<jiff::Timestamp>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct GeneralCommand {
@@ -1605,7 +1666,7 @@ pub struct GetProgramsDto {
pub user_id: Option<uuid::Uuid>,
/// Gets or sets the minimum premiere start date.
#[serde(rename = "MinStartDate")]
pub min_start_date: Option<jiff::Zoned>,
pub min_start_date: Option<jiff::Timestamp>,
/// Gets or sets filter by programs that have completed airing, or not.
#[serde(rename = "HasAired")]
pub has_aired: Option<bool>,
@@ -1614,13 +1675,13 @@ pub struct GetProgramsDto {
pub is_airing: Option<bool>,
/// Gets or sets the maximum premiere start date.
#[serde(rename = "MaxStartDate")]
pub max_start_date: Option<jiff::Zoned>,
pub max_start_date: Option<jiff::Timestamp>,
/// Gets or sets the minimum premiere end date.
#[serde(rename = "MinEndDate")]
pub min_end_date: Option<jiff::Zoned>,
pub min_end_date: Option<jiff::Timestamp>,
/// Gets or sets the maximum premiere end date.
#[serde(rename = "MaxEndDate")]
pub max_end_date: Option<jiff::Zoned>,
pub max_end_date: Option<jiff::Timestamp>,
/// Gets or sets filter for movies.
#[serde(rename = "IsMovie")]
pub is_movie: Option<bool>,
@@ -1696,7 +1757,7 @@ pub struct GroupInfoDto {
pub participants: Vec<String>,
/// Gets the date when this DTO has been created.
#[serde(rename = "LastUpdatedAt")]
pub last_updated_at: jiff::Zoned,
pub last_updated_at: jiff::Timestamp,
}
/// Class GroupUpdate.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
@@ -1748,10 +1809,10 @@ pub struct GroupUpdate {
pub struct GuideInfo {
/// Gets or sets the start date.
#[serde(rename = "StartDate")]
pub start_date: jiff::Zoned,
pub start_date: jiff::Timestamp,
/// Gets or sets the end date.
#[serde(rename = "EndDate")]
pub end_date: jiff::Zoned,
pub end_date: jiff::Timestamp,
}
/// Class IgnoreWaitRequestDto.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
@@ -2215,10 +2276,10 @@ pub struct LocalizationOption {
pub struct LogFile {
/// Gets or sets the date created.
#[serde(rename = "DateCreated")]
pub date_created: jiff::Zoned,
pub date_created: jiff::Timestamp,
/// Gets or sets the date modified.
#[serde(rename = "DateModified")]
pub date_modified: jiff::Zoned,
pub date_modified: jiff::Timestamp,
/// Gets or sets the size.
#[serde(rename = "Size")]
pub size: i64,
@@ -2755,7 +2816,7 @@ pub struct MovieInfo {
#[serde(rename = "ParentIndexNumber")]
pub parent_index_number: Option<i32>,
#[serde(rename = "PremiereDate")]
pub premiere_date: Option<jiff::Zoned>,
pub premiere_date: Option<jiff::Timestamp>,
#[serde(rename = "IsAutomated")]
pub is_automated: bool,
}
@@ -2800,7 +2861,7 @@ pub struct MusicVideoInfo {
#[serde(rename = "ParentIndexNumber")]
pub parent_index_number: Option<i32>,
#[serde(rename = "PremiereDate")]
pub premiere_date: Option<jiff::Zoned>,
pub premiere_date: Option<jiff::Timestamp>,
#[serde(rename = "IsAutomated")]
pub is_automated: bool,
#[serde(rename = "Artists")]
@@ -3070,7 +3131,7 @@ pub struct PersonLookupInfo {
#[serde(rename = "ParentIndexNumber")]
pub parent_index_number: Option<i32>,
#[serde(rename = "PremiereDate")]
pub premiere_date: Option<jiff::Zoned>,
pub premiere_date: Option<jiff::Timestamp>,
#[serde(rename = "IsAutomated")]
pub is_automated: bool,
}
@@ -3419,7 +3480,7 @@ pub struct PlayQueueUpdate {
pub reason: PlayQueueUpdateReason,
/// Gets the UTC time of the last change to the playing queue.
#[serde(rename = "LastUpdate")]
pub last_update: jiff::Zoned,
pub last_update: jiff::Timestamp,
/// Gets the playlist.
#[serde(rename = "Playlist")]
pub playlist: Vec<SyncPlayQueueItem>,
@@ -3729,14 +3790,14 @@ pub struct QuickConnectResult {
pub app_version: String,
/// Gets or sets the DateTime that this request was created.
#[serde(rename = "DateAdded")]
pub date_added: jiff::Zoned,
pub date_added: jiff::Timestamp,
}
/// Class ReadyRequest.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct ReadyRequestDto {
/// Gets or sets when the request has been made by the client.
#[serde(rename = "When")]
pub when: jiff::Zoned,
pub when: jiff::Timestamp,
/// Gets or sets the position ticks.
#[serde(rename = "PositionTicks")]
pub position_ticks: i64,
@@ -3849,7 +3910,7 @@ pub struct RemoteSearchResult {
#[serde(rename = "ParentIndexNumber")]
pub parent_index_number: Option<i32>,
#[serde(rename = "PremiereDate")]
pub premiere_date: Option<jiff::Zoned>,
pub premiere_date: Option<jiff::Timestamp>,
#[serde(rename = "ImageUrl")]
pub image_url: Option<String>,
#[serde(rename = "SearchProviderName")]
@@ -3878,7 +3939,7 @@ pub struct RemoteSubtitleInfo {
#[serde(rename = "Comment")]
pub comment: Option<String>,
#[serde(rename = "DateCreated")]
pub date_created: Option<jiff::Zoned>,
pub date_created: Option<jiff::Timestamp>,
#[serde(rename = "CommunityRating")]
pub community_rating: Option<f32>,
#[serde(rename = "FrameRate")]
@@ -4051,10 +4112,10 @@ pub struct SearchHint {
pub media_type: MediaType,
/// Gets or sets the start date.
#[serde(rename = "StartDate")]
pub start_date: Option<jiff::Zoned>,
pub start_date: Option<jiff::Timestamp>,
/// Gets or sets the end date.
#[serde(rename = "EndDate")]
pub end_date: Option<jiff::Zoned>,
pub end_date: Option<jiff::Timestamp>,
/// Gets or sets the series.
#[serde(rename = "Series")]
pub series: Option<String>,
@@ -4117,7 +4178,7 @@ pub struct SendCommand {
pub playlist_item_id: uuid::Uuid,
/// Gets or sets the UTC time when to execute the command.
#[serde(rename = "When")]
pub when: jiff::Zoned,
pub when: jiff::Timestamp,
/// Gets the position ticks.
#[serde(rename = "PositionTicks")]
pub position_ticks: Option<i64>,
@@ -4126,7 +4187,7 @@ pub struct SendCommand {
pub command: SendCommandType,
/// Gets the UTC time when this command has been emitted.
#[serde(rename = "EmittedAt")]
pub emitted_at: jiff::Zoned,
pub emitted_at: jiff::Timestamp,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct SeriesInfo {
@@ -4156,7 +4217,7 @@ pub struct SeriesInfo {
#[serde(rename = "ParentIndexNumber")]
pub parent_index_number: Option<i32>,
#[serde(rename = "PremiereDate")]
pub premiere_date: Option<jiff::Zoned>,
pub premiere_date: Option<jiff::Timestamp>,
#[serde(rename = "IsAutomated")]
pub is_automated: bool,
}
@@ -4238,10 +4299,10 @@ pub struct SeriesTimerInfoDto {
pub overview: Option<String>,
/// Gets or sets the start date of the recording, in UTC.
#[serde(rename = "StartDate")]
pub start_date: jiff::Zoned,
pub start_date: jiff::Timestamp,
/// Gets or sets the end date of the recording, in UTC.
#[serde(rename = "EndDate")]
pub end_date: jiff::Zoned,
pub end_date: jiff::Timestamp,
/// Gets or sets the name of the service.
#[serde(rename = "ServiceName")]
pub service_name: Option<String>,
@@ -4537,13 +4598,13 @@ pub struct SessionInfoDto {
pub client: Option<String>,
/// Gets or sets the last activity date.
#[serde(rename = "LastActivityDate")]
pub last_activity_date: jiff::Zoned,
pub last_activity_date: jiff::Timestamp,
/// Gets or sets the last playback check in.
#[serde(rename = "LastPlaybackCheckIn")]
pub last_playback_check_in: jiff::Zoned,
pub last_playback_check_in: jiff::Timestamp,
/// Gets or sets the last paused date.
#[serde(rename = "LastPausedDate")]
pub last_paused_date: Option<jiff::Zoned>,
pub last_paused_date: Option<jiff::Timestamp>,
/// Gets or sets the name of the device.
#[serde(rename = "DeviceName")]
pub device_name: Option<String>,
@@ -4699,7 +4760,7 @@ pub struct SongInfo {
#[serde(rename = "ParentIndexNumber")]
pub parent_index_number: Option<i32>,
#[serde(rename = "PremiereDate")]
pub premiere_date: Option<jiff::Zoned>,
pub premiere_date: Option<jiff::Timestamp>,
#[serde(rename = "IsAutomated")]
pub is_automated: bool,
#[serde(rename = "AlbumArtists")]
@@ -4992,10 +5053,10 @@ pub struct TaskInfo {
pub struct TaskResult {
/// Gets or sets the start time UTC.
#[serde(rename = "StartTimeUtc")]
pub start_time_utc: jiff::Zoned,
pub start_time_utc: jiff::Timestamp,
/// Gets or sets the end time UTC.
#[serde(rename = "EndTimeUtc")]
pub end_time_utc: jiff::Zoned,
pub end_time_utc: jiff::Timestamp,
/// Gets or sets the status.
#[serde(rename = "Status")]
pub status: TaskCompletionStatus,
@@ -5121,10 +5182,10 @@ pub struct TimerInfoDto {
pub overview: Option<String>,
/// Gets or sets the start date of the recording, in UTC.
#[serde(rename = "StartDate")]
pub start_date: jiff::Zoned,
pub start_date: jiff::Timestamp,
/// Gets or sets the end date of the recording, in UTC.
#[serde(rename = "EndDate")]
pub end_date: jiff::Zoned,
pub end_date: jiff::Timestamp,
/// Gets or sets the name of the service.
#[serde(rename = "ServiceName")]
pub service_name: Option<String>,
@@ -5208,7 +5269,7 @@ pub struct TrailerInfo {
#[serde(rename = "ParentIndexNumber")]
pub parent_index_number: Option<i32>,
#[serde(rename = "PremiereDate")]
pub premiere_date: Option<jiff::Zoned>,
pub premiere_date: Option<jiff::Timestamp>,
#[serde(rename = "IsAutomated")]
pub is_automated: bool,
}
@@ -5518,7 +5579,7 @@ pub struct UpdateUserItemDataDto {
pub likes: Option<bool>,
/// Gets or sets the last played date.
#[serde(rename = "LastPlayedDate")]
pub last_played_date: Option<jiff::Zoned>,
pub last_played_date: Option<jiff::Timestamp>,
/// Gets or sets a value indicating whether this MediaBrowser.Model.Dto.UserItemDataDto is played.
#[serde(rename = "Played")]
pub played: Option<bool>,
@@ -5674,10 +5735,10 @@ This is not used by the server and is for client-side usage only.*/
pub enable_auto_login: Option<bool>,
/// Gets or sets the last login date.
#[serde(rename = "LastLoginDate")]
pub last_login_date: Option<jiff::Zoned>,
pub last_login_date: Option<jiff::Timestamp>,
/// Gets or sets the last activity date.
#[serde(rename = "LastActivityDate")]
pub last_activity_date: Option<jiff::Zoned>,
pub last_activity_date: Option<jiff::Timestamp>,
/// Gets or sets the configuration.
#[serde(rename = "Configuration")]
pub configuration: Option<UserConfiguration>,
@@ -5714,7 +5775,7 @@ pub struct UserItemDataDto {
pub likes: Option<bool>,
/// Gets or sets the last played date.
#[serde(rename = "LastPlayedDate")]
pub last_played_date: Option<jiff::Zoned>,
pub last_played_date: Option<jiff::Timestamp>,
/// Gets or sets a value indicating whether this MediaBrowser.Model.Dto.UserItemDataDto is played.
#[serde(rename = "Played")]
pub played: bool,
@@ -5854,10 +5915,10 @@ pub struct UserUpdatedMessage {
pub struct UtcTimeResponse {
/// Gets the UTC time when request has been received.
#[serde(rename = "RequestReceptionTime")]
pub request_reception_time: jiff::Zoned,
pub request_reception_time: jiff::Timestamp,
/// Gets the UTC time when response has been sent.
#[serde(rename = "ResponseTransmissionTime")]
pub response_transmission_time: jiff::Zoned,
pub response_transmission_time: jiff::Timestamp,
}
/// Validate path object.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]

View File

@@ -1,5 +1,7 @@
pub mod jellyfin;
use std::sync::Arc;
use ::tap::*;
use reqwest::Method;
use serde::{Deserialize, Serialize};
@@ -12,6 +14,8 @@ pub enum JellyfinApiError {
SerdeError(#[from] serde_json::Error),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Unknown Jellyfin API error")]
Unknown,
}
type Result<T, E = JellyfinApiError> = std::result::Result<T, E>;
@@ -19,8 +23,8 @@ type Result<T, E = JellyfinApiError> = std::result::Result<T, E>;
#[derive(Debug, Clone)]
pub struct JellyfinClient {
client: reqwest::Client,
access_token: Option<String>,
config: JellyfinConfig,
access_token: Option<Arc<str>>,
config: Arc<JellyfinConfig>,
}
impl JellyfinClient {
@@ -28,13 +32,13 @@ impl JellyfinClient {
JellyfinClient {
client: reqwest::Client::new(),
access_token: None,
config,
config: Arc::new(config),
}
}
pub async fn save_token(&self, path: impl AsRef<std::path::Path>) -> std::io::Result<()> {
if let Some(token) = &self.access_token {
tokio::fs::write(path, token).await
tokio::fs::write(path, &**token).await
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
@@ -43,10 +47,17 @@ impl JellyfinClient {
}
}
pub async fn load_token(&mut self, path: impl AsRef<std::path::Path>) -> std::io::Result<()> {
pub async fn load_token(
&mut self,
path: impl AsRef<std::path::Path>,
) -> std::io::Result<String> {
let token = tokio::fs::read_to_string(path).await?;
self.access_token = Some(token);
Ok(())
self.access_token = Some(token.clone().into());
Ok(token)
}
pub async fn set_token(&mut self, token: impl AsRef<str>) {
self.access_token = Some(token.as_ref().into());
}
pub fn request_builder(
@@ -59,7 +70,7 @@ impl JellyfinClient {
.header("X-Emby-Authorization", format!("MediaBrowser Client=\"Jello\", Device=\"Jello\", DeviceId=\"{}\", Version=\"1.0.0\"", self.config.device_id))
.pipe(|builder| {
if let Some(token) = &self.access_token {
builder.header("X-MediaBrowser-Token", token)
builder.header("X-MediaBrowser-Token", &**token)
} else {
builder
}
@@ -118,20 +129,32 @@ impl JellyfinClient {
},
)
.await?;
self.access_token = auth_result.access_token.clone();
self.access_token = auth_result.access_token.clone().map(Into::into);
Ok(auth_result)
}
pub async fn authenticate_with_cached_token(
&mut self,
path: impl AsRef<std::path::Path>,
) -> Result<()> {
) -> Result<String> {
let path = path.as_ref();
if !self.load_token(path).await.is_ok() {
if let Ok(token) = self
.load_token(path)
.await
.inspect_err(|err| tracing::warn!("Failed to load cached token: {}", err))
{
self.authenticate().await?;
self.save_token(path).await?;
Ok(token)
} else {
let token = self
.authenticate()
.await?
.access_token
.ok_or_else(|| JellyfinApiError::Unknown)?;
self.save_token(path).await?;
Ok(token)
}
Ok(())
}
pub async fn raw_items(&self) -> Result<jellyfin::BaseItemDtoQueryResult> {
@@ -148,7 +171,7 @@ impl JellyfinClient {
pub async fn items(
&self,
root: impl Into<Option<String>>,
root: impl Into<Option<uuid::Uuid>>,
) -> Result<Vec<jellyfin::BaseItemDto>> {
let text = &self
.request_builder(Method::GET, "Items")