Don't focus on deletion, just find the edit code
This commit is contained in:
parent
9f000cbdcb
commit
e1d70f424e
20
src/main.rs
20
src/main.rs
|
@ -1,4 +1,4 @@
|
||||||
use crate::rentry::{build_client, delete_paste, CSRFData, DeleteError};
|
use crate::rentry::{build_client, edit_paste, CSRFData, EditError};
|
||||||
|
|
||||||
mod rentry;
|
mod rentry;
|
||||||
|
|
||||||
|
@ -53,20 +53,20 @@ fn main() {
|
||||||
let mut edit_codes = EditCodeGenerator::default();
|
let mut edit_codes = EditCodeGenerator::default();
|
||||||
|
|
||||||
while let Some(edit_code) = edit_codes.next() {
|
while let Some(edit_code) = edit_codes.next() {
|
||||||
match delete_paste(&client, &csrf_data, &edit_code, PASTE_NAME) {
|
match edit_paste(&client, &csrf_data, &edit_code, PASTE_NAME) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
println!("Paste deleted successfully with edit code: {edit_code}");
|
println!("Paste deleted successfully with edit code: {edit_code}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Err(e) => match e {
|
Err(e) => match e {
|
||||||
DeleteError::FormFieldError(msg) if msg == "Invalid edit code." => {
|
EditError::FormFieldError(msg) if msg == "Invalid edit code." => {
|
||||||
println!("Invalid edit code {edit_code}");
|
println!("Invalid edit code {edit_code}");
|
||||||
}
|
}
|
||||||
DeleteError::FormFieldError(msg) => {
|
EditError::FormFieldError(msg) => {
|
||||||
eprintln!("Form error: {msg}");
|
eprintln!("Form error: {msg}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DeleteError::FormError(msg)
|
EditError::FormError(msg)
|
||||||
if msg == "You have hit the limit, please wait a bit. e345" =>
|
if msg == "You have hit the limit, please wait a bit. e345" =>
|
||||||
{
|
{
|
||||||
println!("Hit the limit, waiting...");
|
println!("Hit the limit, waiting...");
|
||||||
|
@ -74,23 +74,23 @@ fn main() {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(30));
|
std::thread::sleep(std::time::Duration::from_secs(30));
|
||||||
edit_codes.retry_last().unwrap();
|
edit_codes.retry_last().unwrap();
|
||||||
}
|
}
|
||||||
DeleteError::FormError(msg) => {
|
EditError::FormError(msg) => {
|
||||||
eprintln!("Form error: {msg}");
|
eprintln!("Form error: {msg}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DeleteError::RequestFailure(msg) => {
|
EditError::RequestFailure(msg) => {
|
||||||
eprintln!("Request error (non 2XX): {msg}");
|
eprintln!("Request error (non 2XX): {msg}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DeleteError::UnexpectedRedirect(msg) => {
|
EditError::UnexpectedRedirect(msg) => {
|
||||||
eprintln!("Unexpected redirect: {msg}");
|
eprintln!("Unexpected redirect: {msg}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DeleteError::UnknownFailure(msg) => {
|
EditError::UnknownFailure(msg) => {
|
||||||
eprintln!("Unknown failure: {msg}");
|
eprintln!("Unknown failure: {msg}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DeleteError::ReqwestError(e) => {
|
EditError::ReqwestError(e) => {
|
||||||
eprintln!("Request failed with: {e:?}");
|
eprintln!("Request failed with: {e:?}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl CSRFData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum DeleteError {
|
pub enum EditError {
|
||||||
ReqwestError(reqwest::Error),
|
ReqwestError(reqwest::Error),
|
||||||
UnexpectedRedirect(String),
|
UnexpectedRedirect(String),
|
||||||
FormFieldError(String),
|
FormFieldError(String),
|
||||||
|
@ -69,13 +69,13 @@ pub enum DeleteError {
|
||||||
FormError(String),
|
FormError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<reqwest::Error> for DeleteError {
|
impl From<reqwest::Error> for EditError {
|
||||||
fn from(err: reqwest::Error) -> Self {
|
fn from(err: reqwest::Error) -> Self {
|
||||||
DeleteError::ReqwestError(err)
|
EditError::ReqwestError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Response> for DeleteError {
|
impl From<Response> for EditError {
|
||||||
fn from(res: Response) -> Self {
|
fn from(res: Response) -> Self {
|
||||||
let status = res.status();
|
let status = res.status();
|
||||||
let headers = res.headers().clone();
|
let headers = res.headers().clone();
|
||||||
|
@ -99,16 +99,16 @@ 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::FormFieldError(txt.trim().to_string());
|
return EditError::FormFieldError(txt.trim().to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
let selector = Selector::parse("form > ul.messages > li.text-error").unwrap();
|
let selector = Selector::parse("form > ul.messages > li.text-error").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.trim().to_string());
|
return EditError::FormError(txt.trim().to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
return DeleteError::UnknownFailure(format!("unknown failure (2XX): {raw_txt}"));
|
return EditError::UnknownFailure(format!("unknown failure (2XX): {raw_txt}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let selector = Selector::parse("span").unwrap();
|
let selector = Selector::parse("span").unwrap();
|
||||||
|
@ -120,16 +120,16 @@ impl From<Response> for DeleteError {
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
let err_txt = err_txt.trim().to_string();
|
let err_txt = err_txt.trim().to_string();
|
||||||
|
|
||||||
DeleteError::RequestFailure(err_txt)
|
EditError::RequestFailure(err_txt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_paste(
|
pub fn edit_paste(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
csrf_data: &CSRFData,
|
csrf_data: &CSRFData,
|
||||||
edit_code: &str,
|
edit_code: &str,
|
||||||
paste_name: &str,
|
paste_name: &str,
|
||||||
) -> Result<(), DeleteError> {
|
) -> Result<(), EditError> {
|
||||||
let url = BASE_URL.to_string() + paste_name + "/edit";
|
let url = BASE_URL.to_string() + paste_name + "/edit";
|
||||||
|
|
||||||
let res = client
|
let res = client
|
||||||
|
@ -145,7 +145,6 @@ pub fn delete_paste(
|
||||||
("new_edit_code", ""),
|
("new_edit_code", ""),
|
||||||
("new_url", ""),
|
("new_url", ""),
|
||||||
("text", ""),
|
("text", ""),
|
||||||
("delete", "delete"),
|
|
||||||
])
|
])
|
||||||
.send()?;
|
.send()?;
|
||||||
|
|
||||||
|
@ -156,7 +155,7 @@ pub fn delete_paste(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(DeleteError::from(res))
|
Err(EditError::from(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_client() -> Client {
|
pub fn build_client() -> Client {
|
||||||
|
|
Loading…
Reference in a new issue