@@ -23,6 +23,7 @@ use crate::services::torrent_file::generate_random_torrent;
23
23
use crate :: utils:: parse_torrent;
24
24
use crate :: web:: api:: server:: v1:: auth:: get_optional_logged_in_user;
25
25
use crate :: web:: api:: server:: v1:: extractors:: bearer_token:: Extract ;
26
+ use crate :: web:: api:: server:: v1:: extractors:: user_id:: ExtractLoggedInUser ;
26
27
use crate :: web:: api:: server:: v1:: responses:: OkResponseData ;
27
28
use crate :: web:: api:: server:: v1:: routes:: API_VERSION_URL_PREFIX ;
28
29
@@ -37,14 +38,9 @@ use crate::web::api::server::v1::routes::API_VERSION_URL_PREFIX;
37
38
#[ allow( clippy:: unused_async) ]
38
39
pub async fn upload_torrent_handler (
39
40
State ( app_data) : State < Arc < AppData > > ,
40
- Extract ( maybe_bearer_token ) : Extract ,
41
+ ExtractLoggedInUser ( user_id ) : ExtractLoggedInUser ,
41
42
multipart : Multipart ,
42
43
) -> Response {
43
- let user_id = match app_data. auth . get_user_id_from_bearer_token ( & maybe_bearer_token) . await {
44
- Ok ( user_id) => user_id,
45
- Err ( error) => return error. into_response ( ) ,
46
- } ;
47
-
48
44
let add_torrent_form = match build_add_torrent_request_from_payload ( multipart) . await {
49
45
Ok ( torrent_request) => torrent_request,
50
46
Err ( error) => return error. into_response ( ) ,
@@ -220,19 +216,14 @@ async fn redirect_to_details_url_using_canonical_info_hash_if_needed(
220
216
#[ allow( clippy:: unused_async) ]
221
217
pub async fn update_torrent_info_handler (
222
218
State ( app_data) : State < Arc < AppData > > ,
223
- Extract ( maybe_bearer_token ) : Extract ,
219
+ ExtractLoggedInUser ( user_id ) : ExtractLoggedInUser ,
224
220
Path ( info_hash) : Path < InfoHashParam > ,
225
221
extract:: Json ( update_torrent_info_form) : extract:: Json < UpdateTorrentInfoForm > ,
226
222
) -> Response {
227
223
let Ok ( info_hash) = InfoHash :: from_str ( & info_hash. lowercase ( ) ) else {
228
224
return errors:: Request :: InvalidInfoHashParam . into_response ( ) ;
229
225
} ;
230
226
231
- let user_id = match app_data. auth . get_user_id_from_bearer_token ( & maybe_bearer_token) . await {
232
- Ok ( user_id) => user_id,
233
- Err ( error) => return error. into_response ( ) ,
234
- } ;
235
-
236
227
match app_data
237
228
. torrent_service
238
229
. update_torrent_info (
@@ -262,18 +253,13 @@ pub async fn update_torrent_info_handler(
262
253
#[ allow( clippy:: unused_async) ]
263
254
pub async fn delete_torrent_handler (
264
255
State ( app_data) : State < Arc < AppData > > ,
265
- Extract ( maybe_bearer_token ) : Extract ,
256
+ ExtractLoggedInUser ( user_id ) : ExtractLoggedInUser ,
266
257
Path ( info_hash) : Path < InfoHashParam > ,
267
258
) -> Response {
268
259
let Ok ( info_hash) = InfoHash :: from_str ( & info_hash. lowercase ( ) ) else {
269
260
return errors:: Request :: InvalidInfoHashParam . into_response ( ) ;
270
261
} ;
271
262
272
- let user_id = match app_data. auth . get_user_id_from_bearer_token ( & maybe_bearer_token) . await {
273
- Ok ( user_id) => user_id,
274
- Err ( error) => return error. into_response ( ) ,
275
- } ;
276
-
277
263
match app_data. torrent_service . delete_torrent ( & info_hash, & user_id) . await {
278
264
Ok ( deleted_torrent_response) => Json ( OkResponseData {
279
265
data : deleted_torrent_response,
0 commit comments