mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
support plugin nexusphp-hit-and-run
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Carbon\Exceptions\InvalidArgumentException;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
|
||||
class HitAndRun extends NexusModel
|
||||
@@ -17,7 +19,7 @@ class HitAndRun extends NexusModel
|
||||
const STATUS_UNREACHED = 3;
|
||||
const STATUS_PARDONED = 4;
|
||||
|
||||
public static $status = [
|
||||
public static array $status = [
|
||||
self::STATUS_INSPECTING => ['text' => 'Inspecting'],
|
||||
self::STATUS_REACHED => ['text' => 'Reached'],
|
||||
self::STATUS_UNREACHED => ['text' => 'Unreached'],
|
||||
@@ -39,17 +41,37 @@ class HitAndRun extends NexusModel
|
||||
protected function seedTimeRequired(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn($value, $attributes) => $this->status == self::STATUS_INSPECTING ? mkprettytime(3600 * Setting::get('hr.seed_time_minimum') - $this->snatch->seedtime) : '---'
|
||||
get: fn($value, $attributes) => $this->doGetSeedTimeRequired()
|
||||
);
|
||||
}
|
||||
|
||||
protected function inspectTimeLeft(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn($value, $attributes) => $this->status == self::STATUS_INSPECTING ? mkprettytime(\Carbon\Carbon::now()->diffInSeconds($this->snatch->completedat->addHours(Setting::get('hr.inspect_time')))) : '---'
|
||||
get: fn($value, $attributes) => $this->doGetInspectTimeLeft()
|
||||
);
|
||||
}
|
||||
|
||||
private function doGetInspectTimeLeft(): string
|
||||
{
|
||||
if ($this->status != self::STATUS_INSPECTING) {
|
||||
return '---';
|
||||
}
|
||||
$inspectTime = HitAndRun::getConfig('inspect_time', $this->torrent->basic_category->mode);
|
||||
$diffInSeconds = Carbon::now()->diffInSeconds($this->snatch->completedat->addHours($inspectTime));
|
||||
return mkprettytime($diffInSeconds);
|
||||
}
|
||||
|
||||
private function doGetSeedTimeRequired(): string
|
||||
{
|
||||
if ($this->status != self::STATUS_INSPECTING) {
|
||||
return '---';
|
||||
}
|
||||
$seedTimeMinimum = HitAndRun::getConfig('seed_time_minimum', $this->torrent->basic_category->mode);
|
||||
$diffInSeconds = 3600 * $seedTimeMinimum - $this->snatch->seedtime;
|
||||
return mkprettytime($diffInSeconds);
|
||||
}
|
||||
|
||||
public function getStatusTextAttribute()
|
||||
{
|
||||
return nexus_trans('hr.status_' . $this->status);
|
||||
@@ -87,8 +109,29 @@ class HitAndRun extends NexusModel
|
||||
|
||||
public static function getIsEnabled(): bool
|
||||
{
|
||||
$result = Setting::get('hr.mode');
|
||||
return $result && in_array($result, [self::MODE_GLOBAL, self::MODE_MANUAL]);
|
||||
$enableSpecialSection = Setting::get('main.spsct') == 'yes';
|
||||
$browseMode = self::getConfig('mode', Setting::get('main.browsecat'));
|
||||
$browseEnabled = $browseMode && in_array($browseMode, [self::MODE_GLOBAL, self::MODE_MANUAL]);
|
||||
if (!$enableSpecialSection) {
|
||||
do_log("Not enable special section, browseEnabled: $browseEnabled");
|
||||
return $browseEnabled;
|
||||
}
|
||||
$specialMode = self::getConfig('mode', Setting::get('main.specialcat'));
|
||||
$specialEnabled = $specialMode && in_array($specialMode, [self::MODE_GLOBAL, self::MODE_MANUAL]);
|
||||
$result = $browseEnabled || $specialEnabled;
|
||||
do_log("Enable special section, browseEnabled: $browseEnabled, specialEnabled: $specialEnabled, result: $result");
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getConfig($name, $searchBoxId)
|
||||
{
|
||||
if ($name == '*') {
|
||||
$key = "hr";
|
||||
} else {
|
||||
$key = "hr.$name";
|
||||
}
|
||||
$default = Setting::get($key);
|
||||
return apply_filter("nexus_setting_get", $default, $name, ['mode' => $searchBoxId]);
|
||||
}
|
||||
|
||||
public function torrent(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
|
||||
@@ -18,6 +18,14 @@ class SearchBox extends NexusModel
|
||||
'extra' => 'object'
|
||||
];
|
||||
|
||||
const SECTION_BROWSE = 'browse';
|
||||
const SECTION_SPECIAL = 'special';
|
||||
|
||||
public static array $sections = [
|
||||
self::SECTION_BROWSE => ['text' => 'Browse'],
|
||||
self::SECTION_SPECIAL => ['text' => 'Special'],
|
||||
];
|
||||
|
||||
const EXTRA_DISPLAY_COVER_ON_TORRENT_LIST = 'display_cover_on_torrent_list';
|
||||
const EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST = 'display_seed_box_icon_on_torrent_list';
|
||||
|
||||
@@ -35,6 +43,21 @@ class SearchBox extends NexusModel
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function listSections($field = null): array
|
||||
{
|
||||
$result = [];
|
||||
foreach (self::$sections as $key => $value) {
|
||||
$value['text'] = nexus_trans("searchbox.sections.$key");
|
||||
$value['mode'] = Setting::get("main.{$key}cat");
|
||||
if ($field !== null && isset($value[$field])) {
|
||||
$result[$key] = $value[$field];
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getCustomFieldsAttribute($value): array
|
||||
{
|
||||
if (!is_array($value)) {
|
||||
|
||||
@@ -289,7 +289,8 @@ class Torrent extends NexusModel
|
||||
|
||||
public function getHrAttribute(): string
|
||||
{
|
||||
$hrMode = Setting::get('hr.mode');
|
||||
// $hrMode = Setting::get('hr.mode');
|
||||
$hrMode = HitAndRun::getConfig('mode', $this->basic_category->mode);
|
||||
if ($hrMode == HitAndRun::MODE_GLOBAL) {
|
||||
return self::HR_YES;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user