Skip to content

Commit d500634

Browse files
committed
refactor: [#290] specific error for suplidatetorrent with a original infohashes
1 parent 61ce771 commit d500634

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ pub enum ServiceError {
115115
#[display(fmt = "A torrent with the same canonical infohash already exists in our database.")]
116116
CanonicalInfoHashAlreadyExists,
117117

118+
#[display(fmt = "A torrent with the same original infohash already exists in our database.")]
119+
OriginalInfoHashAlreadyExists,
120+
118121
#[display(fmt = "This torrent title has already been used.")]
119122
TorrentTitleAlreadyExists,
120123

@@ -297,6 +300,7 @@ pub fn http_status_code_for_service_error(error: &ServiceError) -> StatusCode {
297300
ServiceError::Unauthorized => StatusCode::FORBIDDEN,
298301
ServiceError::InfoHashAlreadyExists => StatusCode::BAD_REQUEST,
299302
ServiceError::CanonicalInfoHashAlreadyExists => StatusCode::BAD_REQUEST,
303+
ServiceError::OriginalInfoHashAlreadyExists => StatusCode::BAD_REQUEST,
300304
ServiceError::TorrentTitleAlreadyExists => StatusCode::BAD_REQUEST,
301305
ServiceError::TrackerOffline => StatusCode::SERVICE_UNAVAILABLE,
302306
ServiceError::CategoryNameEmpty => StatusCode::BAD_REQUEST,

src/services/torrent.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,16 @@ impl Index {
209209
.await?;
210210

211211
if !original_info_hashes.is_empty() {
212+
// A previous torrent with the same canonical infohash has been uploaded before
213+
212214
// Torrent with the same canonical infohash was already uploaded
213215
debug!("Canonical infohash found: {:?}", canonical_info_hash.to_hex_string());
214216

215217
if let Some(original_info_hash) = original_info_hashes.find(original_info_hash) {
216218
// The exact original infohash was already uploaded
217219
debug!("Original infohash found: {:?}", original_info_hash.to_hex_string());
218220

219-
return Err(ServiceError::InfoHashAlreadyExists);
221+
return Err(ServiceError::OriginalInfoHashAlreadyExists);
220222
}
221223

222224
// A new original infohash is being uploaded with a canonical infohash that already exists.
@@ -229,6 +231,7 @@ impl Index {
229231
return Err(ServiceError::CanonicalInfoHashAlreadyExists);
230232
}
231233

234+
// No other torrent with the same canonical infohash has been uploaded before
232235
Ok(())
233236
}
234237

0 commit comments

Comments
 (0)