From ab5ce397987bd97c920101a8d393d0fde29b5f74 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Sun, 8 Mar 2026 21:06:39 +0300 Subject: Allow cookies.json in config dir This allows running the program from anywhere, given the cookies are placed in the config dir. --- src/http_client.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/http_client.rs') diff --git a/src/http_client.rs b/src/http_client.rs index 6e06474..e8251d3 100644 --- a/src/http_client.rs +++ b/src/http_client.rs @@ -1,15 +1,16 @@ use anyhow::{Context, Result}; use reqwest::{Client, cookie::Jar}; -use std::{collections::HashMap, fs, sync::Arc}; +use std::{collections::HashMap, fs, path::PathBuf, sync::Arc}; /// Reads the cookies.json file and builds an authenticated reqwest client. -pub fn build_authenticated_client(cookies_path: &str) -> Result { +pub fn build_authenticated_client(cookies_path: &PathBuf) -> Result { // Read the JSON file. - let cookies_content = fs::read_to_string(cookies_path) - .with_context(|| format!("Failed to read cookies file from: {}", cookies_path))?; + println!("Reading cookies from {cookies_path:?}..."); + let cookies_content = fs::read(cookies_path) + .with_context(|| format!("Failed to read cookies file from {cookies_path:?}."))?; // Parse the JSON into a Rust HashMap. - let cookies_map: HashMap = serde_json::from_str(&cookies_content) + let cookies_map: HashMap = serde_json::from_slice(&cookies_content) .context("Failed to parse cookies file. Ensure it is a flat key-value JSON object.")?; // Create a Cookie Jar. -- cgit v1.2.3-70-g09d2