This commit is contained in:
Brandon Thomas committed 2025-10-30 13:23:57 -04:00
1 parent cc9089388f
commit e45f74617c
9 files changed
+81 -41

No files matched your search

@@ -0,0 +1,26 @@
use crate::requests::index_page::pieces::baggage::Baggage;
use crate::requests::index_page::pieces::sentry_trace::SentryTrace;
use crate::requests::index_page::pieces::svg_path_data::SvgPathData;
use crate::requests::index_page::pieces::verification_token::VerificationToken;
use crate::requests::index_page::pieces::xsid_numbers::XsidNumbers;
#[derive(Clone)]
pub struct GrokClientSecrets {
/// Baggage is <meta> tag data from the index.html
pub baggage: Baggage,
/// Baggage is <meta> tag data from the index.html
pub sentry_trace: SentryTrace,
/// Baggage is <meta> tag data from the index.html
pub verification_token: VerificationToken,
/// The SVG path data to use (chosen via verification_token)
/// We selected one of four-ish possible SVG paths (of length >= 200) by
/// the `verification token -> animation index` algo.
pub svg_path_data: SvgPathData,
/// This doesn't come from the index.html
/// These numbers are separately loaded from the xsid javascript
pub numbers: XsidNumbers,
}
@@ -0,0 +1,24 @@
#[derive(Clone)]
pub struct GrokCookies {
/// The entire cookies header (for now)
cookies: String,
}
impl GrokCookies {
pub fn new(cookies: String) -> Self {
Self { cookies }
}
pub fn as_str(&self) -> &str {
&self.cookies
}
pub fn as_bytes(&self) -> &[u8] {
self.cookies.as_bytes()
}
pub fn to_string(&self) -> String {
self.cookies.clone()
}
}
@@ -0,0 +1,15 @@
use crate::credentials::grok_cookies::GrokCookies;
use crate::datatypes::user_email::UserEmail;
use crate::datatypes::user_id::UserId;
/// Includes the cookies and all the magic other bits needed to call the API.
#[derive(Clone)]
pub struct GrokFullCredentials {
pub cookies: GrokCookies,
/// From index.html
pub user_email: Option<UserEmail>,
/// From index.html
pub user_id: Option<UserId>,
}
@@ -0,0 +1,3 @@
pub mod grok_cookies;
pub mod grok_full_credentials;
pub mod grok_client_secrets;
@@ -1,3 +1,4 @@
use crate::credentials::grok_client_secrets::GrokClientSecrets;
use crate::error::grok_error::GrokError;
use crate::error::grok_generic_api_error::GrokGenericApiError;
use crate::requests::index_page::get_index_page_and_scripts::{get_index_page_and_scripts, GetIndexPageAndScriptsArgs};
@@ -8,14 +9,8 @@ use crate::requests::index_page::parsers::index::parse_index_svg_paths::parse_sv
use crate::requests::index_page::parsers::index::parse_index_verification_token::parse_index_verification_token;
use crate::requests::index_page::parsers::script::parse_script_actions_and_xsid_script_path::parse_script_actions_and_xsid_script_path;
use crate::requests::index_page::parsers::script::parse_xsid_script_numbers::parse_xsid_script_numbers;
use crate::requests::index_page::pieces::baggage::Baggage;
use crate::requests::index_page::pieces::sentry_trace::SentryTrace;
use crate::requests::index_page::pieces::svg_path_data::SvgPathData;
use crate::requests::index_page::pieces::verification_token::VerificationToken;
use crate::requests::index_page::pieces::xsid_numbers::XsidNumbers;
use crate::requests::index_page::utils::convert_verification_token_to_loading_anim::convert_verification_token_to_loading_anim;
use crate::requests::index_page::utils::select_svg_path_by_loading_anim::select_svg_path_by_loading_anim;
use std::collections::HashMap;
pub struct RequestClientSecretsArgs<'a> {
pub cookies: &'a str,
@@ -25,31 +20,9 @@ pub struct RequestClientSecretsArgs<'a> {
// 1) baggage -- on index page
// 2) sentry_trace -- on index page
// 3) x_statsig
#[derive(Clone)]
pub struct ClientSecrets {
/// From the index HTML meta tag
pub baggage: Baggage,
/// From the index HTML meta tag
pub sentry_trace: SentryTrace,
/// From the index HTML meta tag
pub verification_token: VerificationToken,
/// The SVG path data to use (chosen via verification_token)
/// We selected one of four-ish possible SVG paths (of length >= 200) by
/// the `verification token -> animation index` algo.
pub svg_path: SvgPathData,
/// Numbers from the xsid script.
pub numbers: XsidNumbers,
// /// Scripts (for later use)
// pub scripts: HashMap<String, String>,
}
/// Load all the things needed to make requests.
pub async fn request_client_secrets(args: RequestClientSecretsArgs<'_>) -> Result<ClientSecrets, GrokError> {
pub async fn request_client_secrets(args: RequestClientSecretsArgs<'_>) -> Result<GrokClientSecrets, GrokError> {
let payloads = get_index_page_and_scripts(GetIndexPageAndScriptsArgs {
cookie: args.cookies,
@@ -81,7 +54,7 @@ pub async fn request_client_secrets(args: RequestClientSecretsArgs<'_>) -> Resul
let loading_anim = convert_verification_token_to_loading_anim(&verification_token)?;
let svg_path = select_svg_path_by_loading_anim(&svg_paths, &loading_anim)?;
let svg_path_data = select_svg_path_by_loading_anim(&svg_paths, &loading_anim)?;
let actions_and_xsid_script = parse_script_actions_and_xsid_script_path(&payloads.scripts)?;
@@ -100,11 +73,11 @@ pub async fn request_client_secrets(args: RequestClientSecretsArgs<'_>) -> Resul
}.into());
}
Ok(ClientSecrets {
Ok(GrokClientSecrets {
baggage,
sentry_trace,
verification_token,
svg_path,
svg_path_data,
numbers,
//scripts: payloads.scripts,
})
@@ -128,7 +101,7 @@ mod tests {
println!("Baggage: {:?}", secrets.baggage);
println!("Sentry trace: {:?}", secrets.sentry_trace);
println!("Verification token: {:?}", secrets.verification_token);
println!("SVG path: {:?}", secrets.svg_path);
println!("SVG path: {:?}", secrets.svg_path_data);
println!("Numbers: {:?}", secrets.numbers);
assert_eq!(1, 2);
@@ -155,7 +155,7 @@ mod tests {
println!("Verification Token: {:?}", secrets.verification_token);
println!("Sentry Trace: {:?}", secrets.sentry_trace);
println!("Numbers: {:?}", secrets.numbers);
println!("Svg Path: {:?}", secrets.svg_path);
println!("Svg Path: {:?}", secrets.svg_path_data);
println!("Baggage: {:?}", secrets.baggage);
let result = upload_image_and_generate_video(UploadImageAndGenerateVideo {
@@ -164,7 +164,7 @@ mod tests {
baggage: &secrets.baggage,
sentry_trace: &secrets.sentry_trace,
verification_token: &secrets.verification_token,
svg_data: &secrets.svg_path,
svg_data: &secrets.svg_path_data,
numbers: &secrets.numbers,
file: FileUploadSpec::Path("/Users/bt/Pictures/People/Ernest/0c120fb0-d6f3-11ec-9737-6f3f233a88c2.jpg"),
prompt: Some("A man in the forest runs away from a spooky ghost"),
@@ -1,7 +1,6 @@
use crate::datatypes::user_id::UserId;
use crate::datatypes::user_email::UserEmail;
use once_cell::sync::Lazy;
use regex::Regex;
use crate::datatypes::user_email::UserEmail;
/// Find the user email in the index.html payload
/// eg.
@@ -171,7 +171,7 @@ mod tests {
println!("Verification Token: {:?}", secrets.verification_token);
println!("Sentry Trace: {:?}", secrets.sentry_trace);
println!("Numbers: {:?}", secrets.numbers);
println!("Svg Path: {:?}", secrets.svg_path);
println!("Svg Path: {:?}", secrets.svg_path_data);
println!("Baggage: {:?}", secrets.baggage);
let request = GrokLikeMediaPost {
@@ -182,7 +182,7 @@ mod tests {
baggage: &secrets.baggage,
sentry_trace: &secrets.sentry_trace,
verification_token: &secrets.verification_token,
svg_data: &secrets.svg_path,
svg_data: &secrets.svg_path_data,
numbers: &secrets.numbers,
};
@@ -218,7 +218,7 @@ mod tests {
println!("Verification Token: {:?}", secrets.verification_token);
println!("Sentry Trace: {:?}", secrets.sentry_trace);
println!("Numbers: {:?}", secrets.numbers);
println!("Svg Path: {:?}", secrets.svg_path);
println!("Svg Path: {:?}", secrets.svg_path_data);
println!("Baggage: {:?}", secrets.baggage);
let request = GrokVideoGenChatConversationBuilder {
@@ -232,7 +232,7 @@ mod tests {
baggage: &secrets.baggage,
sentry_trace: &secrets.sentry_trace,
verification_token: &secrets.verification_token,
svg_data: &secrets.svg_path,
svg_data: &secrets.svg_path_data,
numbers: &secrets.numbers,
};