Skip to content

Commit b99f425

Browse files
authored
🏖️ 0.9.0 - Introducing Sandbox-mode
2 parents 3e0c898 + 72c98cf commit b99f425

File tree

6 files changed

+49
-15
lines changed

6 files changed

+49
-15
lines changed

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ services:
7373
- MAX_DOWNLOAD_TIME=2h # 1d, 6h, 30m, etc.. (Optional) default: 2h
7474
- IGNORE_ABOVE_SIZE=25GB # 1TB, 1GB, 1MB, etc.. (Optional) default: 25GB
7575
- REMOVE_FROM_CLIENT=true # Boolean (Optional) default: true
76+
- DRY_RUN=false # Boolean (Optional) default: false
7677

7778
# -- (Optional)
7879
sonarr:
@@ -88,6 +89,7 @@ services:
8889
- MAX_DOWNLOAD_TIME=2h # 1d, 6h, 30m, etc.. (Optional) default: 2h
8990
- IGNORE_ABOVE_SIZE=25GB # 1TB, 1GB, 1MB, etc.. (Optional) default: 25GB
9091
- REMOVE_FROM_CLIENT=true # Boolean (Optional) default: true
92+
- DRY_RUN=false # Boolean (Optional) default: false
9193
```
9294
9395
<details>
@@ -112,6 +114,7 @@ services:
112114
- MAX_DOWNLOAD_TIME=2h # 1d, 6h, 30m, etc.. (Optional) default: 2h
113115
- IGNORE_ABOVE_SIZE=25GB # 1TB, 1GB, 1MB, etc.. (Optional) default: 25GB
114116
- REMOVE_FROM_CLIENT=true # Boolean (Optional) default: true
117+
- DRY_RUN=false # Boolean (Optional) default: false
115118

116119
# -- (Optional)
117120
sonarr:
@@ -127,6 +130,7 @@ services:
127130
- MAX_DOWNLOAD_TIME=2h # 1d, 6h, 30m, etc.. (Optional) default: 2h
128131
- IGNORE_ABOVE_SIZE=25GB # 1TB, 1GB, 1MB, etc.. (Optional) default: 25GB
129132
- REMOVE_FROM_CLIENT=true # Boolean (Optional) default: true
133+
- DRY_RUN=false # Boolean (Optional) default: false
130134

131135
# -- (Optional)
132136
lidarr:
@@ -142,6 +146,7 @@ services:
142146
- MAX_DOWNLOAD_TIME=2h # 1d, 6h, 30m, etc.. (Optional) default: 2h
143147
- IGNORE_ABOVE_SIZE=25GB # 1TB, 1GB, 1MB, etc.. (Optional) default: 25GB
144148
- REMOVE_FROM_CLIENT=true # Boolean (Optional) default: true
149+
- DRY_RUN=false # Boolean (Optional) default: false
145150

146151
# -- (Optional)
147152
readarr:
@@ -157,6 +162,7 @@ services:
157162
- MAX_DOWNLOAD_TIME=2h # 1d, 6h, 30m, etc.. (Optional) default: 2h
158163
- IGNORE_ABOVE_SIZE=25GB # 1TB, 1GB, 1MB, etc.. (Optional) default: 25GB
159164
- REMOVE_FROM_CLIENT=true # Boolean (Optional) default: true
165+
- DRY_RUN=false # Boolean (Optional) default: false
160166

161167
# -- (Optional)
162168
whisparr:
@@ -172,6 +178,7 @@ services:
172178
- MAX_DOWNLOAD_TIME=2h # 1d, 6h, 30m, etc.. (Optional) default: 2h
173179
- IGNORE_ABOVE_SIZE=25GB # 1TB, 1GB, 1MB, etc.. (Optional) default: 25GB
174180
- REMOVE_FROM_CLIENT=true # Boolean (Optional) default: true
181+
- DRY_RUN=false # Boolean (Optional) default: false
175182
```
176183
</details>
177184
@@ -247,6 +254,7 @@ A brief rundown to shed light on a couple of things for you:
247254
| MAX_DOWNLOAD_TIME | `2h` | Maximum allowed download time before it's considered stalled. |
248255
| IGNORE_ABOVE_SIZE | `25GB` | Files larger than this size will be ignored and not monitored. |
249256
| REMOVE_FROM_CLIENT | `true` | Remove from both queue and download client (default) OR `false` only the queue of a starr instance. |
257+
| DRY_RUN | `false` | Sandbox mode; try Swaparr without it performing destructive actions on your instances. |
250258
</details>
251259

252260
<details>
@@ -260,7 +268,7 @@ A brief rundown to shed light on a couple of things for you:
260268
| `Striked` | Download flagged as slow or stalled; may be removed if it continues to accumulate strikes. |
261269
| `Removed` | Download has been attempted to be removed from the starr instance. |
262270
| `Ignored` | Download is not monitored because it falls outside the set thresholds (e.g., size or time limits). |
263-
| `Queued` | Download is in the queue waiting to start; will not be striked. |
271+
| `Queued` | Download is in the queue within the download client waiting to start; will not be striked. |
264272
</details>
265273

266274

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
- MAX_DOWNLOAD_TIME=2h # 1d, 6h, 30m, etc.. (Optional) default: 2h
1515
- IGNORE_ABOVE_SIZE=25GB # 1TB, 1GB, 1MB, etc.. (Optional) default: 25GB
1616
- REMOVE_FROM_CLIENT=true # Boolean (Optional) default: true
17+
- DRY_RUN=false # Boolean (Optional) default: false
1718

1819
# -- (Optional)
1920
sonarr:
@@ -29,3 +30,4 @@ services:
2930
- MAX_DOWNLOAD_TIME=2h # 1d, 6h, 30m, etc.. (Optional) default: 2h
3031
- IGNORE_ABOVE_SIZE=25GB # 1TB, 1GB, 1MB, etc.. (Optional) default: 25GB
3132
- REMOVE_FROM_CLIENT=true # Boolean (Optional) default: true
33+
- DRY_RUN=false # Boolean (Optional) default: false

src/queue.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ pub fn process(
158158
let max_download_time_ms =
159159
utils::parse::string_time_notation_to_ms(&env.max_download_time).unwrap() as u64;
160160

161-
if download.status == "metadata" || download.eta >= max_download_time_ms || (download.eta == 0 && download.status != "queued") {
161+
if download.status == "metadata"
162+
|| download.eta >= max_download_time_ms
163+
|| (download.eta == 0 && download.status != "queued")
164+
{
162165
if strikes < env.max_strikes {
163166
strikes += 1;
164167
strikelist.insert(id, strikes);
@@ -167,10 +170,12 @@ pub fn process(
167170
}
168171

169172
if strikes >= env.max_strikes {
170-
delete(&format!(
171-
"{}queue/{}?apikey={}&blocklist={}&removeFromClient={}",
172-
baseapi, id, env.apikey, true, env.remove_from_client
173-
));
173+
if env.dry_run == "false" {
174+
delete(&format!(
175+
"{}queue/{}?apikey={}&blocklist={}&removeFromClient={}",
176+
baseapi, id, env.apikey, true, env.remove_from_client
177+
));
178+
}
174179
state = String::from("Removed");
175180
}
176181
}
@@ -187,4 +192,8 @@ pub fn process(
187192
}
188193

189194
libs::table::render(&table_contents);
195+
196+
if &env.dry_run == "true" {
197+
println!(" ─ Dry-run mode enabled, no actions will be taken.");
198+
}
190199
}

src/utils/log.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn alert(method: &str, title: &str, message: &str, error: Option<String>) {
1919
}
2020

2121
pub fn banner(env: &utils::system::Envs) {
22+
// Yes, a lot of printlines, but it looks better like this.
2223
println!("\n ── Swaparr ───── \n");
2324
println!("╭─╮ Platform: {}", &env.platform);
2425
println!("│ │ Max strikes: {}", &env.max_strikes);
@@ -27,9 +28,13 @@ pub fn banner(env: &utils::system::Envs) {
2728
println!("│ │ Ignore above size: {}", &env.ignore_above_size);
2829
println!("╰─╯ Remove from client: {}\n", &env.remove_from_client);
2930

31+
if &env.dry_run == "true" {
32+
println!("╭─╮ Dry-run: true");
33+
println!("╰─╯ All destructive actions are negated.\n");
34+
}
35+
3036
// Open-Source = ❤️
31-
println!("╭─╮ Has Swaparr been useful and do you like open-source projects?");
32-
println!("│ │ Then please do consider to star the repository on GitHub.");
33-
println!("╰─╯ Your gesture means a lot and will help improve Swaparr!");
37+
println!("╭─╮ Be part of Swaparr's journey ⭐ Star us on GitHub!");
38+
println!("╰─╯ Your support strengthens the open-source community.");
3439
println!("\n ──────────────── \n")
3540
}

src/utils/parse.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ pub fn baseapi(platform: &str, baseurl: &str) -> String {
8383

8484
// Returns the API endpoint based on platform.
8585
pub fn queueapi(platform: &str, baseapi: &str, apikey: &str) -> String {
86+
let default_page_size = 256;
8687
match platform {
87-
"radarr" => format!("{baseapi}queue?includeUnknownMovieItems=true&includeMovie=true&apikey={apikey}"),
88-
"sonarr" => format!("{baseapi}queue?includeUnknownSeriesItems=true&includeSeries=true&apikey={apikey}"),
89-
"lidarr" => format!("{baseapi}queue?includeUnknownArtistItems=true&includeArtist=true&includeAlbum=true&apikey={apikey}"),
90-
"readarr" => format!("{baseapi}queue?includeUnknownAuthorItems=true&includeAuthor=true&includeBook=true&apikey={apikey}"),
91-
"whisparr" => format!("{baseapi}queue?includeUnknownSeriesItems=true&includeSeries=true&includeEpisode=true&apikey={apikey}"),
88+
"radarr" => format!("{baseapi}queue?includeUnknownMovieItems=true&includeMovie=true&pageSize={default_page_size}&apikey={apikey}"),
89+
"sonarr" => format!("{baseapi}queue?includeUnknownSeriesItems=true&includeSeries=true&pageSize={default_page_size}&apikey={apikey}"),
90+
"lidarr" => format!("{baseapi}queue?includeUnknownArtistItems=true&includeArtist=true&includeAlbum=true&pageSize={default_page_size}&apikey={apikey}"),
91+
"readarr" => format!("{baseapi}queue?includeUnknownAuthorItems=true&includeAuthor=true&includeBook=true&pageSize={default_page_size}&apikey={apikey}"),
92+
"whisparr" => format!("{baseapi}queue?includeUnknownSeriesItems=true&includeSeries=true&includeEpisode=true&pageSize={default_page_size}&apikey={apikey}"),
9293
_ => {
9394
utils::log::alert(
9495
"FATAL",

src/utils/system.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub struct Envs {
1212
pub max_download_time: String,
1313
pub ignore_above_size: String,
1414
pub remove_from_client: String,
15+
pub dry_run: String,
1516
}
1617

1718
// Voids provided vars and returns a default value.
@@ -82,7 +83,15 @@ pub fn env() -> Envs {
8283
.unwrap_or_else(|_| default("REMOVE_FROM_CLIENT", "true", false)),
8384
) {
8485
Ok(value) => value.to_string(),
85-
Err(_) => default("REMOVE_FROM_CLIENT", "true", true).to_string()
86+
Err(_) => default("REMOVE_FROM_CLIENT", "true", true).to_string(),
87+
},
88+
89+
dry_run: match utils::parse::string_to_bool(
90+
env::var("DRY_RUN")
91+
.unwrap_or_else(|_| default("DRY_RUN", "false", false)),
92+
) {
93+
Ok(value) => value.to_string(),
94+
Err(_) => default("DRY_RUN", "false", true).to_string(),
8695
},
8796
};
8897

0 commit comments

Comments
 (0)