feat(api): enhance Jellyfin client with async requests and token mgmt
This commit is contained in:
35
src/main.rs
35
src/main.rs
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user