Skip to content

Commit

Permalink
Merge pull request #3814 from HDInnovations/Request-3692
Browse files Browse the repository at this point in the history
(Add) Request #3692
  • Loading branch information
HDVinnie committed May 8, 2024
2 parents 42136ed + 08abf6d commit 1bca8ca
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 8 deletions.
6 changes: 5 additions & 1 deletion app/Console/Commands/AutoGroup.php
Expand Up @@ -60,8 +60,9 @@ final public function handle(): void

foreach ($users as $user) {
// memoize when necessary
$seedsize = null;
$seedtime = null;
$seedsize = null;
$uploads = null;

foreach ($groups as $group) {
$seedtime ??= DB::table('history')
Expand All @@ -70,13 +71,16 @@ final public function handle(): void

$seedsize ??= $user->seedingTorrents()->sum('size');

$uploads ??= $user->torrents()->count();

if (
//short circuit when the values are 0 or null
(!$group->min_uploaded || $group->min_uploaded <= $user->uploaded)
&& (!$group->min_ratio || $group->min_ratio <= $user->ratio)
&& (!$group->min_age || $user->created_at->addSeconds($group->min_age)->isBefore($current))
&& (!$group->min_avg_seedtime || $group->min_avg_seedtime <= ($seedtime))
&& (!$group->min_seedsize || $group->min_seedsize <= ($seedsize))
&& (!$group->min_uploads || $group->min_uploads <= ($uploads))
) {
$user->group_id = $group->id;

Expand Down
12 changes: 5 additions & 7 deletions app/Http/Controllers/StatsController.php
Expand Up @@ -341,16 +341,14 @@ public function group(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\V
public function groupsRequirements(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
$user = auth()->user();
$user_avg_seedtime = DB::table('history')->where('user_id', '=', $user->id)->avg('seedtime');
$user_account_age = Carbon::now()->diffInSeconds($user->created_at);
$user_seed_size = $user->seedingTorrents()->sum('size');

return view('stats.groups.groups-requirements', [
'current' => Carbon::now(),
'user' => auth()->user(),
'user_avg_seedtime' => $user_avg_seedtime,
'user_account_age' => $user_account_age,
'user_seed_size' => $user_seed_size,
'user' => $user,
'user_avg_seedtime' => DB::table('history')->where('user_id', '=', $user->id)->avg('seedtime'),
'user_account_age' => Carbon::now()->diffInSeconds($user->created_at),
'user_seed_size' => $user->seedingTorrents()->sum('size'),
'user_uploads' => $user->torrents()->count(),
'groups' => Group::orderBy('position')->where('is_modo', '=', 0)->get(),
]);
}
Expand Down
7 changes: 7 additions & 0 deletions app/Http/Requests/Staff/StoreGroupRequest.php
Expand Up @@ -147,6 +147,13 @@ public function rules(Request $request): array
'min:0',
], 'prohibited'),
],
'min_uploads' => [
Rule::when($request->boolean('autogroup'), [
'sometimes',
'integer',
'min:0',
], 'prohibited'),
],
];
}
}
7 changes: 7 additions & 0 deletions app/Http/Requests/Staff/UpdateGroupRequest.php
Expand Up @@ -153,6 +153,13 @@ public function rules(Request $request): array
'min:0',
], 'nullable'),
],
'min_uploads' => [
Rule::when($request->boolean('autogroup'), [
'sometimes',
'integer',
'min:0',
], 'nullable'),
],
];
}

Expand Down
1 change: 1 addition & 0 deletions app/Models/Group.php
Expand Up @@ -49,6 +49,7 @@
* @property int $min_avg_seedtime
* @property float $min_ratio
* @property int $min_age
* @property int $min_uploads
*/
class Group extends Model
{
Expand Down
@@ -0,0 +1,30 @@
<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('groups', function (Blueprint $table): void {
$table->unsignedBigInteger('min_uploads')->nullable();
});

DB::table('groups')->where('autogroup', '=', 1)->update(['min_uploads' => 0]);
}
};
12 changes: 12 additions & 0 deletions resources/views/Staff/group/create.blade.php
Expand Up @@ -299,6 +299,18 @@ class="form__text"
Minimum seedsize required
</label>
</p>
<p class="form__group" x-show="autogroup" x-cloak>
<input
id="min_uploads"
class="form__text"
type="text"
name="min_uploads"
placeholder=" "
/>
<label class="form__label form__label--floating" for="min_uploads">
Minimum uploads required
</label>
</p>
<p class="form__group">
<button class="form__button form__button--filled">
{{ __('common.add') }}
Expand Down
13 changes: 13 additions & 0 deletions resources/views/Staff/group/edit.blade.php
Expand Up @@ -359,6 +359,19 @@ class="form__text"
Minimum seedsize
</label>
</p>
<p class="form__group">
<input
id="min_uploads"
class="form__text"
type="text"
name="min_uploads"
placeholder=" "
value="{{ $group->min_uploads }}"
/>
<label class="form__label form__label--floating" for="min_uploads">
Minimum uploads
</label>
</p>
</fieldset>
</div>
<p class="form__group">
Expand Down
2 changes: 2 additions & 0 deletions resources/views/Staff/group/index.blade.php
Expand Up @@ -250,12 +250,14 @@ class="{{ config('other.font-awesome') }} fa-times text-red"
<td>
{{ \App\Helpers\StringHelper::formatBytes($group->min_seedsize ?? 0) }}
</td>
<td>{{ $group->min_uploads }}</td>
@else
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
@endif
</tr>
@endforeach
Expand Down
19 changes: 19 additions & 0 deletions resources/views/stats/groups/groups-requirements.blade.php
Expand Up @@ -158,6 +158,25 @@ class="{{ config('other.font-awesome') }} fa-x text-red"
@endif
</td>
</tr>
<tr>
<td>Min. Uploads</td>
<td>
{{ $group->min_uploads ?? 0 }}
</td>
<td>
@if ($group->min_uploads <= $user_uploads)
<i
class="{{ config('other.font-awesome') }} fa-check text-green"
></i>
@else
<i
class="{{ config('other.font-awesome') }} fa-x text-red"
></i>
|
{{ $group->min_uploads - $user_uploads }}
@endif
</td>
</tr>
</tbody>
</table>
@else
Expand Down

0 comments on commit 1bca8ca

Please sign in to comment.