mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 20:17:24 +08:00
improve getDownloadUrl()
This commit is contained in:
@@ -96,9 +96,8 @@ class TorrentRepository extends BaseRepository
|
|||||||
|
|
||||||
$with = ['user', 'tags'];
|
$with = ['user', 'tags'];
|
||||||
$torrents = $query->with($with)->paginate();
|
$torrents = $query->with($with)->paginate();
|
||||||
$userArr = $user->toArray();
|
|
||||||
foreach ($torrents as &$item) {
|
foreach ($torrents as &$item) {
|
||||||
$item->download_url = $this->getDownloadUrl($item->id, $userArr);
|
$item->download_url = $this->getDownloadUrl($item->id, $user);
|
||||||
}
|
}
|
||||||
return $torrents;
|
return $torrents;
|
||||||
}
|
}
|
||||||
@@ -119,11 +118,11 @@ class TorrentRepository extends BaseRepository
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDownloadUrl($id, array $user): string
|
private function getDownloadUrl($id, array|User $user): string
|
||||||
{
|
{
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'%s/download.php?downhash=%s|%s',
|
'%s/download.php?downhash=%s|%s',
|
||||||
getSchemeAndHttpHost(), $user['id'], $this->encryptDownHash($id, $user)
|
getSchemeAndHttpHost(), is_array($user) ? $user['id'] : $user->id, $this->encryptDownHash($id, $user)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,13 +341,15 @@ class TorrentRepository extends BaseRepository
|
|||||||
|
|
||||||
private function getEncryptDownHashKey($user)
|
private function getEncryptDownHashKey($user)
|
||||||
{
|
{
|
||||||
if ($user instanceof User) {
|
if ($user instanceof User && $user->passkey) {
|
||||||
$passkey = $user->passkey;
|
$passkey = $user->passkey;
|
||||||
} elseif (!is_array($user) || empty($user['passkey']) || empty($user['id'])) {
|
} elseif (is_array($user) && !empty($user['passkey'])) {
|
||||||
|
$passkey = $user['passkey'];
|
||||||
|
} elseif (is_scalar($user)) {
|
||||||
$user = User::query()->findOrFail(intval($user), ['id', 'passkey']);
|
$user = User::query()->findOrFail(intval($user), ['id', 'passkey']);
|
||||||
$passkey = $user->passkey;
|
$passkey = $user->passkey;
|
||||||
} else {
|
} else {
|
||||||
$passkey = $user['passkey'];
|
throw new \InvalidArgumentException("Invalid user: " . json_encode($user));
|
||||||
}
|
}
|
||||||
//down hash is relative to user passkey
|
//down hash is relative to user passkey
|
||||||
return md5($passkey . date('Ymd') . $user['id']);
|
return md5($passkey . date('Ymd') . $user['id']);
|
||||||
|
|||||||
Reference in New Issue
Block a user