Make multiple requests

This commit is contained in:
ItsDrike 2024-04-18 21:08:33 +02:00
parent e577f01fe1
commit 9cc9f5dd02
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0
2 changed files with 61 additions and 19 deletions

View file

@ -1,4 +1,6 @@
use crate::rentry::{build_client, delete_paste, CSRFData};
use std::collections::VecDeque;
use crate::rentry::{build_client, delete_paste, CSRFData, DeleteError};
mod rentry;
@ -6,23 +8,56 @@ const PASTE_NAME: &str = "Hyprland-controversy";
fn main() {
let client = build_client();
let csrf_data = CSRFData::get(&client, PASTE_NAME);
let mut csrf_data = CSRFData::get(&client, PASTE_NAME);
let edit_code = "f";
let mut edit_codes = VecDeque::from([
"qwack", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u",
"v", "w", "x", "y", "z", "a", "b", "c",
]);
while let Some(edit_code) = edit_codes.pop_front() {
match delete_paste(&client, &csrf_data, edit_code, PASTE_NAME) {
Ok(_) => println!("Paste deleted successfully"),
Ok(_) => {
println!("Paste deleted successfully with edit code: {edit_code}");
return;
}
Err(e) => match e {
rentry::DeleteError::RequestFailure(msg) => eprintln!("Request error (non 2XX): {msg}"),
rentry::DeleteError::UnexpectedRedirect(msg) => eprintln!("Unexpected redirect: {msg}"),
rentry::DeleteError::FormError(msg) => {
if msg == "Invalid edit code." {
eprintln!("Invalid edit code")
} else {
eprintln!("Form error: {msg}")
DeleteError::FormFieldError(msg) if msg == "Invalid edit code." => {
println!("Invalid edit code {edit_code}");
}
DeleteError::FormFieldError(msg) => {
eprintln!("Form error: {msg}");
return;
}
DeleteError::FormError(msg)
if msg == "You have hit the limit, please wait a bit. e345" =>
{
println!("Hit the limit, waiting...");
csrf_data = CSRFData::get(&client, PASTE_NAME);
std::thread::sleep(std::time::Duration::from_secs(30));
edit_codes.push_front(edit_code);
}
DeleteError::FormError(msg) => {
eprintln!("Form error: {msg}");
return;
}
DeleteError::RequestFailure(msg) => {
eprintln!("Request error (non 2XX): {msg}");
return;
}
DeleteError::UnexpectedRedirect(msg) => {
eprintln!("Unexpected redirect: {msg}");
return;
}
DeleteError::UnknownFailure(msg) => {
eprintln!("Unknown failure: {msg}");
return;
}
DeleteError::ReqwestError(e) => {
eprintln!("Request failed with: {e:?}");
return;
}
rentry::DeleteError::UnknownFailure(msg) => eprintln!("Unknown failure: {msg}"),
rentry::DeleteError::ReqwestError(e) => eprintln!("Request failed with: {e:?}"),
},
}
}
}

View file

@ -63,9 +63,10 @@ impl CSRFData {
pub enum DeleteError {
ReqwestError(reqwest::Error),
UnexpectedRedirect(String),
FormError(String),
FormFieldError(String),
RequestFailure(String),
UnknownFailure(String),
FormError(String),
}
impl From<reqwest::Error> for DeleteError {
@ -98,7 +99,13 @@ impl From<Response> for DeleteError {
Selector::parse("fieldset > div.text-danger.messages > ul.errorlist > li").unwrap();
if let Some(element) = document.select(&selector).next() {
let txt = element.text().collect::<String>();
return DeleteError::FormError(txt);
return DeleteError::FormFieldError(txt.trim().to_string());
}
let selector = Selector::parse("form > ul.messages > li.text-error").unwrap();
if let Some(element) = document.select(&selector).next() {
let txt = element.text().collect::<String>();
return DeleteError::FormError(txt.trim().to_string());
}
return DeleteError::UnknownFailure(format!("unknown failure (2XX): {raw_txt}"));