Skip to content

Commit

Permalink
feat!: add missing tinfoil keys back to CLI, require them in lib
Browse files Browse the repository at this point in the history
This adds googleApiKey, headers back as CLI flags and adds google_api_key, oneficher_api_keys & headers back in the generate_index lib function
  • Loading branch information
DevYukine committed Nov 21, 2023
1 parent a87ad00 commit e7ec20f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
30 changes: 30 additions & 0 deletions rustfoil-cli/src/cli/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub trait IndexCommand {
fn public_key(&self) -> Option<PathBuf>;
fn success(&self) -> Option<String>;
fn referrer(&self) -> Option<String>;
fn google_api_key(&self) -> Option<String>;
fn headers(&self) -> Option<Vec<String>>;
fn min_version(&self) -> Option<f32>;
fn theme_blacklist(&self) -> Option<Vec<String>>;
fn theme_whitelist(&self) -> Option<Vec<String>>;
Expand Down Expand Up @@ -75,6 +77,14 @@ pub struct GoogleDriveCommand {
#[arg(long)]
pub referrer: Option<String>,

/// Google API Key to use for Google Drive API requests, this is not the same as OAuth!
#[arg(long)]
pub google_api_key: Option<String>,

/// specified custom HTTP headers which should be sent by tinfoil requests
#[arg(long)]
pub headers: Option<Vec<String>>,

/// Adds a minimum Tinfoil version to load the index
#[arg(long)]
pub min_version: Option<f32>,
Expand Down Expand Up @@ -176,6 +186,10 @@ pub struct HttpCommand {
#[arg(long)]
pub referrer: Option<String>,

/// specified custom HTTP headers which should be sent by tinfoil requests
#[arg(long)]
pub headers: Option<Vec<String>>,

/// Adds a minimum Tinfoil version to load the index
#[arg(long)]
pub min_version: Option<f32>,
Expand Down Expand Up @@ -230,6 +244,14 @@ impl IndexCommand for GoogleDriveCommand {
self.referrer.clone()
}

fn google_api_key(&self) -> Option<String> {
self.google_api_key.clone()
}

fn headers(&self) -> Option<Vec<String>> {
self.headers.clone()
}

fn min_version(&self) -> Option<f32> {
self.min_version
}
Expand Down Expand Up @@ -284,6 +306,14 @@ impl IndexCommand for HttpCommand {
self.referrer.clone()
}

fn google_api_key(&self) -> Option<String> {
None
}

fn headers(&self) -> Option<Vec<String>> {
self.headers.clone()
}

fn min_version(&self) -> Option<f32> {
self.min_version
}
Expand Down
6 changes: 5 additions & 1 deletion rustfoil-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,13 @@ where
debug!("{} of {} passed filters", filtered.len(), file_count);

let index = tinfoil_service.generate_index(
&filtered,
Some(&filtered),
None,
command.success(),
command.referrer(),
command.google_api_key(),
None,
command.headers(),
command.min_version(),
command.theme_blacklist(),
command.theme_whitelist(),
Expand Down
4 changes: 2 additions & 2 deletions rustfoil-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustfoil-lib"
version = "0.4.2"
version = "1.0.0"
description = "A library for creating Index files for Tinfoil from Google Drive or local files."
authors = ["DevYukine <[email protected]>"]
edition = "2021"
Expand All @@ -26,4 +26,4 @@ rsa = "^0.9"
sha2 = "^0.10"
regex = "^1.10"
lazy_static = "^1.4"
urlencoding = "^2.1"
urlencoding = "^2.1"
26 changes: 18 additions & 8 deletions rustfoil-lib/src/tinfoil/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ impl TinfoilService {

pub fn generate_index<F>(
&self,
files: &Vec<F>,
files: Option<&Vec<F>>,
directories: Option<Vec<String>>,
success: Option<String>,
referrer: Option<String>,
google_api_key: Option<String>,
oneficher_api_keys: Option<Vec<String>>,
headers: Option<Vec<String>>,
min_version: Option<f32>,
theme_blacklist: Option<Vec<String>>,
theme_whitelist: Option<Vec<String>>,
Expand All @@ -28,19 +32,25 @@ impl TinfoilService {
{
let mut index = TinfoilIndex::new();

index.files = Some(Vec::new());
if let Some(files) = files {
index.files = Some(Vec::new());

for file in files {
let tinfoil_file = TinfoilFile {
url: file.get_url(),
size: file.get_size(),
};
for file in files {
let tinfoil_file = TinfoilFile {
url: file.get_url(),
size: file.get_size(),
};

index.add_file(tinfoil_file);
index.add_file(tinfoil_file);
}
}

index.directories = directories;
index.success = success;
index.referrer = referrer;
index.google_api_key = google_api_key;
index.one_fichier_keys = oneficher_api_keys;
index.headers = headers;
index.version = min_version;
index.theme_black_list = theme_blacklist;
index.theme_white_list = theme_whitelist;
Expand Down

0 comments on commit e7ec20f

Please sign in to comment.