update: torrent api

- add keywords support
This commit is contained in:
HDVinnie
2020-12-15 22:31:49 -05:00
parent 23eb6b3a68
commit 45d9602d17
@@ -13,6 +13,7 @@
namespace App\Http\Controllers\API;
use App\Models\Keyword;
use App\Helpers\Bencode;
use App\Helpers\MediaInfo;
use App\Helpers\TorrentHelper;
@@ -208,6 +209,15 @@ class TorrentController extends BaseController
}
}
// Torrent Keywords System
$keywords = self::parseKeywords($request->input('keywords'));
foreach ($keywords as $keyword) {
$tag = new Keyword();
$tag->name = $keyword;
$tag->torrent_id = $torrent->id;
$tag->save();
}
// check for trusted user and update torrent
if ($user->group->is_trusted) {
$appurl = \config('app.url');
@@ -510,4 +520,25 @@ class TorrentController extends BaseController
return $mediainfo;
}
/**
* Parse Torrent Keywords.
*
* @param $text
*
* @return array
*/
private static function parseKeywords($text)
{
$parts = explode(', ', $text);
$result = [];
foreach ($parts as $part) {
$part = trim($part);
if ($part != '') {
$result[] = $part;
}
}
return $result;
}
}