debug logging instead of print

This commit is contained in:
Brandon Thomas committed 2025-10-30 15:00:53 -04:00
1 parent 9386fbbc86
commit 397409c60b
10 files changed
+111 -137

No files matched your search

@@ -1,6 +1,7 @@
use crate::client::browser_user_agents::FIREFOX_143_MAC_USER_AGENT;
use crate::error::grok_client_error::GrokClientError;
use crate::error::grok_error::GrokError;
use log::warn;
use wreq::Client;
const INDEX_URL: &str = "https://grok.com";
@@ -38,12 +39,18 @@ pub async fn get_index_page_script_with_client(args: GetIndexPageScriptArgs<'_>)
let response = builder.send()
.await
.map_err(|err| GrokClientError::WreqClientError(err))?;
let status = response.status();
// TODO: Cloudflare handling.
let body = response.text()
.await
.map_err(|err| GrokClientError::WreqClientError(err))?;
if !status.is_success() {
warn!("could not get index page script: {}, body: {}", status, body);
}
Ok(body)
}
@@ -2,7 +2,7 @@ use crate::client::browser_user_agents::FIREFOX_143_MAC_USER_AGENT;
use crate::error::grok_client_error::GrokClientError;
use crate::error::grok_error::GrokError;
use crate::error::grok_generic_api_error::GrokGenericApiError;
use log::info;
use log::{info, warn};
use std::ops::Deref;
use wreq::header::{ACCEPT, ACCEPT_ENCODING, ACCEPT_LANGUAGE, CACHE_CONTROL, CONNECTION, CONTENT_TYPE, COOKIE, ORIGIN, PRAGMA, REFERER, TE, UPGRADE, USER_AGENT};
use wreq::ws::message::Message;
@@ -44,23 +44,17 @@ pub async fn get_index_page_with_client(args: GetIndexPageWithClientArgs<'_>) ->
.await
.map_err(|err| GrokClientError::WreqClientError(err))?;
//let status = response.status();
//println!("Status: {}", status);
//let body = response.text()
// .await
// .map_err(|err| GrokGenericApiError::WreqError(err))?;
// stblid=08552693-0377-49d3-b17f-8e4c68b153ec
//for cookie in response.cookies() {
// println!("Cookie: {}={}", cookie.name(), cookie.value());
//}
//for (name, value) in response.headers() {
// println!("Header: {}: {}", name.as_str(), value.to_str().unwrap());
//}
let status = response.status();
let body = response.text()
.await
.map_err(|err| GrokClientError::WreqClientError(err))?;
// TODO: Cloudflare handling
if !status.is_success() {
warn!("could not get index page script: {}, body: {}", status, body);
}
Ok(IndexPage {
body,
})
@@ -7,7 +7,7 @@ use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use byteorder::{LittleEndian, WriteBytesExt};
use chrono::{TimeDelta, Utc};
use log::error;
use log::{debug, error};
use sha2::{Digest, Sha256};
use std::ops::Sub;
@@ -63,43 +63,38 @@ pub fn generate_xsid_with_timestamp(timestamp: u32, args: GenerateXsidArgs<'_>)
let n = timestamp - 1682924400;
println!("n = {}", n);
debug!("[xsid] n = {}", n);
// MATCH !
// \x892\xb1\x04 vs
// [137, 50, 177, 4]
let mut t = vec![];
t.write_u32::<LittleEndian>(n).unwrap(); // TODO Unwrap
println!("t = {:?}", t);
debug!("[xsid] t = {:?}", t);
// MATCH !
let r = BASE64_STANDARD.decode(&args.verification_token.0)
.map_err(|err| {
error!("Decode verification_token failed. {}", err);
GrokClientError::FailedToDecodeVerificationToken(err)
})?; // TODO: Not sure this is right.
println!("r = {:?}", r);
debug!("[xsid] r = {:?}", r);
// o = Signature.xs(r, svg, x_values)
let o = signature_xs(&r, &args.svg_data.0, &args.numbers.numbers)?;
// generate_sign.o 4320e30fd70a3d70a3d7028f5c28f5c28f6028f5c28f5c28f60fd70a3d70a3d700
println!("o = {:?}", o);
debug!("[xsid] o = {:?}", o);
//msg = "!".join([method, path, str(n)]) + "obfiowerehiring" + o
// msg = "!".join([method, path, str(n)]) + "obfiowerehiring" + o
let method = args.method;
let path = args.path;
let msg = format!("{method}!{path}!{n}obfiowerehiring{o}");
// POST!/rest/app-chat/conversations/new!78721673obfiowerehiring4320e30fd70a3d70a3d7028f5c28f5c28f6028f5c28f5c28f60fd70a3d70a3d700
println!("msg = {}", msg);
debug!("[xsid] msg = {}", msg);
//digest = sha256(msg.encode('utf-8')).digest()[:16]
let digest_all_bytes = Sha256::digest(msg.as_bytes()).to_vec();
println!("digest_all_bytes = {:?}", digest_all_bytes);
debug!("[xsid] digest_all_bytes = {:?}", digest_all_bytes);
if digest_all_bytes.len() < 16 {
error!("Digest is too short: {}", digest_all_bytes.len());
@@ -108,20 +103,19 @@ pub fn generate_xsid_with_timestamp(timestamp: u32, args: GenerateXsidArgs<'_>)
let digest : &[u8] = &digest_all_bytes[.. 16];
println!("digest = {:?}", digest);
debug!("[xsid] digest = {:?}", digest);
//prefix_byte = int(floor(random() if not random_float else random_float * 256))
// prefix_byte = int(floor(random() if not random_float else random_float * 256))
let prefix_byte = 0; // NB: This is bad code? floor(random) = 0 always.
//assembled = bytes([prefix_byte]) + r + t + digest + bytes([3])
// assembled = bytes([prefix_byte]) + r + t + digest + bytes([3])
let mut assembled = vec![prefix_byte];
assembled.extend(r);
assembled.extend(t);
assembled.extend(digest);
assembled.extend([3]);
println!("assembled = {:?}", assembled);
debug!("[xsid] assembled = {:?}", assembled);
/*
arr = bytearray(assembled)
@@ -144,15 +138,15 @@ pub fn generate_xsid_with_timestamp(timestamp: u32, args: GenerateXsidArgs<'_>)
// }
//}
println!("arr = {:?}", arr);
debug!("[xsid] arr = {:?}", arr);
// Uses + and /
//encoded = b64encode(bytes(arr)).decode('ascii').replace('=', '')
// Uses + and / for base64
// encoded = b64encode(bytes(arr)).decode('ascii').replace('=', '')
let encoded_bytes = BASE64_STANDARD.encode(arr);
let encoded_bytes = encoded_bytes.replace("=", "");
println!("encoded_bytes = {:?}", encoded_bytes);
debug!("[xsid] encoded_bytes = {:?}", encoded_bytes);
Ok(encoded_bytes)
}
@@ -1,3 +1,4 @@
use log::debug;
use crate::error::grok_client_error::GrokClientError;
use crate::requests::index_page::signature::round_two_decimals::round_two_decimals;
/*
@@ -23,21 +24,21 @@ pub fn signature_h(x: f64, param: f64, c: f64, e: bool) -> Result<f64, GrokClien
// f = ((x * (c - _param)) / 255.0) + _param
let f = ((x * (c - param)) / 255.0) + param;
println!("f = {}", f);
debug!("[signature_h] f = {}", f);
if e {
let floor = f.floor();
println!("floor = {}", floor);
debug!("[signature_h] floor = {}", floor);
return Ok(floor)
}
// rounded = round(float(f), 2)
let rounded = round_two_decimals(f);
println!("rounded = {}", rounded);
debug!("[signature_h] rounded = {}", rounded);
if rounded == 0.0 {
println!("rounded is zero");
debug!("[signature_h] rounded is zero");
return Ok(0.0) // TODO: This might not work
}
@@ -1,7 +1,7 @@
use crate::error::grok_client_error::GrokClientError;
use crate::requests::index_page::signature::signature_cubic_bezier_eased::signature_cubic_bezier_eased;
use crate::requests::index_page::signature::signature_h::signature_h;
use log::error;
use log::{debug, error};
use once_cell::sync::Lazy;
use regex::Regex;
use std::fmt::format;
@@ -84,14 +84,12 @@ pub fn signature_simulate_style(values: &[u32], c: u32) -> Result<SimulatedStyle
// currentTime = round(c / 10.0) * 10
let current_time = ((c as f32 / 10.0).round()) as u32 * 10;
// > currentTime 900
println!("current_time = {:?}", current_time);
debug!("[simulate_style] current_time = {:?}", current_time);
// t = currentTime / duration
let t = current_time as f64 / duration as f64;
// > t 0.2197265625
println!("t = {:?}", t);
debug!("[simulate_style] t = {:?}", t);
// cp = [Signature._h(v, -1 if (i % 2) else 0, 1, False) for i, v in enumerate(values[7:])]
let subvalues = &values[7..];
@@ -102,8 +100,7 @@ pub fn signature_simulate_style(values: &[u32], c: u32) -> Result<SimulatedStyle
cp.push(val);
}
// > cp [0.05, -0.23, 0.95, 0.05]
println!("cp = {:?}", cp);
debug!("[simulate_style] cp = {:?}", cp);
// easedY = Signature.cubicBezierEased(t, cp[0], cp[1], cp[2], cp[3])
let cp_0 = cp.get(0).map(|x| *x).ok_or_else(|| GrokClientError::BadSignatureInputs)?;
@@ -112,8 +109,7 @@ pub fn signature_simulate_style(values: &[u32], c: u32) -> Result<SimulatedStyle
let cp_3 = cp.get(3).map(|x| *x).ok_or_else(|| GrokClientError::BadSignatureInputs)?;
let eased_y = signature_cubic_bezier_eased(t, cp_0, cp_1, cp_2, cp_3);
// > easedY -0.06687371608353283
println!("eased_y = {:?}", eased_y);
debug!("[simulate_style] eased_y = {:?}", eased_y);
// NB: Safety
if values.len() < 6 {
@@ -127,10 +123,8 @@ pub fn signature_simulate_style(values: &[u32], c: u32) -> Result<SimulatedStyle
// end = [float(x) for x in values[3:6]]
let end = values[3..6].iter().map(|x| *x as f64).collect::<Vec<_>>();
// > start [73.0, 44.0, 215.0]
// > end [158.0, 218.0, 29.0]
println!("start = {:?}", start);
println!("end = {:?}", end);
debug!("[simulate_style] start = {:?}", start);
debug!("[simulate_style] end = {:?}", end);
// r = round(start[0] + (end[0] - start[0]) * easedY)
// g = round(start[1] + (end[1] - start[1]) * easedY)
@@ -143,41 +137,32 @@ pub fn signature_simulate_style(values: &[u32], c: u32) -> Result<SimulatedStyle
// color = f"rgb({r}, {g}, {b})"
let color = format!("rgb({r}, {g}, {b})");
// > r 67
// > g 32
// > b 227
// > color rgb(67, 32, 227)
println!("color = {:?}", color);
debug!("[simulate_style] color = {:?}", color);
// endAngle = Signature._h(values[6], 60, 360, True)
let value_6 = values.get(6).map(|v| *v as f64).ok_or_else(|| GrokClientError::BadSignatureInputs)?;
let end_angle = signature_h(value_6, 60.0, 360.0, true)?;
// > endAngle 140
println!("end_angle = {:?}", end_angle);
debug!("[simulate_style] end_angle = {:?}", end_angle);
// angle = endAngle * easedY
let angle = end_angle * eased_y;
// > angle -9.362320251694596
println!("angle = {:?}", angle);
debug!("[simulate_style] angle = {:?}", angle);
// rad = angle * pi / 180.0
let pi = std::f64::consts::PI;
let rad = angle * pi / 180.0;
// > rad -0.16340331401821492
println!("rad = {:?}", rad);
debug!("[simulate_style] rad = {:?}", rad);
// cosv = cos(rad)
// sinv = sin(rad)
let cosv = rad.cos();
let sinv = rad.sin();
// > cosv 0.9866793572390504
// > sinv -0.16267712192663833
println!("cosv = {:?}", cosv);
println!("sinv = {:?}", sinv);
debug!("[simulate_style] cosv = {:?}", cosv);
debug!("[simulate_style] sinv = {:?}", sinv);
/*
if is_effectively_zero(cosv):
@@ -253,20 +238,15 @@ pub fn signature_simulate_style(values: &[u32], c: u32) -> Result<SimulatedStyle
}
}
// > a 0.986679
// > d 0.986679
// > bval -0.1626771
// > cval 0.1626771
println!("a = {}", a);
println!("d = {}", d);
println!("bval = {}", bval);
println!("cval = {}", cval);
debug!("[simulate_style] a = {}", a);
debug!("[simulate_style] d = {}", d);
debug!("[simulate_style] bval = {}", bval);
debug!("[simulate_style] cval = {}", cval);
// transform = f"matrix({a}, {bval}, {cval}, {d}, 0, 0)"
let transform = format!("matrix({a}, {bval}, {cval}, {d}, 0, 0)");
// transform matrix(0.986679, -0.1626771, 0.1626771, 0.986679, 0, 0)
println!("transform = {:?}", transform);
debug!("[simulate_style] transform = {:?}", transform);
Ok(SimulatedStyle {
color,
@@ -1,3 +1,4 @@
use log::debug;
use crate::error::grok_client_error::GrokClientError;
use crate::requests::index_page::signature::round_two_decimals::round_two_decimals;
@@ -33,7 +34,7 @@ pub fn signature_to_hex(num: f64) -> Result<String, GrokClientError> {
// rounded = round(float(num), 2)
let rounded = round_two_decimals(num);
println!("rounded = {}", rounded);
debug!("[to_hex] rounded = {}", rounded);
if rounded == 0.0 {
return Ok("0".to_string());
@@ -43,22 +44,22 @@ pub fn signature_to_hex(num: f64) -> Result<String, GrokClientError> {
let test = 1.0f64.copysign(rounded);
let sign = if test < 0.0 { "-" } else { "" };
println!("sign = {}", sign);
debug!("[to_hex] sign = {}", sign);
let absval = rounded.abs();
let intpart = absval.floor() as u32;
println!("absval = {}", absval);
println!("intpart = {}", intpart);
debug!("[to_hex] absval = {}", absval);
debug!("[to_hex] intpart = {}", intpart);
let frac = absval - (intpart as f64);
println!("frac = {}", frac);
debug!("[to_hex] frac = {}", frac);
if frac == 0.0 {
// return sign + format(intpart, "x") -- this is hex formatting
let ret = format!("{sign}{intpart:x}");
println!("return = {}", ret);
debug!("[to_hex] return = {}", ret);
return Ok(ret);
}
@@ -103,18 +104,18 @@ pub fn signature_to_hex(num: f64) -> Result<String, GrokClientError> {
let frac_str = frac_digits.join("");
let frac_str = frac_str.trim_end_matches('0');
println!("frac_str = {}", frac_str);
debug!("[to_hex] frac_str = {}", frac_str);
if frac_str.is_empty() {
// return sign + format(intpart, "x")
let ret = format!("{sign}{intpart:x}");
println!("return = {}", ret);
debug!("[to_hex] return = {}", ret);
return Ok(ret);
}
// return sign + format(intpart, "x") + "." + frac_str
let ret = format!("{sign}{intpart:x}.{frac_str}");
println!("return = {}", ret);
debug!("[to_hex] return = {}", ret);
Ok(ret)
}
@@ -1,6 +1,7 @@
use crate::error::grok_client_error::GrokClientError;
use log::debug;
use once_cell::sync::Lazy;
use regex::Regex;
use crate::error::grok_client_error::GrokClientError;
static CLEAN_NON_DIGIT_REGEX : Lazy<Regex> = Lazy::new(|| {
Regex::new(r#"[^\d]+"#)
@@ -29,24 +30,24 @@ static CLEAN_NON_DIGIT_REGEX : Lazy<Regex> = Lazy::new(|| {
pub fn signature_xa(svg_data: &str) -> Result<Vec<Vec<u32>>, GrokClientError> {
// s = (svg) -- not this is needed, looks like a NO-OP to me.
let s = svg_data;
println!("s.len() ={}", s.len());
debug!("[xa] s.len() ={}", s.len());
// substr = s[9:]
let substr = &s[9..];
println!("Substr ={}", substr);
println!("substr.len() ={}", substr.len());
debug!("[xa] substr ={}", substr);
debug!("[xa] substr.len() ={}", substr.len());
// parts = substr.split("C")
let parts = substr.split("C").collect::<Vec<_>>();
println!("parts.len() = {}", parts.len());
println!("parts = {:?}", parts);
debug!("[xa] parts.len() = {}", parts.len());
debug!("[xa] parts = {:?}", parts);
let mut out = Vec::new();
for part in parts {
// cleaned = sub(r"[^\d]+", " ", part).strip()
let cleaned = CLEAN_NON_DIGIT_REGEX.replace_all(part, " ").to_string().trim().to_string();
println!("cleaned len = {} value = {}", cleaned.len(), cleaned);
debug!("[xa] cleaned len = {} value = {}", cleaned.len(), cleaned);
let mut nums;
if cleaned == "" {
// nums = [0]
@@ -60,7 +61,8 @@ pub fn signature_xa(svg_data: &str) -> Result<Vec<Vec<u32>>, GrokClientError> {
}
out.push(nums);
}
println!("out = {:?}", out);
debug!("[xa] out = {:?}", out);
Ok(out)
}
@@ -1,10 +1,10 @@
use log::error;
use crate::error::grok_client_error::GrokClientError;
use crate::requests::index_page::signature::signature_simulate_style::signature_simulate_style;
use crate::requests::index_page::signature::signature_to_hex::signature_to_hex;
use crate::requests::index_page::signature::signature_xa::signature_xa;
use log::{debug, error};
use once_cell::sync::Lazy;
use regex::Regex;
use crate::requests::index_page::signature::signature_to_hex::signature_to_hex;
static NUMBER_REGEX : Lazy<Regex> = Lazy::new(|| {
Regex::new(r#"[\d\.\-]+"#)
@@ -38,15 +38,6 @@ static NUMBER_REGEX : Lazy<Regex> = Lazy::new(|| {
/// `svg_data` is the <path d="" /> svg path stroke data
/// `x_values` are the magic numbers from the script
pub fn signature_xs(x_bytes: &[u8], svg_data: &str, x_values: &[u32]) -> Result<String, GrokClientError> {
/*
Inputs:
> xs.x_bytes = b'\xca\xddz\th\x94#\x8d\xac\xef\x01\x86x\xcc\\tB\x13\xdah\x8f\x17\x93\xd58fE\xd4\x97\x1a{\xb2\xbb\x1c\xc4+-\xe28E6.~g_\x04\x86T'
> xs.svg = M 10,30 C 147,16 51,222 136,87 h 31 s 177,77 40,114 C 68,166 18,188 114,44 h 220 s 148,210 202,25 C 220,36 246,218 12,120 h 244 s 34,154 56,161 C 211,204 208,60 174,14 h 155 s 157,116 220,95 C 116,164 53,210 174,232 h 139 s 148,151 135,221 C 167,196 118,27 149,247 h 233 s 129,238 113,21 C 73,44 215,158 218,29 h 68 s 13,98 243,134 C 44,98 149,35 20,178 h 163 s 219,104 41,152 C 237,107 118,120 127,117 h 57 s 41,167 43,136 C 116,168 44,246 182,209 h 143 s 238,93 237,119 C 142,36 64,67 97,111 h 71 s 230,247 119,27 C 206,56 158,51 71,115 h 135 s 120,186 74,57 C 197,165 180,214 102,16 h 88 s 252,48 189,166 C 163,237 57,253 154,60 h 96 s 84,56 15,66 C 177,101 10,202 185,227 h 29 s 204,55 115,219 C 103,82 127,143 194,99 h 102 s 179,63 84,110
> xs.x_values = [40, 18, 3, 18]
Arr becomes:
xs.arr = [202, 221, 122, 9, 104, 148, 35, 141, 172, 239, 1, 134, 120, 204, 92, 116, 66, 19, 218, 104, 143, 23, 147, 213, 56, 102, 69, 212, 151, 26, 123, 178, 187, 28, 196, 43, 45, 226, 56, 69, 54, 46, 126, 103, 95, 4, 134, 84]
*/
// arr = list(x_bytes) -- we already have this as the input
let arr = x_bytes;
@@ -55,7 +46,7 @@ xs.arr = [202, 221, 122, 9, 104, 148, 35, 141, 172, 239, 1, 134, 120, 204, 92, 1
let a = arr.get(i).map(|x| *x).ok_or_else(|| GrokClientError::BadSignatureInputs)?;
let idx = a % 16;
println!("idx = {}", idx);
debug!("[xs] idx = {}", idx);
// c = ((arr[x_values[1]] % 16) * (arr[x_values[2]] % 16)) * (arr[x_values[3]] % 16)
let xv1 = ith_usize(x_values, 1)?;
@@ -66,7 +57,7 @@ xs.arr = [202, 221, 122, 9, 104, 148, 35, 141, 172, 239, 1, 134, 120, 204, 92, 1
let av3 = ith_u32(arr, xv3)? % 16;
let c = av1 * av2 * av3; // Max value: 4096 (16x16x16)
println!("c = {}", c);
debug!("[xs] c = {}", c);
// o = Signature.xa(svg)
let o = signature_xa(svg_data)?;
@@ -74,18 +65,14 @@ xs.arr = [202, 221, 122, 9, 104, 148, 35, 141, 172, 239, 1, 134, 120, 204, 92, 1
// vals = o[idx]
let vals = o.get(idx as usize).ok_or_else(|| GrokClientError::BadSignatureInputs)?;
// > xs.vals.len = 11
// > xs.vals = [73, 44, 215, 158, 218, 29, 68, 13, 98, 243, 134]
println!("vals.len = {:?}", vals.len());
println!("vals = {:?}", vals);
debug!("[xs] vals.len = {:?}", vals.len());
debug!("[xs] vals = {:?}", vals);
// k = Signature.simulateStyle(vals, c)
let k = signature_simulate_style(vals, c)?;
// > xs.k.color = rgb(67, 32, 227)
// > xs.k.transform = matrix(0.986679, -0.1626771, 0.1626771, 0.986679, 0, 0)
println!("k.color = {}", &k.color);
println!("k.transform = {}", &k.transform);
debug!("[xs] k.color = {}", &k.color);
debug!("[xs] k.transform = {}", &k.transform);
/*
concat = str(k["color"]) + str(k["transform"])
@@ -103,8 +90,7 @@ xs.arr = [202, 221, 122, 9, 104, 148, 35, 141, 172, 239, 1, 134, 120, 204, 92, 1
// concat = str(k["color"]) + str(k["transform"])
let concat = format!("{}{}", k.color, k.transform);
// > xs.concat = rgb(67, 32, 227)matrix(0.986679, -0.1626771, 0.1626771, 0.986679, 0, 0)
println!("concat = {}", concat);
debug!("[xs] concat = {}", concat);
// matches = findall(r"[\d\.\-]+", concat)
let matches = NUMBER_REGEX.captures_iter(&concat)
@@ -112,8 +98,7 @@ xs.arr = [202, 221, 122, 9, 104, 148, 35, 141, 172, 239, 1, 134, 120, 204, 92, 1
.map(|m| m.as_str().to_string())
.collect::<Vec<_>>();
// > xs.matches = ['67', '32', '227', '0.986679', '-0.1626771', '0.1626771', '0.986679', '0', '0']
println!("matches = {:?}", matches);
debug!("[xs] matches = {:?}", matches);
/*
converted = []
@@ -140,10 +125,8 @@ xs.arr = [202, 221, 122, 9, 104, 148, 35, 141, 172, 239, 1, 134, 120, 204, 92, 1
let joined = converted.join("");
let cleaned = joined.replace(".", "").replace("-", "");
// > xs.joined = 4320e30.fd70a3d70a3d7-0.28f5c28f5c28f60.28f5c28f5c28f60.fd70a3d70a3d700
println!("joined = {}", joined);
// > xs.cleaned = 4320e30fd70a3d70a3d7028f5c28f5c28f6028f5c28f5c28f60fd70a3d70a3d700
println!("cleaned = {}", cleaned);
debug!("[xs] joined = {}", joined);
debug!("[xs] cleaned = {}", cleaned);
Ok(cleaned)
}
@@ -2,7 +2,7 @@ use crate::datatypes::api::verification_token::VerificationToken;
use crate::error::grok_client_error::GrokClientError;
use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use log::error;
use log::{debug, error};
#[derive(Debug, Clone)]
pub struct LoadingAnim(pub(crate) usize);
@@ -28,6 +28,8 @@ pub fn convert_verification_token_to_loading_anim(verification_token: &Verificat
let byte = decoded_bytes.get(5)
.map(|byte| *byte)
.ok_or(GrokClientError::InvalidVerificationTokenBytes)?;
debug!("verification token byte: {}", byte);
// note, we'll put the string construction in the `to_id()` method since we need the raw integer again
let anim = (byte % 4) as usize;
@@ -27,7 +27,6 @@ pub struct GrokVideoGenChatConversationBuilder<'a> {
pub file_id: &'a FileId,
pub media_type: VideoMediaPostType,
pub prompt: Option<&'a str>,
pub request_timeout: Option<Duration>,
pub cookie: &'a str,
pub user_id: &'a UserId,
@@ -37,6 +36,8 @@ pub struct GrokVideoGenChatConversationBuilder<'a> {
pub verification_token: &'a VerificationToken,
pub svg_data: &'a SvgPathData,
pub numbers: &'a XsidNumbers,
pub request_timeout: Option<Duration>,
}
#[derive(Debug, Copy, Clone)]
@@ -174,19 +175,16 @@ impl <'a> GrokVideoGenChatConversationBuilder<'a> {
GrokGenericApiError::WreqError(err)
})?;
// TODO: Handle unsuccessful request
if !status.is_success() {
warn!("Not successful enqueuing video gen: {:?}", response_body);
warn!("Not successful enqueuing video gen (code: {}) : {:?}", status.as_u16(), response_body);
// error!("Upload file request returned an error (code {}) : {:?}", status.as_u16(), response_body);
// return Err(classify_general_http_status_code_and_body(status, response_body));
}
// TODO: Just for now...
info!("Video Body: {:?}", response_body);
// TODO:
//if !status.is_success() {
// error!("Upload file request returned an error (code {}) : {:?}", status.as_u16(), response_body);
// return Err(classify_general_http_status_code_and_body(status, response_body));
//}
//let response : GrokApiUploadFileResponse = serde_json::from_str(response_body)
// .map_err(|err| GrokGenericApiError::SerdeResponseParseErrorWithBody(err, response_body.to_string()))?;
@@ -198,6 +196,7 @@ impl <'a> GrokVideoGenChatConversationBuilder<'a> {
#[cfg(test)]
mod tests {
use super::*;
use crate::datatypes::file_upload_spec::FileUploadSpec;
use crate::recipes::request_client_secrets::{request_client_secrets, RequestClientSecretsArgs};
use crate::test_utils::get_test_cookies::get_typed_test_cookies;
use errors::AnyhowResult;
@@ -209,12 +208,22 @@ mod tests {
let cookies = get_typed_test_cookies()?;
let file_id = FileId("990ddf90-8f34-42b1-81a5-39c509d62ff7".to_string()); // Mochi
let secrets = request_client_secrets(RequestClientSecretsArgs {
cookies: &cookies,
}).await?;
//let file_id = FileId("990ddf90-8f34-42b1-81a5-39c509d62ff7".to_string()); // Mochi
let upload_request = GrokUploadFile {
file: FileUploadSpec::Path("/Users/bt/dev/storyteller/storyteller-rust/test_data/image/mochi.jpg"),
cookie: cookies.to_string(),
request_timeout: None,
};
let upload_result = upload_request.upload().await?;
let file_id = upload_result.file_id.expect("upload should have file_id");
println!("Verification Token: {:?}", secrets.verification_token);
println!("Sentry Trace: {:?}", secrets.sentry_trace);
println!("Numbers: {:?}", secrets.numbers);
@@ -222,18 +231,19 @@ mod tests {
println!("Baggage: {:?}", secrets.baggage);
let request = GrokVideoGenChatConversationBuilder {
user_id: &secrets.user_id,
file_id: &file_id,
media_type: VideoMediaPostType::UserUploadedImage,
cookie: cookies.as_str(),
prompt: Some("dog shakes the glasses off"),
request_timeout: None,
cookie: cookies.as_str(),
user_id: &secrets.user_id,
baggage: &secrets.baggage,
sentry_trace: &secrets.sentry_trace,
verification_token: &secrets.verification_token,
svg_data: &secrets.svg_path_data,
numbers: &secrets.numbers,
request_timeout: None,
};
let result = request.send().await?;