diff --git a/app/Models/ExamUser.php b/app/Models/ExamUser.php index 55e06d19..d16e4384 100644 --- a/app/Models/ExamUser.php +++ b/app/Models/ExamUser.php @@ -2,6 +2,8 @@ namespace App\Models; +use App\Repositories\ExamRepository; + class ExamUser extends NexusModel { protected $fillable = ['exam_id', 'uid', 'status', 'progress', 'begin', 'end', 'is_done']; @@ -43,38 +45,8 @@ class ExamUser extends NexusModel public function getProgressFormattedAttribute(): array { - $result = []; - $progress = $this->progress; - foreach ($this->exam->indexes as $key => $index) { - if (!isset($index['checked']) || !$index['checked']) { - continue; - } - $currentValue = $progress[$index['index']] ?? 0; - $requireValue = $index['require_value']; - $unit = Exam::$indexes[$index['index']]['unit'] ?? ''; - switch ($index['index']) { - case Exam::INDEX_UPLOADED: - case Exam::INDEX_DOWNLOADED: - $currentValueFormatted = mksize($currentValue); - $requireValueAtomic = $requireValue * 1024 * 1024 * 1024; - break; - case Exam::INDEX_SEED_TIME_AVERAGE: - $currentValueFormatted = number_format($currentValue / 3600, 2) . " $unit"; - $requireValueAtomic = $requireValue * 3600; - break; - default: - $currentValueFormatted = $currentValue; - $requireValueAtomic = $requireValue; - } - $index['name'] = Exam::$indexes[$index['index']]['name'] ?? ''; - $index['index_formatted'] = nexus_trans('exam.index_text_' . $index['index']); - $index['require_value_formatted'] = "$requireValue " . ($index['unit'] ?? ''); - $index['current_value'] = $currentValue; - $index['current_value_formatted'] = $currentValueFormatted; - $index['passed'] = $currentValue >= $requireValueAtomic; - $result[] = $index; - } - return $result; + $examRep = new ExamRepository(); + return $examRep->getProgressFormatted($this->exam, $this->progress); } public static function listStatus($onlyKeyValue = false): array diff --git a/app/Repositories/ExamRepository.php b/app/Repositories/ExamRepository.php index 1844be26..0db572af 100644 --- a/app/Repositories/ExamRepository.php +++ b/app/Repositories/ExamRepository.php @@ -691,7 +691,7 @@ class ExamRepository extends BaseRepository } - private function getProgressFormatted(Exam $exam, array $progress, $locale = null) + public function getProgressFormatted(Exam $exam, array $progress, $locale = null) { $result = []; foreach ($exam->indexes as $key => $index) { @@ -700,6 +700,7 @@ class ExamRepository extends BaseRepository } $currentValue = $progress[$index['index']] ?? 0; $requireValue = $index['require_value']; + $unit = Exam::$indexes[$index['index']]['unit'] ?? ''; switch ($index['index']) { case Exam::INDEX_UPLOADED: case Exam::INDEX_DOWNLOADED: @@ -707,7 +708,7 @@ class ExamRepository extends BaseRepository $requireValueAtomic = $requireValue * 1024 * 1024 * 1024; break; case Exam::INDEX_SEED_TIME_AVERAGE: - $currentValueFormatted = number_format($currentValue / 3600, 2) . " {$index['unit']}"; + $currentValueFormatted = number_format($currentValue / 3600, 2) . " $unit"; $requireValueAtomic = $requireValue * 3600; break; default: @@ -716,7 +717,7 @@ class ExamRepository extends BaseRepository } $index['name'] = Exam::$indexes[$index['index']]['name'] ?? ''; $index['index_formatted'] = nexus_trans('exam.index_text_' . $index['index']); - $index['require_value_formatted'] = "$requireValue " . ($index['unit'] ?? ''); + $index['require_value_formatted'] = "$requireValue $unit"; $index['current_value'] = $currentValue; $index['current_value_formatted'] = $currentValueFormatted; $index['passed'] = $currentValue >= $requireValueAtomic; diff --git a/app/Repositories/TrackerRepository.php b/app/Repositories/TrackerRepository.php index 556512f8..73edf972 100644 --- a/app/Repositories/TrackerRepository.php +++ b/app/Repositories/TrackerRepository.php @@ -617,8 +617,11 @@ class TrackerRepository extends BaseRepository protected function isReAnnounce(Request $request): int { $key = $request->query->get('key'); + $ip = $request->query->get('ip'); + $ipv4 = $request->query->get('ipv4'); + $ipv6 = $request->query->get('ipv6'); $queryString = $request->getQueryString(); - $lockKeyOriginal = str_replace($key, '', $queryString); + $lockKeyOriginal = str_replace([$key, $ip, $ipv4, $ipv6], '', $queryString); $lockKey = md5($lockKeyOriginal); $startTimestamp = nexus()->getStartTimestamp(); $redis = Redis::connection()->client(); diff --git a/include/constants.php b/include/constants.php index 65d36753..cf3e22cc 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@