torrust_index_backend/web/api/v1/contexts/settings/
mod.rs

1//! API context: `settings`.
2//!
3//! This API context is responsible for handling the application settings.
4//!
5//! # Endpoints
6//!
7//! - [Get all settings](#get-all-settings)
8//! - [Update all settings](#update-all-settings)
9//! - [Get site name](#get-site-name)
10//! - [Get public settings](#get-public-settings)
11//!
12//! # Get all settings
13//!
14//! `GET /v1/settings`
15//!
16//! Returns all settings.
17//!
18//! **Example request**
19//!
20//! ```bash
21//! curl \
22//!   --header "Content-Type: application/json" \
23//!   --header "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7InVzZXJfaWQiOjEsInVzZXJuYW1lIjoiaW5kZXhhZG1pbiIsImFkbWluaXN0cmF0b3IiOnRydWV9LCJleHAiOjE2ODYyMTU3ODh9.4k8ty27DiWwOk4WVcYEhIrAndhpXMRWnLZ3i_HlJnvI" \
24//!   --request GET \
25//!   "http://127.0.0.1:3001/v1/settings"
26//! ```
27//!
28//! **Example response** `200`
29//!
30//! ```json
31//! {
32//!   "data": {
33//!     "website": {
34//!       "name": "Torrust"
35//!     },
36//!     "tracker": {
37//!       "url": "udp://localhost:6969",
38//!       "mode": "Public",
39//!       "api_url": "http://localhost:1212",
40//!       "token": "MyAccessToken",
41//!       "token_valid_seconds": 7257600
42//!     },
43//!     "net": {
44//!       "port": 3001,
45//!       "base_url": null
46//!     },
47//!     "auth": {
48//!       "email_on_signup": "Optional",
49//!       "min_password_length": 6,
50//!       "max_password_length": 64,
51//!       "secret_key": "MaxVerstappenWC2021"
52//!     },
53//!     "database": {
54//!       "connect_url": "sqlite://./storage/database/data.db?mode=rwc"
55//!     },
56//!     "mail": {
57//!       "email_verification_enabled": false,
58//!       "from": "example@email.com",
59//!       "reply_to": "noreply@email.com",
60//!       "username": "",
61//!       "password": "",
62//!       "server": "",
63//!       "port": 25
64//!     },
65//!     "image_cache": {
66//!       "max_request_timeout_ms": 1000,
67//!       "capacity": 128000000,
68//!       "entry_size_limit": 4000000,
69//!       "user_quota_period_seconds": 3600,
70//!       "user_quota_bytes": 64000000
71//!     },
72//!     "api": {
73//!       "default_torrent_page_size": 10,
74//!       "max_torrent_page_size": 30
75//!     },
76//!     "tracker_statistics_importer": {
77//!       "torrent_info_update_interval": 3600
78//!     }
79//!   }
80//! }
81//! ```
82//! **Resource**
83//!
84//! Refer to the [`TorrustBackend`](crate::config::TorrustBackend)
85//! struct for more information about the response attributes.
86//!
87//! # Update all settings
88//!
89//! **NOTICE**: This endpoint to update the settings does not work when you use
90//! environment variables to configure the application. You need to use a
91//! configuration file instead. Because settings are persisted in that file.
92//! Refer to the issue [#144](https://github.com/torrust/torrust-index-backend/issues/144)
93//! for more information.
94//!
95//! `POST /v1/settings`
96//!
97//! **Example request**
98//!
99//! ```bash
100//! curl \
101//!   --header "Content-Type: application/json" \
102//!   --header "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7InVzZXJfaWQiOjEsInVzZXJuYW1lIjoiaW5kZXhhZG1pbiIsImFkbWluaXN0cmF0b3IiOnRydWV9LCJleHAiOjE2ODYyMTU3ODh9.4k8ty27DiWwOk4WVcYEhIrAndhpXMRWnLZ3i_HlJnvI" \
103//!   --request POST \
104//!   --data '{"website":{"name":"Torrust"},"tracker":{"url":"udp://localhost:6969","mode":"Public","api_url":"http://localhost:1212","token":"MyAccessToken","token_valid_seconds":7257600},"net":{"port":3001,"base_url":null},"auth":{"email_on_signup":"Optional","min_password_length":6,"max_password_length":64,"secret_key":"MaxVerstappenWC2021"},"database":{"connect_url":"sqlite://./storage/database/data.db?mode=rwc"},"mail":{"email_verification_enabled":false,"from":"example@email.com","reply_to":"noreply@email.com","username":"","password":"","server":"","port":25},"image_cache":{"max_request_timeout_ms":1000,"capacity":128000000,"entry_size_limit":4000000,"user_quota_period_seconds":3600,"user_quota_bytes":64000000},"api":{"default_torrent_page_size":10,"max_torrent_page_size":30},"tracker_statistics_importer":{"torrent_info_update_interval":3600}}' \
105//!   "http://127.0.0.1:3001/v1/settings"
106//! ```
107//!
108//! The response contains the settings that were updated.
109//!
110//! **Resource**
111//!
112//! Refer to the [`TorrustBackend`](crate::config::TorrustBackend)
113//! struct for more information about the response attributes.
114//!
115//! # Get site name
116//!
117//! `GET /v1/settings/name`
118//!
119//! It returns the name of the site.
120//!
121//! **Example request**
122//!
123//! ```bash
124//! curl \
125//!   --header "Content-Type: application/json" \
126//!   --request GET \
127//!   "http://127.0.0.1:3001/v1/settings/name"
128//! ```
129//!
130//! **Example response** `200`
131//!
132//! ```json
133//! {
134//!   "data":"Torrust"
135//! }
136//! ```
137//!
138//! # Get public settings
139//!
140//! `GET /v1/settings/public`
141//!
142//! It returns all the public settings.
143//!
144//! **Example request**
145//!
146//! ```bash
147//! curl \
148//!   --header "Content-Type: application/json" \
149//!   --request GET \
150//!   "http://127.0.0.1:3001/v1/settings/public"
151//! ```
152//!
153//! **Example response** `200`
154//!
155//! ```json
156//! {
157//!   "data": {
158//!     "website_name": "Torrust",
159//!     "tracker_url": "udp://localhost:6969",
160//!     "tracker_mode": "Public",
161//!     "email_on_signup": "Optional"
162//!   }
163//! }
164//! ```
165//!
166//! **Resource**
167//!
168//! Refer to the [`ConfigurationPublic`](crate::config::ConfigurationPublic)
169//! struct for more information about the response attributes.
170pub mod handlers;
171pub mod routes;