Skip to content

Commit

Permalink
Merge pull request #3783 from HDInnovations/8.x.x
Browse files Browse the repository at this point in the history
(Release) v8.1.0
  • Loading branch information
HDVinnie authored Apr 26, 2024
2 parents 17c49b7 + 1706578 commit 54f6745
Show file tree
Hide file tree
Showing 107 changed files with 2,816 additions and 1,653 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ DB_USERNAME=root
DB_PASSWORD=
#PRISTINE_DB_FILE=/home/vagrant/code/database/unit3d_test.sql

BROADCAST_DRIVER=redis
CACHE_DRIVER=redis
BROADCAST_CONNECTION=redis
CACHE_STORE=redis
SESSION_DRIVER=redis
SESSION_CONNECTION=session
SESSION_LIFETIME=120
Expand Down
24 changes: 9 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,18 @@
# Ignore everything in the public/files directory EXCEPT the .gitkeep
/public/files
!.gitkeep

/public/css
/public/fonts
/public/img
/public/js
/public/sounds
/public/vendor
/public/mix-manifest.json
/public/mix-sri.json

/storage/backups
/storage/gitupdate
/storage/*.key

/vendor
/.vagrant
Homestead.json
Homestead.yaml
npm-debug.log
.env
laravel-echo-server.json
laravel-echo-server.lock

# Composer
/vendor

# Vite
/public/build

Expand All @@ -43,7 +32,12 @@ laravel-echo-server.lock

# Vim
.*.swp
_ide_helper.php

# Miscellaneous
/.vagrant
Homestead.json
Homestead.yaml
npm-debug.log
_ide_helper.php
supervisor.ini
/.phpunit.cache/
27 changes: 16 additions & 11 deletions app/Console/Commands/AutoGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace App\Console\Commands;

use App\Enums\UserGroup;
use App\Helpers\ByteUnits;
use App\Models\Group;
use App\Models\User;
use App\Services\Unit3dAnnounce;
Expand Down Expand Up @@ -44,11 +43,11 @@ class AutoGroup extends Command
/**
* Execute the console command.
*/
public function handle(ByteUnits $byteUnits): void
public function handle(): void
{
$now = now();
// Temp Hard Coding of Immune Groups (Config Files To Come)
$current = Carbon::now();

$groups = Group::query()
->where('autogroup', '=', 1)
->orderBy('position')
Expand All @@ -64,19 +63,25 @@ public function handle(ByteUnits $byteUnits): void
$seedtime = null;

foreach ($groups as $group) {
$seedtime ??= DB::table('history')
->whereNull('deleted_at')
->where('user_id', '=', $user->id)
->avg('seedtime') ?? 0;

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

if (
//short circuit when the values are 0 or null
($group->min_uploaded ? $group->min_uploaded <= $user->uploaded : true)
&& ($group->min_ratio ? $group->min_ratio <= $user->ratio : true)
&& ($group->min_age ? $user->created_at->addRealSeconds($group->min_age)->isBefore($current) : true)
&& ($group->min_avg_seedtime ? $group->min_avg_seedtime <= ($seedtime ??= DB::table('history')->where('user_id', '=', $user->id)->avg('seedtime') ?? 0) : true)
&& ($group->min_seedsize ? $group->min_seedsize <= ($seedsize ??= $user->seedingTorrents()->sum('size')) : true)
(!$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))
) {
$user->group_id = $group->id;

// Leech ratio dropped below sites minimum

if ($user->group_id == UserGroup::LEECH->value) {
if ($user->group_id === UserGroup::LEECH->value) {
$user->can_request = false;
$user->can_invite = false;
$user->can_download = false;
Expand All @@ -96,7 +101,7 @@ public function handle(ByteUnits $byteUnits): void
}
}

$elapsed = now()->floatDiffInSeconds($now);
$elapsed = now()->diffInSeconds($now);
$this->comment('Automated User Group Command Complete ('.$elapsed.')');
}
}
21 changes: 11 additions & 10 deletions app/Console/Commands/AutoPreWarning.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AutoPreWarning extends Command
*
* @var string
*/
protected $description = 'Automatically Sends Pre Warning PM To Users';
protected $description = 'Automatically Sends Pre Warning Notifications To Users';

/**
* Execute the console command.
Expand All @@ -58,9 +58,9 @@ public function handle(): void
->where('updated_at', '<', $carbon->copy()->subDays(config('hitrun.prewarn'))->toDateTimeString())
->get();

$usersWithPreWarnings = [];

foreach ($prewarn as $pre) {
// Skip Prewarning if Torrent is NULL
// e.g. Torrent has been Rejected by a Moderator after it has been downloaded and not deleted
if (null === $pre->torrent) {
continue;
}
Expand All @@ -71,20 +71,21 @@ public function handle(): void
->where('user_id', '=', $pre->user->id)
->first();

// Send Pre Warning PM If Actual Warning Doesnt Already Exsist
if ($exsist === null) {
$timeleft = config('hitrun.grace') - config('hitrun.prewarn');

// Send Notifications
$pre->user->notify(new UserPreWarning($pre->user, $pre->torrent));

// Set History Prewarn
$pre->prewarn = true;
$pre->timestamps = false;
$pre->save();

// Add user to usersWithWarnings array
$usersWithPreWarnings[$pre->user->id] = $pre->user;
}
}
}

// Send a single notification for each user with warnings
foreach ($usersWithPreWarnings as $user) {
$user->notify(new UserPreWarning($user));
}
}

$this->comment('Automated User Pre-Warning Command Complete');
Expand Down
4 changes: 1 addition & 3 deletions app/Console/Commands/AutoRefundDownload.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ class AutoRefundDownload extends Command

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
public function handle(): void
{
$now = Carbon::now();
$MIN_SEEDTIME = config('hitrun.seedtime');
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/AutoRemoveFeaturedTorrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function handle(): void
sprintf('Ladies and Gents, [url=%s/torrents/%s]%s[/url] is no longer featured.', $appurl, $torrent->id, $torrent->name)
);

Unit3dAnnounce::addTorrent($torrent);
Unit3dAnnounce::removeFeaturedTorrent($torrent->id);
}

// Delete The Record From DB
Expand Down
13 changes: 10 additions & 3 deletions app/Console/Commands/AutoWarning.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function handle(): void
->where('updated_at', '<', $carbon->copy()->subDays(config('hitrun.grace'))->toDateTimeString())
->get();

$usersWithWarnings = [];

foreach ($hitrun as $hr) {
if (!$hr->user->group->is_immune && $hr->actual_downloaded > ($hr->torrent->size * (config('hitrun.buffer') / 100))) {
$exsist = Warning::withTrashed()
Expand All @@ -84,13 +86,18 @@ public function handle(): void
$hr->user->hitandruns++;
$hr->user->save();

// Send Notifications
$hr->user->notify(new UserWarning($hr->user, $hr->torrent));

$hr->timestamps = false;
$hr->save();

// Add user to usersWithWarnings array
$usersWithWarnings[$hr->user->id] = $hr->user;
}
}

// Send a single notification for each user with warnings
foreach ($usersWithWarnings as $user) {
$user->notify(new UserWarning($user));
}
}

// Calculate User Warning Count and Disable DL Priv If Required.
Expand Down
32 changes: 23 additions & 9 deletions app/Http/Controllers/API/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use App\Models\User;
use App\Repositories\ChatRepository;
use App\Services\Tmdb\TMDBScraper;
use App\Services\Unit3dAnnounce;
use App\Traits\TorrentMeta;
use Exception;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -79,10 +80,12 @@ public function index(): TorrentsResource
)
->latest('sticky')
->latest('bumped_at')
->paginate(25);
->cursorPaginate(25);

// See app/Traits/TorrentMeta.php
return $this->scopeMeta($torrents);
$this->scopeMeta($torrents);

return $torrents;
});

return new TorrentsResource($torrents);
Expand Down Expand Up @@ -164,13 +167,13 @@ public function store(Request $request): \Illuminate\Http\JsonResponse
$du_until = $request->input('du_until');

if (($user->group->is_modo || $user->group->is_internal) && isset($du_until)) {
$torrent->du_until = Carbon::now()->addDays($request->input('du_until'));
$torrent->du_until = Carbon::now()->addDays($request->integer('du_until'));
}
$torrent->free = $user->group->is_modo || $user->group->is_internal ? ($request->input('free') ?? 0) : 0;
$fl_until = $request->input('fl_until');

if (($user->group->is_modo || $user->group->is_internal) && isset($fl_until)) {
$torrent->fl_until = Carbon::now()->addDays($request->input('fl_until'));
$torrent->fl_until = Carbon::now()->addDays($request->integer('fl_until'));
}
$torrent->sticky = $user->group->is_modo || $user->group->is_internal ? ($request->input('sticky') ?? 0) : 0;
$torrent->moderated_at = Carbon::now();
Expand Down Expand Up @@ -311,8 +314,17 @@ public function store(Request $request): \Illuminate\Http\JsonResponse
// Save The Torrent
$torrent->save();

// Populate the status/seeders/leechers/times_completed fields for the external tracker
$torrent->refresh();

Unit3dAnnounce::addTorrent($torrent);

if ($torrent->getAttribute('featured')) {
Unit3dAnnounce::addFeaturedTorrent($torrent->id);
}

// Set torrent to featured
if ($torrent->featured == 1) {
if ($torrent->getAttribute('featured')) {
$featuredTorrent = new FeaturedTorrent();
$featuredTorrent->user_id = $user->id;
$featuredTorrent->torrent_id = $torrent->id;
Expand Down Expand Up @@ -363,7 +375,7 @@ public function store(Request $request): \Illuminate\Http\JsonResponse
$user = $torrent->user;
$username = $user->username;
$anon = $torrent->anon;
$featured = $torrent->featured;
$featured = $torrent->getAttribute('featured');
$free = $torrent->free;
$doubleup = $torrent->doubleup;

Expand Down Expand Up @@ -499,7 +511,7 @@ public function filter(Request $request): TorrentsResource|\Illuminate\Http\Json
$cacheKey = $url.'?'.$queryString;

$torrents = cache()->remember($cacheKey, 300, function () use ($request, $isRegex) {
$torrents = Torrent::with(['user:id,username', 'category', 'type', 'resolution', 'distributor', 'region'])
$torrents = Torrent::with(['user:id,username', 'category', 'type', 'resolution', 'distributor', 'region', 'files'])
->select('*')
->selectRaw("
CASE
Expand Down Expand Up @@ -546,10 +558,12 @@ public function filter(Request $request): TorrentsResource|\Illuminate\Http\Json
->when($request->filled('episodeNumber'), fn ($query) => $query->ofEpisode((int) $request->episodeNumber))
->latest('sticky')
->orderBy($request->input('sortField') ?? $this->sortField, $request->input('sortDirection') ?? $this->sortDirection)
->paginate(min($request->input('perPage') ?? $this->perPage, 100));
->cursorPaginate(min($request->input('perPage') ?? $this->perPage, 100));

// See app/Traits/TorrentMeta.php
return $this->scopeMeta($torrents);
$this->scopeMeta($torrents);

return $torrents;
});

if ($torrents !== null) {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
abstract class Controller extends BaseController
{
use AuthorizesRequests;
use ValidatesRequests;
Expand Down
Loading

0 comments on commit 54f6745

Please sign in to comment.