fix: auth caching api between users

Don't cache rsskeys of users and provide the responses to other users.
This commit is contained in:
Roardom
2024-09-15 17:43:16 +00:00
parent b313751581
commit f8b31e2cdd
@@ -645,8 +645,6 @@ class TorrentController extends BaseController
'type_id' => $hit['type']['id'] ?? null,
'resolution_id' => $hit['resolution']['id'] ?? null,
'created_at' => date('Y-m-d\TH:i:s.Z\Z', $hit['created_at']),
'download_link' => route('torrent.download.rsskey', ['id' => $hit['id'], 'rsskey' => auth('api')->user()->rsskey]),
'magnet_link' => config('torrent.magnet') ? 'magnet:?dn='.$hit['name'].'&xt=urn:btih:'.$hit['info_hash'].'&as='.route('torrent.download.rsskey', ['id' => $hit['id'], 'rsskey' => auth('api')->user()->rsskey]).'&tr='.route('announce', ['passkey' => auth('api')->user()->passkey]).'&xl='.$hit['size'] : null,
'details_link' => route('torrents.show', ['id' => $hit['id']]),
]
]);
@@ -667,6 +665,14 @@ class TorrentController extends BaseController
$page = $request->integer('page') ?: 1;
$perPage = min(100, $request->integer('perPage') ?: 25);
// Auth keys must not be cached
$torrents->through(function ($torrent) {
$torrent['attributes']['download_link'] = route('torrent.download.rsskey', ['id' => $torrent['id'], 'rsskey' => auth('api')->user()->rsskey]);
$torrent['attributes']['magnet_link'] = config('torrent.magnet') ? 'magnet:?dn='.$torrent['attributes']['name'].'&xt=urn:btih:'.$torrent['attributes']['info_hash'].'&as='.route('torrent.download.rsskey', ['id' => $torrent['id'], 'rsskey' => auth('api')->user()->rsskey]).'&tr='.route('announce', ['passkey' => auth('api')->user()->passkey]).'&xl='.$torrent['attributes']['size'] : null;
return $torrent;
});
return response()->json([
'data' => $torrents->items(),
'links' => [