Skip to content

Commit 836c94d

Browse files
committed
refactor: [#615] upload torrent handler now uses an optional user id
1 parent 935eb53 commit 836c94d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/services/torrent.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ impl Index {
132132
pub async fn add_torrent(
133133
&self,
134134
add_torrent_req: AddTorrentRequest,
135-
user_id: UserId,
135+
maybe_user_id: Option<UserId>,
136136
) -> Result<AddTorrentResponse, ServiceError> {
137137
self.authorization_service
138-
.authorize(ACTION::AddTorrent, Some(user_id))
138+
.authorize(ACTION::AddTorrent, maybe_user_id)
139139
.await?;
140140

141141
let metadata = self.validate_and_build_metadata(&add_torrent_req).await?;
@@ -149,7 +149,7 @@ impl Index {
149149

150150
let torrent_id = self
151151
.torrent_repository
152-
.add(&original_info_hash, &torrent, &metadata, user_id)
152+
.add(&original_info_hash, &torrent, &metadata, maybe_user_id.unwrap())
153153
.await?;
154154

155155
// Synchronous secondary tasks

src/web/api/server/v1/contexts/torrent/handlers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ use crate::web::api::server::v1::routes::API_VERSION_URL_PREFIX;
3737
#[allow(clippy::unused_async)]
3838
pub async fn upload_torrent_handler(
3939
State(app_data): State<Arc<AppData>>,
40-
ExtractLoggedInUser(user_id): ExtractLoggedInUser,
40+
ExtractOptionalLoggedInUser(maybe_user_id): ExtractOptionalLoggedInUser,
4141
multipart: Multipart,
4242
) -> Response {
4343
let add_torrent_form = match build_add_torrent_request_from_payload(multipart).await {
4444
Ok(torrent_request) => torrent_request,
4545
Err(error) => return error.into_response(),
4646
};
4747

48-
match app_data.torrent_service.add_torrent(add_torrent_form, user_id).await {
48+
match app_data.torrent_service.add_torrent(add_torrent_form, maybe_user_id).await {
4949
Ok(response) => new_torrent_response(&response).into_response(),
5050
Err(error) => error.into_response(),
5151
}

0 commit comments

Comments
 (0)