mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 17:01:16 +00:00
Merge branch 'master' of https://github.com/NNTmux/newznab-tmux
This commit is contained in:
@@ -7,6 +7,7 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\BasePageController;
|
||||
use App\Http\Requests\Admin\AdminGroupListRequest;
|
||||
use App\Models\UsenetGroup;
|
||||
use App\Support\SizeUnit;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
@@ -75,6 +76,16 @@ class AdminGroupController extends BasePageController
|
||||
|
||||
switch ($action) {
|
||||
case 'submit':
|
||||
// Convert the size + unit pair to bytes; a blank input stays blank
|
||||
// so the model stores null and the site-wide setting applies.
|
||||
$minSizeInput = $request->input('minsizetoformrelease');
|
||||
if ($minSizeInput !== null && $minSizeInput !== '') {
|
||||
$request->merge([
|
||||
'minsizetoformrelease' => SizeUnit::toBytes($minSizeInput, $request->input('minsizetoformrelease_unit', 'MB')),
|
||||
]);
|
||||
}
|
||||
$request->request->remove('minsizetoformrelease_unit');
|
||||
|
||||
if (empty($request->input('id'))) {
|
||||
// Add a new group.
|
||||
$request->merge(['name' => UsenetGroup::isValidGroup($request->input('name'))]);
|
||||
@@ -101,7 +112,9 @@ class AdminGroupController extends BasePageController
|
||||
break;
|
||||
}
|
||||
|
||||
return view('admin.groups.edit', compact('title', 'group'));
|
||||
$groupMinSize = SizeUnit::fromBytes($group['minsizetoformrelease'] ?? 0);
|
||||
|
||||
return view('admin.groups.edit', compact('title', 'group', 'groupMinSize') + ['sizeUnits' => SizeUnit::UNITS]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Models\ReleaseStat;
|
||||
use App\Models\RoleStat;
|
||||
use App\Models\Settings;
|
||||
use App\Models\SignupStat;
|
||||
use App\Support\SizeUnit;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
@@ -32,7 +33,14 @@ class AdminSiteController extends BasePageController
|
||||
|
||||
switch ($action) {
|
||||
case 'submit':
|
||||
Settings::settingsUpdate($request->all());
|
||||
$data = $request->all();
|
||||
|
||||
foreach (SizeUnit::SITE_SIZE_SETTINGS as $sizeKey) {
|
||||
$data[$sizeKey] = SizeUnit::toBytes($data[$sizeKey] ?? null, $data[$sizeKey.'_unit'] ?? 'MB');
|
||||
unset($data[$sizeKey.'_unit']);
|
||||
}
|
||||
|
||||
Settings::settingsUpdate($data);
|
||||
|
||||
return redirect()->to('admin/site-edit')->with('success', 'Settings updated successfully');
|
||||
|
||||
@@ -43,8 +51,15 @@ class AdminSiteController extends BasePageController
|
||||
|
||||
$compress_headers_warning = ! str_contains(config('settings.nntp_server'), 'astra') ? 'compress_headers_warning' : '';
|
||||
|
||||
$sizeFields = [];
|
||||
foreach (SizeUnit::SITE_SIZE_SETTINGS as $sizeKey) {
|
||||
$sizeFields[$sizeKey] = SizeUnit::fromBytes($this->viewData['site'][$sizeKey] ?? 0);
|
||||
}
|
||||
|
||||
$this->viewData = array_merge($this->viewData, [
|
||||
'error' => $error,
|
||||
'sizeFields' => $sizeFields,
|
||||
'sizeUnits' => SizeUnit::UNITS,
|
||||
'yesno' => [
|
||||
'ids' => [1, 0],
|
||||
'names' => ['Yes', 'No'],
|
||||
|
||||
@@ -29,11 +29,11 @@ use Illuminate\Support\Facades\Schema;
|
||||
*/
|
||||
final class AdditionalCandidateQuery
|
||||
{
|
||||
/** Default size lower bound when the setting is empty/unset (megabytes). */
|
||||
public const int DEFAULT_MIN_SIZE_MB = 1;
|
||||
/** Default size lower bound when the setting is empty/unset (bytes, 1 MB). */
|
||||
public const int DEFAULT_MIN_SIZE_BYTES = 1048576;
|
||||
|
||||
/** Default size upper bound when the setting is empty/unset (gigabytes). */
|
||||
public const int DEFAULT_MAX_SIZE_GB = 100;
|
||||
/** Default size upper bound when the setting is empty/unset (bytes, 100 GB). */
|
||||
public const int DEFAULT_MAX_SIZE_BYTES = 107374182400;
|
||||
|
||||
/**
|
||||
* Hard cap on the bucket fan-out. `leftguid` is the first character of a
|
||||
@@ -52,32 +52,32 @@ final class AdditionalCandidateQuery
|
||||
private static ?bool $supportsClaims = null;
|
||||
|
||||
/**
|
||||
* Resolve the minimum-size filter (megabytes). Returns 0 when disabled.
|
||||
* Resolve the minimum-size filter (bytes). Returns 0 when disabled.
|
||||
*
|
||||
* An explicit '0' setting means "no minimum size filter". An empty/null
|
||||
* setting falls back to {@see self::DEFAULT_MIN_SIZE_MB}.
|
||||
* setting falls back to {@see self::DEFAULT_MIN_SIZE_BYTES}.
|
||||
*/
|
||||
public static function minSizeMB(): int
|
||||
public static function minSizeBytes(): int
|
||||
{
|
||||
$value = Settings::settingValue('minsizetopostprocess');
|
||||
if ($value === '' || $value === null) {
|
||||
return self::DEFAULT_MIN_SIZE_MB;
|
||||
return self::DEFAULT_MIN_SIZE_BYTES;
|
||||
}
|
||||
|
||||
return max(0, (int) $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the maximum-size filter (gigabytes). Returns 0 when disabled.
|
||||
* Resolve the maximum-size filter (bytes). Returns 0 when disabled.
|
||||
*
|
||||
* An explicit '0' setting means "no maximum size filter". An empty/null
|
||||
* setting falls back to {@see self::DEFAULT_MAX_SIZE_GB}.
|
||||
* setting falls back to {@see self::DEFAULT_MAX_SIZE_BYTES}.
|
||||
*/
|
||||
public static function maxSizeGB(): int
|
||||
public static function maxSizeBytes(): int
|
||||
{
|
||||
$value = Settings::settingValue('maxsizetopostprocess');
|
||||
if ($value === '' || $value === null) {
|
||||
return self::DEFAULT_MAX_SIZE_GB;
|
||||
return self::DEFAULT_MAX_SIZE_BYTES;
|
||||
}
|
||||
|
||||
return max(0, (int) $value);
|
||||
@@ -97,22 +97,22 @@ final class AdditionalCandidateQuery
|
||||
Builder $query,
|
||||
int|string $groupID = '',
|
||||
string $guidChar = '',
|
||||
?int $minSizeMB = null,
|
||||
?int $maxSizeGB = null,
|
||||
?int $minSizeBytes = null,
|
||||
?int $maxSizeBytes = null,
|
||||
bool $includeClaimed = false,
|
||||
): Builder {
|
||||
$min = $minSizeMB ?? self::minSizeMB();
|
||||
$max = $maxSizeGB ?? self::maxSizeGB();
|
||||
$min = $minSizeBytes ?? self::minSizeBytes();
|
||||
$max = $maxSizeBytes ?? self::maxSizeBytes();
|
||||
$query
|
||||
->where('r.passwordstatus', -1)
|
||||
->where('r.haspreview', -1)
|
||||
->where('r.nzbstatus', 1)
|
||||
->where('c.disablepreview', 0);
|
||||
if ($min > 0) {
|
||||
$query->where('r.size', '>', $min * 1048576);
|
||||
$query->where('r.size', '>', $min);
|
||||
}
|
||||
if ($max > 0) {
|
||||
$query->where('r.size', '<', $max * 1073741824);
|
||||
$query->where('r.size', '<', $max);
|
||||
}
|
||||
if ($groupID !== '' && $groupID !== 0 && $groupID !== '0') {
|
||||
$query->where('r.groups_id', $groupID);
|
||||
@@ -136,15 +136,15 @@ final class AdditionalCandidateQuery
|
||||
public static function baseBuilder(
|
||||
int|string $groupID = '',
|
||||
string $guidChar = '',
|
||||
?int $minSizeMB = null,
|
||||
?int $maxSizeGB = null,
|
||||
?int $minSizeBytes = null,
|
||||
?int $maxSizeBytes = null,
|
||||
bool $includeClaimed = false,
|
||||
): Builder {
|
||||
$query = Release::query()
|
||||
->from('releases as r')
|
||||
->leftJoin('categories as c', 'c.id', '=', 'r.categories_id');
|
||||
|
||||
return self::applyPredicates($query, $groupID, $guidChar, $minSizeMB, $maxSizeGB, $includeClaimed);
|
||||
return self::applyPredicates($query, $groupID, $guidChar, $minSizeBytes, $maxSizeBytes, $includeClaimed);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,16 +277,16 @@ final class AdditionalCandidateQuery
|
||||
int $limit,
|
||||
string $token,
|
||||
int|string $groupID = '',
|
||||
?int $minSizeMB = null,
|
||||
?int $maxSizeGB = null,
|
||||
?int $minSizeBytes = null,
|
||||
?int $maxSizeBytes = null,
|
||||
array $columns = ['*'],
|
||||
array $excludedReleaseIds = [],
|
||||
): EloquentCollection {
|
||||
$effectiveLimit = max(1, $limit);
|
||||
|
||||
return DB::transaction(function () use ($guidChar, $effectiveLimit, $token, $groupID, $minSizeMB, $maxSizeGB, $columns, $excludedReleaseIds): EloquentCollection {
|
||||
return DB::transaction(function () use ($guidChar, $effectiveLimit, $token, $groupID, $minSizeBytes, $maxSizeBytes, $columns, $excludedReleaseIds): EloquentCollection {
|
||||
$supportsClaims = self::supportsClaims();
|
||||
$query = self::baseBuilder($groupID, $guidChar, $minSizeMB, $maxSizeGB)
|
||||
$query = self::baseBuilder($groupID, $guidChar, $minSizeBytes, $maxSizeBytes)
|
||||
->select('r.id')
|
||||
->orderByDesc('r.postdate')
|
||||
->orderBy('r.id')
|
||||
|
||||
@@ -177,8 +177,8 @@ class AdditionalProcessingOrchestrator
|
||||
$this->config->queryLimit > 0 ? $this->config->queryLimit : 25,
|
||||
$this->claimToken,
|
||||
$groupID,
|
||||
$this->config->minSizeMB,
|
||||
$this->config->maxSizeGB,
|
||||
$this->config->minSizeBytes,
|
||||
$this->config->maxSizeBytes,
|
||||
[
|
||||
'id',
|
||||
'guid',
|
||||
|
||||
@@ -39,9 +39,9 @@ final readonly class ProcessingConfiguration
|
||||
|
||||
public int $maximumRarPasswordChecks;
|
||||
|
||||
public int $maxSizeGB;
|
||||
public int $maxSizeBytes;
|
||||
|
||||
public int $minSizeMB;
|
||||
public int $minSizeBytes;
|
||||
|
||||
public bool $alternateNNTP;
|
||||
|
||||
@@ -117,8 +117,8 @@ final readonly class ProcessingConfiguration
|
||||
// (explicit '0' means disabled, empty/null means default) are owned
|
||||
// in one place and shared between the bucket query and the per-worker
|
||||
// fetch.
|
||||
$this->maxSizeGB = AdditionalCandidateQuery::maxSizeGB();
|
||||
$this->minSizeMB = AdditionalCandidateQuery::minSizeMB();
|
||||
$this->maxSizeBytes = AdditionalCandidateQuery::maxSizeBytes();
|
||||
$this->minSizeBytes = AdditionalCandidateQuery::minSizeBytes();
|
||||
$this->alternateNNTP = (bool) config('nntmux_nntp.use_alternate_nntp_server');
|
||||
$this->ffmpegDuration = (int) (Settings::settingValue('ffmpeg_duration') ?: 5);
|
||||
$this->addPAR2Files = (bool) config('nntmux_settings.add_par2');
|
||||
|
||||
@@ -29,16 +29,10 @@ class ForkingService
|
||||
|
||||
protected PostProcessRunner $postProcessRunner;
|
||||
|
||||
protected int $maxSize;
|
||||
|
||||
protected int $minSize;
|
||||
|
||||
protected int $maxRetries;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->maxSize = (int) Settings::settingValue('maxsizetoprocessnfo');
|
||||
$this->minSize = (int) Settings::settingValue('minsizetoprocessnfo');
|
||||
$this->maxRetries = (int) Settings::settingValue('maxnforetries') >= 0
|
||||
? -((int) Settings::settingValue('maxnforetries') + 1)
|
||||
: NfoService::NFO_UNPROC;
|
||||
|
||||
@@ -830,11 +830,11 @@ class NfoService
|
||||
}
|
||||
|
||||
if ($this->getMaxSize() > 0) {
|
||||
$query->where('size', '<', $this->getMaxSize() * 1073741824);
|
||||
$query->where('size', '<', $this->getMaxSize());
|
||||
}
|
||||
|
||||
if ($this->getMinSize() > 0) {
|
||||
$query->where('size', '>', $this->getMinSize() * 1048576);
|
||||
$query->where('size', '>', $this->getMinSize());
|
||||
}
|
||||
|
||||
return $query;
|
||||
@@ -985,8 +985,8 @@ class NfoService
|
||||
'AND r.nfostatus BETWEEN %d AND %d %s %s',
|
||||
($maxRetries < -8 ? -8 : $maxRetries),
|
||||
self::NFO_UNPROC,
|
||||
($maxSize > 0 ? ('AND r.size < '.($maxSize * 1073741824)) : ''),
|
||||
($minSize > 0 ? ('AND r.size > '.($minSize * 1048576)) : '')
|
||||
($maxSize > 0 ? ('AND r.size < '.$maxSize) : ''),
|
||||
($minSize > 0 ? ('AND r.size > '.$minSize) : '')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Converts release-size settings between bytes (storage format) and the
|
||||
* human-selectable units (MB / GB) shown on the admin settings pages.
|
||||
*/
|
||||
class SizeUnit
|
||||
{
|
||||
public const int MB = 1048576;
|
||||
|
||||
public const int GB = 1073741824;
|
||||
|
||||
public const array UNITS = ['MB', 'GB'];
|
||||
|
||||
/**
|
||||
* Site settings whose values are release sizes stored in bytes.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public const array SITE_SIZE_SETTINGS = [
|
||||
'minsizetoformrelease',
|
||||
'maxsizetoformrelease',
|
||||
'minsizetopostprocess',
|
||||
'maxsizetopostprocess',
|
||||
'minsizetoprocessnfo',
|
||||
'maxsizetoprocessnfo',
|
||||
];
|
||||
|
||||
/**
|
||||
* Convert a value expressed in the given unit to bytes.
|
||||
*
|
||||
* Empty and non-positive values map to 0 ("disabled" semantics).
|
||||
*/
|
||||
public static function toBytes(int|float|string|null $value, string $unit): int
|
||||
{
|
||||
$multiplier = match (strtoupper($unit)) {
|
||||
'MB' => self::MB,
|
||||
'GB' => self::GB,
|
||||
default => throw new InvalidArgumentException("Unsupported size unit [$unit]."),
|
||||
};
|
||||
|
||||
if ($value === null || $value === '' || ! is_numeric($value)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return max(0, (int) round((float) $value * $multiplier));
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a byte count into a value + unit pair for display.
|
||||
*
|
||||
* GB is preferred when the value divides evenly into gibibytes, otherwise
|
||||
* MB is used (rounded to two decimals when not evenly divisible).
|
||||
*
|
||||
* @return array{value: int|float, unit: string}
|
||||
*/
|
||||
public static function fromBytes(int|float|string|null $bytes): array
|
||||
{
|
||||
$bytes = is_numeric($bytes) ? (int) $bytes : 0;
|
||||
|
||||
if ($bytes <= 0) {
|
||||
return ['value' => 0, 'unit' => 'MB'];
|
||||
}
|
||||
|
||||
if ($bytes % self::GB === 0) {
|
||||
return ['value' => intdiv($bytes, self::GB), 'unit' => 'GB'];
|
||||
}
|
||||
|
||||
if ($bytes % self::MB === 0) {
|
||||
return ['value' => intdiv($bytes, self::MB), 'unit' => 'MB'];
|
||||
}
|
||||
|
||||
return ['value' => round($bytes / self::MB, 2), 'unit' => 'MB'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user