Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
refactor(Torrent/Download): Make multi tracker behaviour more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Aug 9, 2019
1 parent 4fe52e5 commit e366938
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions apps/models/form/Torrent/DownloadForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,17 @@ public function getSendFileContent()
$multi_trackers = config('base.site_tracker_url') . ',' . $multi_trackers;
$multi_trackers_list = explode(',', $multi_trackers);
$multi_trackers_list = array_unique($multi_trackers_list); // use array_unique to remove dupe tracker
// fulfill each tracker with scheme and suffix about user identity
$multi_trackers_list = array_map(function ($uri) use ($scheme, $announce_suffix) {
return $scheme . $uri . $announce_suffix;
}, $multi_trackers_list);

if (config('base.site_multi_tracker_behaviour') == 'separate') {
/** d['announce-list'] = [ [tracker1], [backup1], [backup2] ] */
foreach ($multi_trackers_list as $tracker) { // separate each tracker to different tier
$dict["announce-list"] = [];
foreach ($multi_trackers_list as $uri) {
$tracker = $scheme . $uri . $announce_suffix; // fulfill each tracker with scheme and suffix about user identity
if (config('base.site_multi_tracker_behaviour') == 'separate') {
/** d['announce-list'] = [ [tracker1], [backup1], [backup2] ] */
$dict["announce-list"][] = [$tracker]; // Make each tracker as tier
} else { // config('base.site_multi_tracker_behaviour') == 'union'
/** d['announce-list'] = [[ tracker1, tracker2, tracker3 ]] */
$dict["announce-list"][0][] = $tracker; // all tracker in tier 0
}
} else { // config('base.site_multi_tracker_behaviour') == 'union'
/** d['announce-list'] = [[ tracker1, tracker2, tracker3 ]] */
$dict["announce-list"][] = $multi_trackers_list;
}
}

Expand Down

0 comments on commit e366938

Please sign in to comment.