mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
fetch user id
This commit is contained in:
1 parent
e92bf8c0cb
commit
a906bcf1be
5 files changed
+58
-6
No files matched your search
@@ -1,4 +1,5 @@
|
||||
|
||||
/// Type for User IDs.
|
||||
/// User IDs are UUIDs.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UserId(pub String);
|
||||
@@ -44,8 +44,8 @@ pub struct ClientSecrets {
|
||||
/// Numbers from the xsid script.
|
||||
pub numbers: XsidNumbers,
|
||||
|
||||
/// Scripts (for later use)
|
||||
pub scripts: HashMap<String, String>,
|
||||
// /// Scripts (for later use)
|
||||
// pub scripts: HashMap<String, String>,
|
||||
}
|
||||
|
||||
/// Load all the things needed to make requests.
|
||||
@@ -106,7 +106,7 @@ pub async fn request_client_secrets(args: RequestClientSecretsArgs<'_>) -> Resul
|
||||
verification_token,
|
||||
svg_path,
|
||||
numbers,
|
||||
scripts: payloads.scripts,
|
||||
//scripts: payloads.scripts,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -4,3 +4,4 @@ pub mod parse_index_script_list;
|
||||
pub mod parse_index_sentry_trace;
|
||||
pub mod parse_index_svg_paths;
|
||||
pub mod parse_index_verification_token;
|
||||
mod parse_index_user_id;
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
use crate::datatypes::user_id::UserId;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
|
||||
/// Find the user id in the index.html payload
|
||||
/// eg. \"userId\":\"85980643-ffab-4984-a3de-59a608c47d7f\",
|
||||
static JSON_REGEX: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(r#"\\?"userI[dD]\\?":\s*\\?"([a-zA-Z0-9-]{25,})\\?",?"#)
|
||||
.expect("Regex should parse")
|
||||
});
|
||||
|
||||
/// Parse the user id from the index.html
|
||||
pub fn parse_index_user_id(html: &str) -> Option<UserId> {
|
||||
let maybe_meta = scrape_user_id_via_regex(html);
|
||||
|
||||
if let Some(meta) = maybe_meta {
|
||||
return Some(UserId(meta))
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn scrape_user_id_via_regex(html: &str) -> Option<String> {
|
||||
let captures = JSON_REGEX.captures(html)?;
|
||||
let capture = captures.get(1)?;
|
||||
Some(capture.as_str().to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::requests::index_page::get_index_page::{get_index, GetIndexPageArgs};
|
||||
use crate::requests::index_page::parsers::index::parse_index_user_id::parse_index_user_id;
|
||||
use crate::test_utils::get_test_cookies::get_test_cookies;
|
||||
use errors::AnyhowResult;
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore] // Manual test invocation
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
let cookie = get_test_cookies()?;
|
||||
let index = get_index(GetIndexPageArgs {
|
||||
cookie: &cookie,
|
||||
}).await?;
|
||||
|
||||
let user_id = parse_index_user_id(&index.body);
|
||||
println!("User ID : {:?}", user_id);
|
||||
|
||||
assert_eq!(1, 2);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -24,14 +24,14 @@ const CHAT_CONVERSATION_URL: &str = "https://grok.com/rest/app-chat/conversation
|
||||
|
||||
/// Request builder
|
||||
pub struct GrokVideoGenChatConversationBuilder<'a> {
|
||||
pub user_id: &'a UserId,
|
||||
pub file_id: &'a FileId,
|
||||
pub media_type: VideoMediaPostType,
|
||||
pub cookie: &'a str,
|
||||
// TODO: Optional prompt
|
||||
pub prompt: Option<&'a str>,
|
||||
pub request_timeout: Option<Duration>,
|
||||
|
||||
pub cookie: &'a str,
|
||||
pub user_id: &'a UserId,
|
||||
|
||||
pub baggage: &'a Baggage,
|
||||
pub sentry_trace: &'a SentryTrace,
|
||||
pub verification_token: &'a VerificationToken,
|
||||
|
||||
Reference in new issue
Block a user