Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Add) Request #3692 #3814

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/Console/Commands/AutoGroup.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* @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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading