feat(api): enhance Jellyfin client with async requests and token mgmt

This commit is contained in:
uttarayan21
2025-11-13 16:11:08 +05:30
parent ffd5562ed3
commit 5425031994
5 changed files with 238 additions and 8 deletions

View File

@@ -1,9 +1,38 @@
mod errors;
use api::{JellyfinClient, JellyfinConfig};
use errors::*;
use gpui::{
div, prelude::*, px, rgb, size, App, Application, Bounds, Context, SharedString, Window,
WindowBounds, WindowOptions,
App, Application, Bounds, Context, SharedString, Window, WindowBounds, WindowOptions, div,
prelude::*, px, rgb, size,
};
pub fn main() {
#[tokio::main]
pub async fn main() -> Result<()> {
dotenvy::dotenv()
.change_context(Error)
.inspect_err(|err| {
eprintln!("Failed to load .env file: {}", err);
})
.ok();
let config = JellyfinConfig::new(
std::env::var("JELLYFIN_USERNAME").change_context(Error)?,
std::env::var("JELLYFIN_PASSWORD").change_context(Error)?,
std::env::var("JELLYFIN_SERVER_URL").change_context(Error)?,
"jello".to_string(),
);
let mut jellyfin = api::JellyfinClient::new(config);
authenticate(&mut jellyfin).await?;
Ok(())
}
pub async fn authenticate(client: &mut JellyfinClient) -> Result<()> {
if std::path::PathBuf::from(".session").exists() {
client.load_token(".session").change_context(Error)?;
} else {
client.authenticate().await.change_context(Error)?;
client.save_token(".session").change_context(Error)?;
}
Ok(())
}