Skip to content

Commit

Permalink
Merge pull request #4358 from Roardom/modq-order
Browse files Browse the repository at this point in the history
(Fix) Order torrent creation from most to least important
  • Loading branch information
HDVinnie authored Dec 2, 2024
2 parents 8a5c9ae + e7c3690 commit e71b28c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 40 deletions.
28 changes: 16 additions & 12 deletions app/Http/Controllers/API/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,17 @@ public function store(Request $request): \Illuminate\Http\JsonResponse
// Populate the status/seeders/leechers/times_completed fields for the external tracker
$torrent->refresh();

Unit3dAnnounce::addTorrent($torrent);
// Backup the files contained in the torrent
$files = TorrentTools::getTorrentFiles($decodedTorrent);

if ($torrent->getAttribute('featured')) {
Unit3dAnnounce::addFeaturedTorrent($torrent->id);
foreach ($files as &$file) {
$file['torrent_id'] = $torrent->id;
}

// Can't insert them all at once since some torrents have more files than mysql supports placeholders.
// Divide by 3 since we're inserting 3 fields: name, size and torrent_id
foreach (collect($files)->chunk(intdiv(65_000, 3)) as $files) {
TorrentFile::insert($files->toArray());
}

// Set torrent to featured
Expand All @@ -337,19 +344,16 @@ public function store(Request $request): \Illuminate\Http\JsonResponse
$featuredTorrent->save();
}

// Backup the files contained in the torrent
$files = TorrentTools::getTorrentFiles($decodedTorrent);
// Tracker updates come after database updates in case tracker's offline

foreach ($files as &$file) {
$file['torrent_id'] = $torrent->id;
}
Unit3dAnnounce::addTorrent($torrent);

// Can't insert them all at once since some torrents have more files than mysql supports placeholders.
// Divide by 3 since we're inserting 3 fields: name, size and torrent_id
foreach (collect($files)->chunk(intdiv(65_000, 3)) as $files) {
TorrentFile::insert($files->toArray());
if ($torrent->getAttribute('featured')) {
Unit3dAnnounce::addFeaturedTorrent($torrent->id);
}

// TMDB updates come after tracker updates in case TMDB's offline

$tmdbScraper = new TMDBScraper();

if ($torrent->category->tv_meta && $torrent->tmdb) {
Expand Down
60 changes: 32 additions & 28 deletions app/Http/Controllers/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,6 @@ public function store(StoreTorrentRequest $request): \Illuminate\Http\RedirectRe
// 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);
}

$category = Category::findOrFail($request->integer('category_id'));

// Backup the files contained in the torrent
Expand All @@ -436,6 +430,38 @@ public function store(StoreTorrentRequest $request): \Illuminate\Http\RedirectRe
TorrentFile::insert($files->toArray());
}

// Cover Image for No-Meta Torrents
if ($request->hasFile('torrent-cover')) {
$image_cover = $request->file('torrent-cover');

abort_if(\is_array($image_cover), 400);

$filename_cover = 'torrent-cover_'.$torrent->id.'.jpg';
$path_cover = public_path('/files/img/'.$filename_cover);
Image::make($image_cover->getRealPath())->fit(400, 600)->encode('jpg', 90)->save($path_cover);
}

// Banner Image for No-Meta Torrents
if ($request->hasFile('torrent-banner')) {
$image_cover = $request->file('torrent-banner');

abort_if(\is_array($image_cover), 400);

$filename_cover = 'torrent-banner_'.$torrent->id.'.jpg';
$path_cover = public_path('/files/img/'.$filename_cover);
Image::make($image_cover->getRealPath())->fit(960, 540)->encode('jpg', 90)->save($path_cover);
}

// Tracker updates come after initial database updates in case tracker's offline

Unit3dAnnounce::addTorrent($torrent);

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

// TMDB updates come after tracker updates in case TMDB's offline

// TMDB Meta
if ($torrent->tmdb != 0) {
switch (true) {
Expand All @@ -461,28 +487,6 @@ public function store(StoreTorrentRequest $request): \Illuminate\Http\RedirectRe
Keyword::upsert($keywords->toArray(), ['torrent_id', 'name']);
}

// Cover Image for No-Meta Torrents
if ($request->hasFile('torrent-cover')) {
$image_cover = $request->file('torrent-cover');

abort_if(\is_array($image_cover), 400);

$filename_cover = 'torrent-cover_'.$torrent->id.'.jpg';
$path_cover = public_path('/files/img/'.$filename_cover);
Image::make($image_cover->getRealPath())->fit(400, 600)->encode('jpg', 90)->save($path_cover);
}

// Banner Image for No-Meta Torrents
if ($request->hasFile('torrent-banner')) {
$image_cover = $request->file('torrent-banner');

abort_if(\is_array($image_cover), 400);

$filename_cover = 'torrent-banner_'.$torrent->id.'.jpg';
$path_cover = public_path('/files/img/'.$filename_cover);
Image::make($image_cover->getRealPath())->fit(960, 540)->encode('jpg', 90)->save($path_cover);
}

// check for trusted user and update torrent
if ($user->group->is_trusted && !$request->boolean('mod_queue_opt_in')) {
$appurl = config('app.url');
Expand Down

0 comments on commit e71b28c

Please sign in to comment.