Skip to content

Commit 9e8de9c

Browse files
Version 3.0 beta 3 (final beta)
Changes (only in beta 3): - Implemented token support (GitHub personal access token) to work better with the GitHub API and increase the number of requests available to the user (--gh <personal access token>) - Added a UserAgent for requests to the GitHub API (--ua <user-agent>) - Added a new "gru-classic" tool (--tool gru-classic) that allows you to use the built-in GRU progress bar with a design from the first version of the GRU utility (version 1.x.x) - Checking 7-Zip files for existence (7z.exe , 7z.dll ), if the user has extracted only the executable file from the archive for some reason. gru.exe - A new argument --ghost has been added, which allows you to search for asset matches not in one release, but in several recent ones, if a developer publishes different applications in the same repository in different releases. - Updated user-agent (Chrome version) - The help text has been updated, and information has been returned that the AI, for some reason, considered unnecessary and deleted. - Minor improvements and corrections. - Added information about the planned version 3.1 (most likely not in 2025, but I can't say anything for sure right now)
1 parent 232dff5 commit 9e8de9c

File tree

4 files changed

+58
-56
lines changed

4 files changed

+58
-56
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "gru"
3-
version = "3.0.0-pre2-beta3"
3+
version = "3.0.0-beta3"
44
edition = "2021"
55
authors = ["Zalexanninev15 <blue.shark@disroot.org>"]
66
license = "MIT License"
@@ -14,13 +14,13 @@ winconsole = "0.11.1"
1414
press-btn-continue = "0.2.0"
1515
arguments = "0.8.0"
1616
isahc = "1.7.2"
17-
serde_json = { version = "1.0.137", default-features = false, features = [
17+
serde_json = { version = "1.0.138", default-features = false, features = [
1818
"alloc",
1919
] }
2020
trauma = "2.2.4"
2121
console = "0.15.8"
2222
tokio = "1.36.0"
23-
winapi = { version = "0.3", features = [
23+
winapi = { version = "0.3.9", features = [
2424
"winnt",
2525
"handleapi",
2626
"processthreadsapi",

src/json.rs

+43-42
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
use isahc::ReadResponseExt;
1+
use isahc::prelude::*;
2+
use isahc::{ Request, ReadResponseExt };
23
use serde_json::Value;
34

45
pub fn parse_data(
56
repo: &str,
67
search_words: &str,
78
pre: &bool,
8-
one_release: &bool
9+
one_release: &bool,
10+
ua: &str,
11+
api_key: Option<&str>
912
) -> (String, String) {
1013
if *pre == false {
1114
return fetch_and_parse_release(
1215
&format!("https://api.github.com/repos/{}/releases/latest", repo),
1316
search_words,
14-
one_release
17+
one_release,
18+
ua,
19+
api_key
1520
);
1621
}
17-
// When pre=true, fetch all releases at once
22+
1823
let releases = fetch_and_parse_releases(
19-
&format!("https://api.github.com/repos/{}/releases", repo)
24+
&format!("https://api.github.com/repos/{}/releases", repo),
25+
ua,
26+
api_key
2027
);
2128

2229
let releases_array = match releases.as_array() {
@@ -25,16 +32,16 @@ pub fn parse_data(
2532
return fetch_and_parse_release(
2633
&format!("https://api.github.com/repos/{}/releases/latest", repo),
2734
search_words,
28-
one_release
35+
one_release,
36+
ua,
37+
api_key
2938
);
3039
}
3140
};
3241

3342
if *one_release {
34-
// Original behavior: Find latest stable and pre-release
3543
let (stable, prerelease) = find_latest_releases(releases_array);
3644

37-
// Determine which release to use based on dates
3845
let selected_release = match (stable, prerelease) {
3946
(Some(stable), Some(pre)) => {
4047
let pre_date = pre["published_at"].as_str().unwrap_or("");
@@ -54,7 +61,6 @@ pub fn parse_data(
5461

5562
parse_text(&serde_json::to_string(selected_release).unwrap(), search_words)
5663
} else {
57-
// New behavior: Search through multiple releases
5864
for release in releases_array {
5965
if let Some(assets) = release["assets"].as_array() {
6066
for asset in assets {
@@ -69,23 +75,41 @@ pub fn parse_data(
6975
}
7076
}
7177
}
72-
// If no matching asset is found in any release
7378
(String::new(), String::from("app.zip"))
7479
}
7580
}
7681

77-
fn fetch_and_parse_release(url: &str, search_words: &str, one_release: &bool) -> (String, String) {
82+
fn create_github_request(url: &str, ua: &str, api_key: Option<&str>) -> Request<()> {
83+
let mut builder = Request::builder().uri(url).header("User-Agent", format!("{}", ua));
84+
85+
if let Some(key) = api_key {
86+
builder = builder
87+
.header("Accept", "application/vnd.github+json")
88+
.header("Authorization", format!("Bearer {}", key))
89+
.header("X-GitHub-Api-Version", "2022-11-28");
90+
}
91+
92+
builder.body(()).expect("Failed to create request")
93+
}
94+
95+
fn fetch_and_parse_release(
96+
url: &str,
97+
search_words: &str,
98+
one_release: &bool,
99+
ua: &str,
100+
api_key: Option<&str>
101+
) -> (String, String) {
78102
if *one_release {
79-
let json = isahc
80-
::get(url)
103+
let request = create_github_request(url, ua, api_key);
104+
let json = request
105+
.send()
81106
.expect("GitHub API: Error 404")
82107
.text()
83108
.expect("GitHub API: Json lost");
84109
parse_text(&json, search_words)
85110
} else {
86-
// For multi-release search, we need to get all releases
87111
let releases_url = url.replace("/latest", "");
88-
let releases = fetch_and_parse_releases(&releases_url);
112+
let releases = fetch_and_parse_releases(&releases_url, ua, api_key);
89113

90114
if let Some(releases_array) = releases.as_array() {
91115
for release in releases_array {
@@ -107,39 +131,16 @@ fn fetch_and_parse_release(url: &str, search_words: &str, one_release: &bool) ->
107131
}
108132
}
109133

110-
fn fetch_and_parse_releases(url: &str) -> Value {
111-
let json = isahc
112-
::get(url)
134+
fn fetch_and_parse_releases(url: &str, ua: &str, api_key: Option<&str>) -> Value {
135+
let request = create_github_request(url, ua, api_key);
136+
let json = request
137+
.send()
113138
.expect("GitHub API: Error 404")
114139
.text()
115140
.expect("GitHub API: Json lost");
116141
serde_json::from_str(&json).expect("GitHub API: Error parsing json")
117142
}
118143

119-
// Version 3.1 ???
120-
/* extern crate reqwest;
121-
use reqwest::header;
122-
123-
fn main() -> Result<(), Box<dyn std::error::Error>> {
124-
let mut headers = header::HeaderMap::new();
125-
headers.insert("Accept", "application/vnd.github+json".parse().unwrap());
126-
headers.insert("Authorization", "Bearer sssssss".parse().unwrap());
127-
headers.insert("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36".parse().unwrap());
128-
headers.insert("X-GitHub-Api-Version", "2022-11-28".parse().unwrap());
129-
130-
let client = reqwest::blocking::Client::builder()
131-
.redirect(reqwest::redirect::Policy::none())
132-
.build()
133-
.unwrap();
134-
let res = client.get("https://api.github.com/repos/obsproject/obs-studio/releases/latest")
135-
.headers(headers)
136-
.send()?
137-
.text()?;
138-
println!("{}", res);
139-
140-
Ok(())
141-
} */
142-
143144
fn find_latest_releases(releases: &[Value]) -> (Option<&Value>, Option<&Value>) {
144145
let mut latest_stable = None;
145146
let mut latest_prerelease = None;

src/main.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ fn main() {
9999
let tool = arguments.get::<String>("tool").unwrap_or("gru".to_string());
100100
let d_link = arguments.get::<String>("link").unwrap_or("null".to_string());
101101
let mut no_ghost = arguments.get::<bool>("ghost").unwrap_or(false);
102+
let api_token = arguments.get::<String>("gh").unwrap_or("null".to_string());
102103
let ua = arguments
103104
.get::<String>("ua")
104105
.unwrap_or(
@@ -140,6 +141,7 @@ fn main() {
140141
println!("[Debug] wgetrc = {}", wgetrc);
141142
println!("[Debug] show_pre = {}", show_pre);
142143
println!("[Debug] no_ghost = {}", no_ghost);
144+
println!("[Debug] api_token = {}", api_token);
143145
press_btn_continue::wait("[Debug] Press Enter to continue...").unwrap();
144146
}
145147

@@ -154,13 +156,12 @@ fn main() {
154156
first_launch = true;
155157
}
156158

159+
let (v_list_version, mut v_list_asset) = if api_token == "null" {
160+
json::parse_data(&repo, &part, &show_pre, &no_ghost, &ua, None)
161+
} else {
162+
json::parse_data(&repo, &part, &show_pre, &no_ghost, &ua, Some(&api_token))
163+
};
157164
// Getting the new version release
158-
let (v_list_version, mut v_list_asset) = json::parse_data(
159-
&repo,
160-
&part,
161-
&show_pre,
162-
&no_ghost
163-
);
164165

165166
if debug_mode {
166167
println!("\n[Debug] v_list_version = \"{}\"", v_list_version);
@@ -355,17 +356,17 @@ OPTIONS:
355356
Default: 'gru'.
356357
--link <url> Sometimes releases may not contain assets to download, but just be a place for a list of changes (what's new?).
357358
Set the download link (direct) to the release in other place. Default: null.
358-
--ua <user-agent> Specify a user-agent for better download speed. The argument applies only to the 'curl' and 'wget' tools.
359+
--ua <user-agent> Specify a user-agent for better download speed. The argument applies to the 'curl' and 'wget' tools and GitHub API requests.
359360
Default: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36.
361+
--gh <personal access token> Use a Personal access token to request access to GitHub if there are problems with access on the GitHub
362+
side due to restrictions imposed by them.
363+
Get personal access token: https://github.com/settings/personal-access-tokens
360364
--wgetrc / --no-wgetrc Use config file for 'wget' (.wgetrc). Default: --no-wgetrc.
361365
--pre / --no-pre Use a pre-release instead of a stable release (if there are no stable releases or the unstable release was released after the stable release and is the most recent).
362366
Default: --no-pre.
363367
--ghost / --no-ghost Search for matching assets across multiple recent releases instead of only the latest one. Default: --no-ghost.
364368
--debug / --no-debug Enable debug mode. Default: --no-debug.
365369
[Version 3.1 Preview Arguments (not supported now)]
366-
--gh <personal access token> Use a Personal access token to request access to GitHub if there are problems with access on the GitHub
367-
side due to restrictions imposed by them.
368-
Get personal access token: https://github.com/settings/personal-access-tokens
369370
--nuget / --no-nuget Enabling the correct operation mode with nuget packages, which include the release of the downloaded application itself.
370371
371372
EXAMPLES:

0 commit comments

Comments
 (0)