From e36693855fd3ecb0f837474dabfb01ae8b9a5c3a Mon Sep 17 00:00:00 2001 From: Rhilip Date: Fri, 9 Aug 2019 16:01:41 +0800 Subject: [PATCH] refactor(Torrent/Download): Make multi tracker behaviour more readable refs: https://github.com/zcqian/tjupt/commit/e48a4c1932ff84d1cd77a0022e30c07421cb55ab#diff-19ea9a346c0da02aefa62f4648622880R72-R80 --- apps/models/form/Torrent/DownloadForm.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/apps/models/form/Torrent/DownloadForm.php b/apps/models/form/Torrent/DownloadForm.php index 31dda27..98f53fb 100644 --- a/apps/models/form/Torrent/DownloadForm.php +++ b/apps/models/form/Torrent/DownloadForm.php @@ -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; } }