Make multiple requests
This commit is contained in:
parent
e577f01fe1
commit
9cc9f5dd02
69
src/main.rs
69
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([
|
||||||
match delete_paste(&client, &csrf_data, edit_code, PASTE_NAME) {
|
"qwack", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u",
|
||||||
Ok(_) => println!("Paste deleted successfully"),
|
"v", "w", "x", "y", "z", "a", "b", "c",
|
||||||
Err(e) => match e {
|
]);
|
||||||
rentry::DeleteError::RequestFailure(msg) => eprintln!("Request error (non 2XX): {msg}"),
|
|
||||||
rentry::DeleteError::UnexpectedRedirect(msg) => eprintln!("Unexpected redirect: {msg}"),
|
while let Some(edit_code) = edit_codes.pop_front() {
|
||||||
rentry::DeleteError::FormError(msg) => {
|
match delete_paste(&client, &csrf_data, edit_code, PASTE_NAME) {
|
||||||
if msg == "Invalid edit code." {
|
Ok(_) => {
|
||||||
eprintln!("Invalid edit code")
|
println!("Paste deleted successfully with edit code: {edit_code}");
|
||||||
} else {
|
return;
|
||||||
eprintln!("Form error: {msg}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rentry::DeleteError::UnknownFailure(msg) => eprintln!("Unknown failure: {msg}"),
|
Err(e) => match e {
|
||||||
rentry::DeleteError::ReqwestError(e) => eprintln!("Request failed with: {e:?}"),
|
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;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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