Skip to content

Commit accf866

Browse files
committed
#149 ability to set default value for limit param for search query
1 parent 21611bf commit accf866

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

README.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,25 @@ Telegram bot interface for downloading content via Prowlarr.
1111

1212
Configuration is done through environment variables.
1313

14-
| Variable | Description | Mandatory | Default |
15-
|-----------------------|--------------------------------------------------------------------------------------------------------------|--------------------------------------|-----------------|
16-
| ALLOWED_USERS | Comma separated list of telegram user ids, who are allowed to use the bot. | | Anyone |
17-
| COMPLETE_IP | IP to bind the complete webhook to. | | 0.0.0.0 |
18-
| COMPLETE_PORT | TCP port to listen for download completion requests. | | |
19-
| PROWLARR_API_KEY | API key to access Prowlarr. | if PROWLARR_API_KEY_FILE isn't set | |
20-
| PROWLARR_API_KEY_FILE | Path to a file with API key to access Prowlarr. | if PROWLARR_API_KEY isn't set | |
21-
| PROWLARR_BASE_URL | e.g. http://localhost:9696 | | |
22-
| PROWLARR_INDEXER_IDS | Comma separated list of Prowlarr indexer ids to use. | | |
23-
| REDIS_URL | Redis URL, to use as a store for link mappings. If not set, a non-persistent in-memory storage will be used. | | |
24-
| REDIS_SEQUENCE_START | First id value to use. | | 1000 |
25-
| REDIS_KEY_EXPIRATION | When mappings will expire. | | 604800 (1 week) |
26-
| RUST_LOG | Minimal log level. | | info |
27-
| TELOXIDE_PROXY | Proxy to use for connecting to Telegram, e.g. socks5://localhost:9000 | | |
28-
| TELOXIDE_TOKEN | Telegram bot token (from [@BotFather](https://t.me/BotFather) bot) | Yes | |
29-
| WEBHOOK_IP | IP to bind the Telegram webhook to. | | 0.0.0.0 |
30-
| WEBHOOK_PORT | Port on which the bot will be listening for requests from Telegram. | For non-polling telegram interaction | |
31-
| WEBHOOK_URL | Example: https://<app-name>.herokuapp.com:443 | For non-polling telegram interaction | |
14+
| Variable | Description | Mandatory | Default |
15+
|------------------------------|--------------------------------------------------------------------------------------------------------------|--------------------------------------|-----------------|
16+
| ALLOWED_USERS | Comma separated list of telegram user ids, who are allowed to use the bot. | | Anyone |
17+
| COMPLETE_IP | IP to bind the complete webhook to. | | 0.0.0.0 |
18+
| COMPLETE_PORT | TCP port to listen for download completion requests. | | |
19+
| PROWLARR_API_KEY | API key to access Prowlarr. | if PROWLARR_API_KEY_FILE isn't set | |
20+
| PROWLARR_API_KEY_FILE | Path to a file with API key to access Prowlarr. | if PROWLARR_API_KEY isn't set | |
21+
| PROWLARR_BASE_URL | e.g. http://localhost:9696 | | |
22+
| PROWLARR_DEFAULT_LIMIT_PARAM | e.g. 100 | | |
23+
| PROWLARR_INDEXER_IDS | Comma separated list of Prowlarr indexer ids to use. | | |
24+
| REDIS_URL | Redis URL, to use as a store for link mappings. If not set, a non-persistent in-memory storage will be used. | | |
25+
| REDIS_SEQUENCE_START | First id value to use. | | 1000 |
26+
| REDIS_KEY_EXPIRATION | When mappings will expire. | | 604800 (1 week) |
27+
| RUST_LOG | Minimal log level. | | info |
28+
| TELOXIDE_PROXY | Proxy to use for connecting to Telegram, e.g. socks5://localhost:9000 | | |
29+
| TELOXIDE_TOKEN | Telegram bot token (from [@BotFather](https://t.me/BotFather) bot) | Yes | |
30+
| WEBHOOK_IP | IP to bind the Telegram webhook to. | | 0.0.0.0 |
31+
| WEBHOOK_PORT | Port on which the bot will be listening for requests from Telegram. | For non-polling telegram interaction | |
32+
| WEBHOOK_URL | Example: https://<app-name>.herokuapp.com:443 | For non-polling telegram interaction | |
3233

3334
### Usage example
3435

src/core/prowlarr.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::core::download_meta::{DownloadMeta, DownloadMetaProvider};
1212
pub struct ProwlarrClient {
1313
api_key: String,
1414
base_url: Url,
15+
limit_param: String,
1516
indexer_id_params: String,
1617
client: Client,
1718
}
@@ -42,13 +43,17 @@ struct DownloadParams<'a> {
4243
const PROWLARR_API_KEY_ENV: &str = "PROWLARR_API_KEY";
4344
const PROWLARR_API_KEY_FILE_ENV: &str = "PROWLARR_API_KEY_FILE";
4445
const PROWLARR_BASE_URL_ENV: &str = "PROWLARR_BASE_URL";
46+
const PROWLARR_DEFAULT_LIMIT_PARAM_ENV: &str = "PROWLARR_DEFAULT_LIMIT_PARAM";
4547
const PROWLARR_INDEXER_IDS_ENV: &str = "PROWLARR_INDEXER_IDS";
4648

4749
impl ProwlarrClient {
4850
pub fn from_env() -> ProwlarrClient {
4951
ProwlarrClient {
5052
api_key: get_api_key(),
5153
base_url: ProwlarrClient::parse_base_url(),
54+
limit_param: env::var(PROWLARR_DEFAULT_LIMIT_PARAM_ENV)
55+
.map(|v| format!("&limit={}", v))
56+
.unwrap_or_default(),
5257
indexer_id_params: ProwlarrClient::get_indexer_id_params(),
5358
client: Client::new(),
5459
}
@@ -80,8 +85,8 @@ impl ProwlarrClient {
8085
}
8186

8287
pub async fn search(&self, query: &str) -> reqwest::Result<Vec<SearchResult>> {
83-
self.client.get(format!("{}api/v1/search?apikey={}&query={}{}",
84-
self.base_url, self.api_key, query, self.indexer_id_params))
88+
self.client.get(format!("{}api/v1/search?apikey={}{}&query={}{}", self.base_url,
89+
self.api_key, self.limit_param, query, self.indexer_id_params))
8590
.send()
8691
.await?
8792
.json::<Vec<SearchResult>>()
@@ -205,7 +210,7 @@ mod test {
205210
}
206211

207212
mod client {
208-
use crate::core::prowlarr::{ProwlarrClient, PROWLARR_API_KEY_ENV, PROWLARR_BASE_URL_ENV};
213+
use crate::core::prowlarr::{ProwlarrClient, PROWLARR_API_KEY_ENV, PROWLARR_BASE_URL_ENV, PROWLARR_DEFAULT_LIMIT_PARAM_ENV};
209214
use chrono::DateTime;
210215
use reqwest::header::CONTENT_TYPE;
211216
use reqwest::StatusCode;
@@ -228,6 +233,7 @@ mod test {
228233
.and(path("/api/v1/search"))
229234
.and(query_param("apikey", "key123"))
230235
.and(query_param("query", "Ubuntu"))
236+
.and(query_param("limit", "100"))
231237
.respond_with(ResponseTemplate::new(200)
232238
.set_body_string(
233239
"[{\"guid\":\"101\",\"indexerId\":1,\"title\":\"Title\",\
@@ -239,6 +245,7 @@ mod test {
239245

240246
let prowlarr_client = temp_env::with_vars(
241247
[(PROWLARR_API_KEY_ENV, Some("key123")),
248+
(PROWLARR_DEFAULT_LIMIT_PARAM_ENV, Some("100")),
242249
(PROWLARR_BASE_URL_ENV, Some(&mock_server.uri()))],
243250
ProwlarrClient::from_env);
244251

0 commit comments

Comments
 (0)