mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
fix issue #281
This commit is contained in:
@@ -36,6 +36,8 @@ use Illuminate\Support\Str;
|
|||||||
use Nexus\Database\NexusDB;
|
use Nexus\Database\NexusDB;
|
||||||
use Nexus\Imdb\Imdb;
|
use Nexus\Imdb\Imdb;
|
||||||
use Rhilip\Bencode\Bencode;
|
use Rhilip\Bencode\Bencode;
|
||||||
|
use Firebase\JWT\JWT;
|
||||||
|
use Firebase\JWT\Key;
|
||||||
|
|
||||||
class TorrentRepository extends BaseRepository
|
class TorrentRepository extends BaseRepository
|
||||||
{
|
{
|
||||||
@@ -334,13 +336,23 @@ class TorrentRepository extends BaseRepository
|
|||||||
public function encryptDownHash($id, $user): string
|
public function encryptDownHash($id, $user): string
|
||||||
{
|
{
|
||||||
$key = $this->getEncryptDownHashKey($user);
|
$key = $this->getEncryptDownHashKey($user);
|
||||||
return (new Hashids($key))->encode($id);
|
$payload = [
|
||||||
|
'id' => $id,
|
||||||
|
'exp' => time() + 3600
|
||||||
|
];
|
||||||
|
return JWT::encode($payload, $key, 'HS256');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function decryptDownHash($downHash, $user)
|
public function decryptDownHash($downHash, $user)
|
||||||
{
|
{
|
||||||
$key = $this->getEncryptDownHashKey($user);
|
$key = $this->getEncryptDownHashKey($user);
|
||||||
return (new Hashids($key))->decode($downHash);
|
try {
|
||||||
|
$decoded = JWT::decode($downHash, new Key($key, 'HS256'));
|
||||||
|
return [$decoded->id];
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
do_log("Invalid down hash: $downHash, " . $e->getMessage(), "error");
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getEncryptDownHashKey($user)
|
private function getEncryptDownHashKey($user)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.13');
|
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.13');
|
||||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-08-28');
|
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-09-13');
|
||||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||||
|
|||||||
Reference in New Issue
Block a user