diff --git a/app/Filament/Resources/User/BonusLogResource.php b/app/Filament/Resources/User/BonusLogResource.php index b1524696..9a58bc98 100644 --- a/app/Filament/Resources/User/BonusLogResource.php +++ b/app/Filament/Resources/User/BonusLogResource.php @@ -94,6 +94,7 @@ class BonusLogResource extends Resource SelectFilter::make('business_type') ->options(BonusLogs::listStaticProps(Arr::except(BonusLogs::$businessTypes, BonusLogs::$businessTypeBonus), 'bonus-log.business_types', true)) ->label(__('bonus-log.fields.business_type')) + ->searchable(true) , // Tables\Filters\Filter::make('exclude_seeding_bonus') // ->toggle() diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php index 866f2694..db282faf 100644 --- a/app/Http/Controllers/CommentController.php +++ b/app/Http/Controllers/CommentController.php @@ -25,17 +25,8 @@ class CommentController extends Controller */ public function index(Request $request) { - $torrentId = $request->torrent_id; - $with = ['create_user', 'update_user']; - $comments = Comment::query() - ->with($with) - ->where('torrent', $torrentId) - ->paginate(); + $comments = $this->repository->getList($request, Auth::user()); $resource = CommentResource::collection($comments); -// $resource->additional([ -// 'page_title' => nexus_trans('comment.index.page_title'), -// ]); - return $this->success($resource); } diff --git a/app/Http/Resources/CommentResource.php b/app/Http/Resources/CommentResource.php index 4ecaec39..b29e5886 100644 --- a/app/Http/Resources/CommentResource.php +++ b/app/Http/Resources/CommentResource.php @@ -15,15 +15,13 @@ class CommentResource extends JsonResource */ public function toArray($request) { - $descriptionArr = format_description($this->text); return [ 'id' => $this->id, - 'description' => $descriptionArr, - 'images' => get_image_from_description($descriptionArr), - 'updated_at_human' => format_datetime($this->editdate), - 'created_at_human' => $this->added->format('Y-m-d H:i'), + 'text' => $this->text, + 'updated_at' => format_datetime($this->editdate), + 'created_at' => format_datetime($this->added), 'create_user' => new UserResource($this->whenLoaded('create_user')), - 'update_user' => new UserResource($this->whenLoaded('update_user')), + 'update_user' => $this->when($this->editedby > 0, new UserResource($this->whenLoaded('update_user'))), ]; } } diff --git a/app/Models/BonusLogs.php b/app/Models/BonusLogs.php index 4bfd1019..d7e916cb 100644 --- a/app/Models/BonusLogs.php +++ b/app/Models/BonusLogs.php @@ -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'], diff --git a/app/Models/TrackerUrl.php b/app/Models/TrackerUrl.php index 0992bf39..ecca2b6b 100644 --- a/app/Models/TrackerUrl.php +++ b/app/Models/TrackerUrl.php @@ -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; } diff --git a/app/Models/User.php b/app/Models/User.php index 2d61f611..f9000cea 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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); } diff --git a/app/Repositories/ClaimRepository.php b/app/Repositories/ClaimRepository.php index ff19b7ca..1aa53e5a 100644 --- a/app/Repositories/ClaimRepository.php +++ b/app/Repositories/ClaimRepository.php @@ -2,6 +2,7 @@ namespace App\Repositories; use App\Jobs\SettleClaim; +use App\Models\BonusLogs; use App\Models\Claim; use App\Models\Message; use App\Models\Snatch; @@ -260,16 +261,24 @@ class ClaimRepository extends BaseRepository //Wrap with transaction DB::transaction(function () use ($uid, $unReachedIdArr, $toUpdateIdArr, $bonusFinal, $totalDeduct, $uploadedCaseWhen, $seedTimeCaseWhen, $message, $now) { + //get latest + $oldBonus = User::query()->find($uid, ['seedbonus'])->seedbonus; + $delta = 0; //Increase user bonus - User::query()->where('id', $uid)->increment('seedbonus', $bonusFinal); - do_log("Increase user bonus: $bonusFinal", 'alert'); + $delta += $bonusFinal; + do_log("Increase user: $uid bonus: $bonusFinal", 'alert'); + BonusLogs::add($uid, $oldBonus, $bonusFinal, $oldBonus + $bonusFinal, "", BonusLogs::BUSINESS_TYPE_CLAIMED_REACHED); + $oldBonus += $bonusFinal; //Handle unreached if (!empty($unReachedIdArr)) { Claim::query()->whereIn('id', $unReachedIdArr)->delete(); - User::query()->where('id', $uid)->decrement('seedbonus', $totalDeduct); - do_log("Deduct user bonus: $totalDeduct", 'alert'); + $delta -= $totalDeduct; + do_log("Deduct user: $uid bonus: $totalDeduct", 'alert'); + BonusLogs::add($uid, $oldBonus, $totalDeduct, $oldBonus - $totalDeduct, "", BonusLogs::BUSINESS_TYPE_CLAIMED_UNREACHED); + $oldBonus -= $totalDeduct; } + User::query()->where('id', $uid)->increment('seedbonus', $delta); //Update claim `last_settle_at` and init `seed_time_begin` & `uploaded_begin` if (!empty($toUpdateIdArr)) { diff --git a/app/Repositories/CommentRepository.php b/app/Repositories/CommentRepository.php index 76722c50..b81195a1 100644 --- a/app/Repositories/CommentRepository.php +++ b/app/Repositories/CommentRepository.php @@ -9,26 +9,27 @@ use App\Models\Torrent; use App\Models\User; use Carbon\Carbon; use Hamcrest\Core\Set; +use Illuminate\Contracts\Auth\Authenticatable; +use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Nexus\Database\NexusDB; class CommentRepository extends BaseRepository { - public function getList(array $params) + public function getList(Request $request, Authenticatable $user) { $query = Comment::query()->with(['create_user', 'update_user']); - if (!empty($params['torrent_id'])) { - $query->where('torrent', $params['torrent_id']); + if (!empty($request->torrent_id)) { + $query->where('torrent', $request->torrent_id); } - if (!empty($params['offer_id'])) { - $query->where('offer', $params['offer_id']); + if (!empty($request->offer_id)) { + $query->where('offer', $request->offer_id); } - if (!empty($params['request_id'])) { - $query->where('request', $params['request_id']); + if (!empty($request->request_id)) { + $query->where('request', $request->request_id); } - list($sortField, $sortType) = $this->getSortFieldAndType($params); - $query->orderBy($sortField, $sortType); - return $query->paginate(); + $query->orderBy('id', 'desc'); + return $query->paginate($this->getPerPageFromRequest($request)); } public function store(array $params, User $user) diff --git a/include/functions.php b/include/functions.php index 0d45b176..a1426152 100644 --- a/include/functions.php +++ b/include/functions.php @@ -5003,6 +5003,9 @@ function get_searchbox_value($mode = 1, $item = 'showsubcat'){ function get_ratio($userid, $html = true){ $row = get_user_row($userid); + if (empty($row)) { + return "---"; + } $uped = $row['uploaded']; $downed = $row['downloaded']; if ($html == true){ diff --git a/public/js/ptgen.js b/public/js/ptgen.js index 99d57a71..73c75f09 100644 --- a/public/js/ptgen.js +++ b/public/js/ptgen.js @@ -20,7 +20,11 @@ jQuery('.btn-get-pt-gen').on('click', function () { } doInsert(response.data.format, '', false) if (response.data.aka && response.data.site === 'douban') { - form.find("input[name=small_descr]").val(response.data.aka.join("/")) + let aka = response.data.aka + if (response.data.chinese_title) { + aka.unshift(response.data.chinese_title) + } + form.find("input[name=small_descr]").val(aka.join("/")) } if (response.data.imdb_link) { form.find("input[data-pt-gen=url]").val(response.data.imdb_link) diff --git a/public/usercp.php b/public/usercp.php index 22a29d0f..98c7ea5e 100644 --- a/public/usercp.php +++ b/public/usercp.php @@ -1062,7 +1062,7 @@ if (get_setting('seed_box.enabled') == 'yes') {