fix better????

Signed-off-by: Xe Iaso <me@christine.website>
This commit is contained in:
Cadey Ratio 2022-04-05 21:02:14 -04:00
parent ea8e1e045a
commit 6b771b5503
2 changed files with 14 additions and 3 deletions

View File

@ -125,14 +125,16 @@ pub struct Links {
impl Client { impl Client {
pub fn new() -> Result<Self> { pub fn new() -> Result<Self> {
let mut creds = Credentials::default();
let p = Path::new(".patreon.json"); let p = Path::new(".patreon.json");
let config = fs::read_to_string(p)?; let config = fs::read_to_string(p)?;
let creds: Credentials = serde_json::from_str(&config)?; creds = serde_json::from_str(&config)?;
Ok(Self { Ok(Self {
cli: reqwest::Client::new(), cli: reqwest::Client::new(),
base_url: "https://api.patreon.com".into(), base_url: "https://api.patreon.com".into(),
creds, creds: creds,
}) })
} }

View File

@ -1,7 +1,10 @@
use crate::{post::Post, signalboost::Person}; use crate::{post::Post, signalboost::Person};
use color_eyre::eyre::Result; use color_eyre::eyre::Result;
use serde::Deserialize; use serde::Deserialize;
use std::{fs, path::PathBuf}; use std::{
fs,
path::{Path, PathBuf},
};
use tracing::{error, instrument}; use tracing::{error, instrument};
pub mod markdown; pub mod markdown;
@ -18,6 +21,12 @@ pub struct Config {
#[instrument] #[instrument]
async fn patrons() -> Result<Option<patreon::Users>> { async fn patrons() -> Result<Option<patreon::Users>> {
let p = Path::new(".patreon.json");
if !p.exists() {
info!("{:?} does not exist", p);
return Ok(None);
}
let mut cli = patreon::Client::new()?; let mut cli = patreon::Client::new()?;
if let Err(why) = cli.refresh_token().await { if let Err(why) = cli.refresh_token().await {