mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-16 05:50:55 +08:00
exam support valid multiple
This commit is contained in:
@@ -4,6 +4,8 @@ namespace App\Models;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
|
||||
class Snatch extends NexusModel
|
||||
{
|
||||
@@ -33,6 +35,59 @@ class Snatch extends NexusModel
|
||||
|
||||
const FINISHED_NO = 'no';
|
||||
|
||||
protected function uploadText(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn($value, $attributes) => sprintf('%s@%s', mksize($attributes['uploaded']), $this->getUploadSpeed())
|
||||
);
|
||||
}
|
||||
|
||||
protected function downloadText(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn($value, $attributes) => sprintf('%s@%s', mksize($attributes['downloaded']), $this->getDownloadSpeed())
|
||||
);
|
||||
}
|
||||
|
||||
protected function shareRatio(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn($value, $attributes) => $this->getShareRatio()
|
||||
);
|
||||
}
|
||||
|
||||
public function getUploadSpeed(): string
|
||||
{
|
||||
if ($this->seedtime <= 0) {
|
||||
$speed = mksize(0);
|
||||
} else {
|
||||
$speed = mksize($this->uploaded / ($this->seedtime + $this->leechtime));
|
||||
}
|
||||
return "$speed/s";
|
||||
}
|
||||
|
||||
public function getDownloadSpeed(): string
|
||||
{
|
||||
if ($this->leechtime <= 0) {
|
||||
$speed = mksize(0);
|
||||
} else {
|
||||
$speed = mksize($this->downloaded / $this->leechtime);
|
||||
}
|
||||
return "$speed/s";
|
||||
}
|
||||
|
||||
public function getShareRatio()
|
||||
{
|
||||
if ($this->downloaded) {
|
||||
$ratio = floor(($this->uploaded / $this->downloaded) * 1000) / 1000;
|
||||
} elseif ($this->uploaded) {
|
||||
$ratio = nexus_trans('snatch.share_ratio_infinity');
|
||||
} else {
|
||||
$ratio = '---';
|
||||
}
|
||||
return $ratio;
|
||||
}
|
||||
|
||||
public function scopeIsFinished(Builder $builder)
|
||||
{
|
||||
return $builder->where('finished', self::FINISHED_YES);
|
||||
|
||||
Reference in New Issue
Block a user