diff --git a/app/Console/Commands/AutoRemoveFeaturedTorrent.php b/app/Console/Commands/AutoRemoveFeaturedTorrent.php index d5a4072c20..b44e6ecc0a 100644 --- a/app/Console/Commands/AutoRemoveFeaturedTorrent.php +++ b/app/Console/Commands/AutoRemoveFeaturedTorrent.php @@ -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 diff --git a/app/Http/Controllers/API/TorrentController.php b/app/Http/Controllers/API/TorrentController.php index f57a155560..3c31bef6b6 100644 --- a/app/Http/Controllers/API/TorrentController.php +++ b/app/Http/Controllers/API/TorrentController.php @@ -316,6 +316,10 @@ public function store(Request $request): \Illuminate\Http\JsonResponse Unit3dAnnounce::addTorrent($torrent); + if ($torrent->featured) { + Unit3dAnnounce::addFeaturedTorrent($torrent->id); + } + // Set torrent to featured if ($torrent->featured == 1) { $featuredTorrent = new FeaturedTorrent(); diff --git a/app/Http/Controllers/TorrentBuffController.php b/app/Http/Controllers/TorrentBuffController.php index 9405cb36cb..7f104090a6 100644 --- a/app/Http/Controllers/TorrentBuffController.php +++ b/app/Http/Controllers/TorrentBuffController.php @@ -142,7 +142,7 @@ public function grantFeatured(Request $request, int $id): \Illuminate\Http\Redir $torrent->featured = true; $torrent->save(); - Unit3dAnnounce::addTorrent($torrent); + Unit3dAnnounce::addFeaturedTorrent($torrent->id); $featured = new FeaturedTorrent(); $featured->user_id = $user->id; @@ -180,7 +180,7 @@ public function revokeFeatured(Request $request, int $id): \Illuminate\Http\Redi $torrent->featured = false; $torrent->save(); - Unit3dAnnounce::addTorrent($torrent); + Unit3dAnnounce::removeFeaturedTorrent($torrent->id); $appurl = config('app.url'); diff --git a/app/Http/Controllers/TorrentController.php b/app/Http/Controllers/TorrentController.php index 071f62dea7..92d69eab75 100644 --- a/app/Http/Controllers/TorrentController.php +++ b/app/Http/Controllers/TorrentController.php @@ -410,6 +410,10 @@ public function store(StoreTorrentRequest $request): \Illuminate\Http\RedirectRe Unit3dAnnounce::addTorrent($torrent); + if ($torrent->getAttribute('featured')) { + Unit3dAnnounce::addFeaturedTorrent($torrent->id); + } + // Count and save the torrent number in this category $category = Category::findOrFail($request->integer('category_id')); $category->num_torrent = $category->torrents()->count(); diff --git a/app/Services/Unit3dAnnounce.php b/app/Services/Unit3dAnnounce.php index f45781e581..8de9b8302e 100644 --- a/app/Services/Unit3dAnnounce.php +++ b/app/Services/Unit3dAnnounce.php @@ -280,6 +280,20 @@ public static function removePersonalFreeleech(int $user_id): bool ]); } + public static function addFeaturedTorrent(int $torrent_id): bool + { + return self::put('featured-torrents', [ + 'torrent_id' => $torrent_id, + ]); + } + + public static function removeFeaturedTorrent(int $torrent_id): bool + { + return self::delete('featured-torrents', [ + 'torrent_id' => $torrent_id, + ]); + } + /** * @return bool|array */