Browse Source

Handle boosts

pull/1/head
Toromino 1 year ago
parent
commit
bcf0fa9a33
2 changed files with 46 additions and 13 deletions
  1. 4
    4
      Cargo.toml
  2. 42
    9
      src/main.rs

+ 4
- 4
Cargo.toml View File

@@ -5,9 +5,9 @@ authors = ["Toromino <foxhkron@toromino.de>"]
5 5
 edition = "2018"
6 6
 
7 7
 [dependencies]
8
-chrono = { version = "0.4", features = ["serde"] }
8
+chrono = { version = "0.4.10", features = ["serde"] }
9 9
 getopts = "0.2.21"
10 10
 reqwest = { version = "0.10.1", features = ["json"] }
11
-serde = { version = "1.0", features = ["derive"] }
12
-serde_json = "1.0"
13
-tokio = { version = "0.2", features = ["full"] }
11
+serde = { version = "1.0.104", features = ["derive"] }
12
+serde_json = "1.0.44"
13
+tokio = { version = "0.2.9", features = ["full"] }

+ 42
- 9
src/main.rs View File

@@ -49,17 +49,34 @@ impl Credentials {
49 49
 struct Status {
50 50
     id: String,
51 51
     created_at: String,
52
+    reblog: Option<Box<Status>>,
52 53
 }
53 54
 
54 55
 impl Status {
55 56
     async fn delete(&self, client: &reqwest::Client, url: &str, token: &str) {
56
-        client
57
-            .delete(&format!("https://{}/api/v1/statuses/{}", url, &self.id))
58
-            .header("Authorization", &format!("Bearer {}", &token))
59
-            .send()
60
-            .await
61
-            .expect("An error occured while deleting a status");
62
-        println!("Successfully deleted status '{}'", &self.id);
57
+        match &self.reblog {
58
+            Some(reblog) => {
59
+                client
60
+                    .delete(&format!(
61
+                        "https://{}/api/v1/statuses/{}/unreblog",
62
+                        url, &reblog.id
63
+                    ))
64
+                    .header("Authorization", &format!("Bearer {}", &token))
65
+                    .send()
66
+                    .await
67
+                    .expect("An error occured while deleting a share");
68
+                println!("Successfully deleted share of '{}'", &reblog.id);
69
+            }
70
+            None => {
71
+                client
72
+                    .delete(&format!("https://{}/api/v1/statuses/{}", url, &self.id))
73
+                    .header("Authorization", &format!("Bearer {}", &token))
74
+                    .send()
75
+                    .await
76
+                    .expect("An error occured while deleting a status");
77
+                println!("Successfully deleted status '{}'", &self.id);
78
+            }
79
+        }
63 80
     }
64 81
 }
65 82
 
@@ -274,6 +291,20 @@ async fn main() {
274 291
     );
275 292
 
276 293
     let timestamp = prompt().parse::<NaiveDate>().unwrap();
294
+
295
+    println!("Should Pubcleaner also delete shares/boosts/announces? (y/N)");
296
+    let delete_shares = if &prompt() == "y" { true } else { false };
297
+
298
+    let fmt_shares = if delete_shares { " and shares" } else { "" };
299
+
300
+    println!(
301
+        "You want to delete statuses{} older than {}. Is that correct? (y/N)",
302
+        fmt_shares, &timestamp
303
+    );
304
+    println!("WARNING: All data will be deleted PERMANENTLY!");
305
+    if prompt() != "y" {
306
+        panic!("Aborted!")
307
+    };
277 308
     let mut counter: i32 = 0;
278 309
     let mut last_largest_id: Option<String> = None;
279 310
     loop {
@@ -288,8 +319,10 @@ async fn main() {
288 319
                 .timestamp()
289 320
                 < NaiveDateTime::new(timestamp, NaiveTime::from_hms(0, 0, 0)).timestamp()
290 321
             {
291
-                status.delete(&client, &url, &access_token).await;
292
-                counter += 1;
322
+                if (delete_shares && status.reblog.is_some()) || status.reblog.is_none() {
323
+                    status.delete(&client, &url, &access_token).await;
324
+                    counter += 1;
325
+                }
293 326
             }
294 327
         }
295 328
 

Loading…
Cancel
Save