Make multiple requests
This commit is contained in:
parent
e577f01fe1
commit
9cc9f5dd02
61
src/main.rs
61
src/main.rs
|
@ -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;
|
mod rentry;
|
||||||
|
|
||||||
|
@ -6,23 +8,56 @@ const PASTE_NAME: &str = "Hyprland-controversy";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let client = build_client();
|
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) {
|
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 {
|
Err(e) => match e {
|
||||||
rentry::DeleteError::RequestFailure(msg) => eprintln!("Request error (non 2XX): {msg}"),
|
DeleteError::FormFieldError(msg) if msg == "Invalid edit code." => {
|
||||||
rentry::DeleteError::UnexpectedRedirect(msg) => eprintln!("Unexpected redirect: {msg}"),
|
println!("Invalid edit code {edit_code}");
|
||||||
rentry::DeleteError::FormError(msg) => {
|
|
||||||
if msg == "Invalid edit code." {
|
|
||||||
eprintln!("Invalid edit code")
|
|
||||||
} else {
|
|
||||||
eprintln!("Form error: {msg}")
|
|
||||||
}
|
}
|
||||||
|
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:?}"),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -63,9 +63,10 @@ impl CSRFData {
|
||||||
pub enum DeleteError {
|
pub enum DeleteError {
|
||||||
ReqwestError(reqwest::Error),
|
ReqwestError(reqwest::Error),
|
||||||
UnexpectedRedirect(String),
|
UnexpectedRedirect(String),
|
||||||
FormError(String),
|
FormFieldError(String),
|
||||||
RequestFailure(String),
|
RequestFailure(String),
|
||||||
UnknownFailure(String),
|
UnknownFailure(String),
|
||||||
|
FormError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<reqwest::Error> for DeleteError {
|
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();
|
Selector::parse("fieldset > div.text-danger.messages > ul.errorlist > li").unwrap();
|
||||||
if let Some(element) = document.select(&selector).next() {
|
if let Some(element) = document.select(&selector).next() {
|
||||||
let txt = element.text().collect::<String>();
|
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}"));
|
return DeleteError::UnknownFailure(format!("unknown failure (2XX): {raw_txt}"));
|
||||||
|
|
Loading…
Reference in a new issue