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

(Fix) Add/remove featured torrents to external tracker #3766

Merged
merged 1 commit into from
Apr 19, 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
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
4 changes: 4 additions & 0 deletions app/Http/Controllers/API/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/TorrentBuffController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');

Expand Down
4 changes: 4 additions & 0 deletions app/Http/Controllers/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions app/Services/Unit3dAnnounce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<mixed>
*/
Expand Down
Loading