fix: dont create file storage by default

This commit is contained in:
ThetaDev 2023-04-23 18:32:40 +02:00
parent 24142588a8
commit 8a14a47555

View file

@ -242,9 +242,11 @@ struct RustyPipeOpts {
/// Builder to construct a new RustyPipe client /// Builder to construct a new RustyPipe client
pub struct RustyPipeBuilder { pub struct RustyPipeBuilder {
storage: Option<Box<dyn CacheStorage>>, storage: Option<Box<dyn CacheStorage>>,
no_storage: bool,
reporter: Option<Box<dyn Reporter>>, reporter: Option<Box<dyn Reporter>>,
no_reporter: bool,
n_http_retries: u32, n_http_retries: u32,
user_agent: String, user_agent: Option<String>,
default_opts: RustyPipeOpts, default_opts: RustyPipeOpts,
} }
@ -339,17 +341,19 @@ impl RustyPipeBuilder {
pub fn new() -> Self { pub fn new() -> Self {
RustyPipeBuilder { RustyPipeBuilder {
default_opts: RustyPipeOpts::default(), default_opts: RustyPipeOpts::default(),
storage: Some(Box::<FileStorage>::default()), storage: None,
reporter: Some(Box::<FileReporter>::default()), no_storage: false,
reporter: None,
no_reporter: false,
n_http_retries: 2, n_http_retries: 2,
user_agent: DEFAULT_UA.to_owned(), user_agent: None,
} }
} }
/// Returns a new, configured RustyPipe instance. /// Returns a new, configured RustyPipe instance.
pub fn build(self) -> RustyPipe { pub fn build(self) -> RustyPipe {
let http = ClientBuilder::new() let http = ClientBuilder::new()
.user_agent(self.user_agent) .user_agent(self.user_agent.unwrap_or_else(|| DEFAULT_UA.to_owned()))
.gzip(true) .gzip(true)
.brotli(true) .brotli(true)
.redirect(reqwest::redirect::Policy::none()) .redirect(reqwest::redirect::Policy::none())
@ -375,8 +379,22 @@ impl RustyPipeBuilder {
RustyPipe { RustyPipe {
inner: Arc::new(RustyPipeRef { inner: Arc::new(RustyPipeRef {
http, http,
storage: self.storage, storage: if self.no_storage {
reporter: self.reporter, None
} else {
Some(
self.storage
.unwrap_or_else(|| Box::<FileStorage>::default()),
)
},
reporter: if self.no_reporter {
None
} else {
Some(
self.reporter
.unwrap_or_else(|| Box::<FileReporter>::default()),
)
},
n_http_retries: self.n_http_retries, n_http_retries: self.n_http_retries,
consent_cookie: format!( consent_cookie: format!(
"{}={}{}", "{}={}{}",
@ -394,33 +412,37 @@ impl RustyPipeBuilder {
} }
} }
/// Add a `CacheStorage` backend for persisting cached information /// Add a [`CacheStorage`] backend for persisting cached information
/// (YouTube client versions, deobfuscation code) between /// (YouTube client versions, deobfuscation code) between
/// program executions. /// program executions.
/// ///
/// **Default value**: `FileStorage` in `rustypipe_cache.json` /// **Default value**: [`FileStorage`] in `rustypipe_cache.json`
pub fn storage(mut self, storage: Box<dyn CacheStorage>) -> Self { pub fn storage(mut self, storage: Box<dyn CacheStorage>) -> Self {
self.storage = Some(storage); self.storage = Some(storage);
self.no_storage = false;
self self
} }
/// Disable cache storage /// Disable cache storage
pub fn no_storage(mut self) -> Self { pub fn no_storage(mut self) -> Self {
self.storage = None; self.storage = None;
self.no_storage = true;
self self
} }
/// Add a `Reporter` to collect error details /// Add a `Reporter` to collect error details
/// ///
/// **Default value**: `FileReporter` creating reports in `./rustypipe_reports` /// **Default value**: [`FileReporter`] creating reports in `./rustypipe_reports`
pub fn reporter(mut self, reporter: Box<dyn Reporter>) -> Self { pub fn reporter(mut self, reporter: Box<dyn Reporter>) -> Self {
self.reporter = Some(reporter); self.reporter = Some(reporter);
self.no_reporter = false;
self self
} }
/// Disable the creation of report files in case of errors and warnings. /// Disable the creation of report files in case of errors and warnings.
pub fn no_reporter(mut self) -> Self { pub fn no_reporter(mut self) -> Self {
self.reporter = None; self.reporter = None;
self.no_reporter = true;
self self
} }
@ -442,7 +464,7 @@ impl RustyPipeBuilder {
/// **Default value**: `Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0` /// **Default value**: `Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0`
/// (Firefox ESR on Debian) /// (Firefox ESR on Debian)
pub fn user_agent<S: Into<String>>(mut self, user_agent: S) -> Self { pub fn user_agent<S: Into<String>>(mut self, user_agent: S) -> Self {
self.user_agent = user_agent.into(); self.user_agent = Some(user_agent.into());
self self
} }