mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
encrypt download url
This commit is contained in:
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BaseRepository
|
||||
{
|
||||
protected function getSortFieldAndType(array $params)
|
||||
private static $enctyper;
|
||||
|
||||
protected function getSortFieldAndType(array $params): array
|
||||
{
|
||||
$field = $params['sort_field'] ?? 'id';
|
||||
$type = 'desc';
|
||||
@@ -15,4 +18,5 @@ class BaseRepository
|
||||
}
|
||||
return [$field, $type];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ToolRepository extends BaseRepository
|
||||
{
|
||||
private static $encrypter;
|
||||
|
||||
public function backupWeb(): array
|
||||
{
|
||||
@@ -142,4 +145,18 @@ class ToolRepository extends BaseRepository
|
||||
do_log("Final result: " . json_encode($backupResult));
|
||||
return $backupResult;
|
||||
}
|
||||
|
||||
public function getEncrypter(): Encrypter
|
||||
{
|
||||
if (!is_null(self::$encrypter)) {
|
||||
return self::$encrypter;
|
||||
}
|
||||
$key = nexus_env('APP_KEY');
|
||||
$prefix = 'base64:';
|
||||
if (Str::startsWith($key,$prefix)) {
|
||||
$key = substr($key, strlen($prefix));
|
||||
$key = base64_decode($key);
|
||||
}
|
||||
return self::$encrypter = new Encrypter($key, 'AES-256-CBC');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,4 +254,23 @@ class TorrentRepository extends BaseRepository
|
||||
return "$speed/s";
|
||||
}
|
||||
|
||||
public function encryptDownHash($id, $uid): string
|
||||
{
|
||||
$toolRep = new ToolRepository();
|
||||
$payload = [
|
||||
'id' => $id,
|
||||
'uid' => $uid,
|
||||
'date' => date('Ymd'),
|
||||
];
|
||||
return $toolRep->getEncrypter()->encrypt($payload);
|
||||
}
|
||||
|
||||
public function decryptDownHash($downHash)
|
||||
{
|
||||
$toolRep = new ToolRepository();
|
||||
return $toolRep->getEncrypter()->decrypt($downHash);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user