mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-22 02:47:27 +08:00
Merge branch '1.9' into php8
This commit is contained in:
@@ -42,6 +42,7 @@ class BonusLogs extends NexusModel
|
||||
const BUSINESS_TYPE_TASK_NOT_PASS_DEDUCT = 20;
|
||||
const BUSINESS_TYPE_TASK_PASS_REWARD = 21;
|
||||
const BUSINESS_TYPE_REWARD_TORRENT = 22;
|
||||
const BUSINESS_TYPE_CLAIMED_UNREACHED = 23;
|
||||
|
||||
//获得类,普通获得,1000 起步
|
||||
const BUSINESS_TYPE_ROLE_WORK_SALARY = 1000;
|
||||
@@ -50,6 +51,7 @@ class BonusLogs extends NexusModel
|
||||
const BUSINESS_TYPE_RECEIVE_GIFT = 1003;
|
||||
const BUSINESS_TYPE_UPLOAD_TORRENT = 1004;
|
||||
const BUSINESS_TYPE_TORRENT_BE_REWARD = 1005;
|
||||
const BUSINESS_TYPE_CLAIMED_REACHED = 1006;
|
||||
|
||||
//获得类,做种获得,10000 起
|
||||
const BUSINESS_TYPE_SEEDING_BASIC = 10000;
|
||||
@@ -81,6 +83,7 @@ class BonusLogs extends NexusModel
|
||||
self::BUSINESS_TYPE_TASK_NOT_PASS_DEDUCT => ['text' => 'Task failure penalty'],
|
||||
self::BUSINESS_TYPE_TASK_PASS_REWARD => ['text' => 'Task success reward'],
|
||||
self::BUSINESS_TYPE_REWARD_TORRENT => ['text' => 'Reward torrent'],
|
||||
self::BUSINESS_TYPE_CLAIMED_UNREACHED => ['text' => 'Claimed torrent unreached'],
|
||||
|
||||
self::BUSINESS_TYPE_ROLE_WORK_SALARY => ['text' => 'Role work salary'],
|
||||
self::BUSINESS_TYPE_TORRENT_BE_DOWNLOADED => ['text' => 'Torrent be downloaded'],
|
||||
@@ -88,6 +91,7 @@ class BonusLogs extends NexusModel
|
||||
self::BUSINESS_TYPE_RECEIVE_GIFT => ['text' => 'Receive gift'],
|
||||
self::BUSINESS_TYPE_UPLOAD_TORRENT => ['text' => 'Upload torrent'],
|
||||
self::BUSINESS_TYPE_TORRENT_BE_REWARD => ['text' => 'Torrent be reward'],
|
||||
self::BUSINESS_TYPE_CLAIMED_REACHED => ['text' => 'Claimed torrent reached'],
|
||||
|
||||
self::BUSINESS_TYPE_SEEDING_BASIC => ['text' => 'Seeding basic'],
|
||||
self::BUSINESS_TYPE_SEEDING_DONOR_ADDITION => ['text' => 'Seeding donor addition'],
|
||||
|
||||
@@ -85,13 +85,23 @@ class TrackerUrl extends NexusModel
|
||||
if ($redis->exists($notFoundFlagKey)) {
|
||||
return false;
|
||||
}
|
||||
self::saveUrlCache();
|
||||
$result = call_user_func_array([$redis, $command], $params);
|
||||
if ($result !== false) {
|
||||
return $result;
|
||||
$lockKey = "$notFoundFlagKey:lock";
|
||||
if (!$redis->set($lockKey, 1, ["nx", "ex" => 5])) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
self::saveUrlCache();
|
||||
$result = call_user_func_array([$redis, $command], $params);
|
||||
if ($result !== false) {
|
||||
return $result;
|
||||
}
|
||||
//只从 db 拉取一次,仍然没有即标记不存在, 有效期 15 分钟
|
||||
$redis->setex($notFoundFlagKey, 900, date("Y-m-d H:i:s"));
|
||||
} catch (\Throwable $throwable) {
|
||||
do_log($throwable->getMessage(), 'error');
|
||||
} finally {
|
||||
$redis->del($lockKey);
|
||||
}
|
||||
//只从 db 拉取一次,仍然没有即标记不存在, 有效期 15 分钟
|
||||
$redis->setex($notFoundFlagKey, 900, date("Y-m-d H:i:s"));
|
||||
do_log(sprintf("redis command %s with args %s no result", $command, json_encode($params)), 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
+25
-2
@@ -6,6 +6,7 @@ use App\Exceptions\NexusException;
|
||||
use App\Http\Middleware\Locale;
|
||||
use App\Models\Traits\NexusActivityLogTrait;
|
||||
use App\Repositories\ExamRepository;
|
||||
use App\Repositories\TokenRepository;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
@@ -635,10 +636,32 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
return is_null($this->original['notifs']) || str_contains($this->notifs, "[{$name}]");
|
||||
}
|
||||
|
||||
public function tokenCan(string $ability)
|
||||
public function tokenCan(string $ability): bool
|
||||
{
|
||||
$redis = NexusDB::redis();
|
||||
return $redis->sismember(Setting::USER_TOKEN_PERMISSION_ALLOWED_CACHE_KRY, $ability)
|
||||
$cacheKey = Setting::USER_TOKEN_PERMISSION_ALLOWED_CACHE_KRY;
|
||||
if (!$redis->exists($cacheKey)) {
|
||||
$lockKey = "$cacheKey:lock";
|
||||
if ($redis->set($lockKey, 1, ['nx', 'ex' => 5])) {
|
||||
try {
|
||||
if (!$redis->exists($cacheKey)) {
|
||||
$abilities = TokenRepository::listUserTokenPermissions(false);
|
||||
do_log("load user token permissions: " . json_encode($abilities), 'alert');
|
||||
if (!empty($abilities)) {
|
||||
$redis->sadd($cacheKey, ...$abilities);
|
||||
} else {
|
||||
$redis->sadd($cacheKey, "__NO_USER_TOKEN_PERMISSION__");
|
||||
$redis->expire($cacheKey, 900);
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $throwable) {
|
||||
do_log($throwable->getMessage(), 'error');
|
||||
} finally {
|
||||
$redis->del($lockKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $redis->sismember($cacheKey, $ability)
|
||||
&& $this->accessToken && $this->accessToken->can($ability);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user