mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-05-02 10:37:23 +08:00
[admin] filter improve & fix ad link
This commit is contained in:
@@ -60,7 +60,7 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
echo date('Y-m-d H:i:s', 1623820546);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -82,8 +82,9 @@ class Handler extends ExceptionHandler
|
||||
} else {
|
||||
$msg = 'Server Error';
|
||||
}
|
||||
$msg = $e->getMessage();
|
||||
$trace = $e->getTraceAsString();
|
||||
if (config('app.debug')) {
|
||||
$msg = $e->getMessage();
|
||||
$data['trace'] = $e->getTraceAsString();
|
||||
}
|
||||
return new JsonResponse(
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Models\Exam;
|
||||
use App\Repositories\ExamRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
@@ -113,4 +114,11 @@ class ExamController extends Controller
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
$result = Exam::query()->orderBy('id', 'desc')->get();
|
||||
$resource = ExamResource::collection($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class TorrentController extends Controller
|
||||
$params = $request->all();
|
||||
$params['visible'] = Torrent::VISIBLE_YES;
|
||||
$params['category_mode'] = Setting::get('main.browsecat');
|
||||
$result = $this->repository->getList($params);
|
||||
$result = $this->repository->getList($params, Auth::user());
|
||||
$resource = TorrentResource::collection($result);
|
||||
$resource->additional([
|
||||
'page_title' => nexus_trans('torrent.index.page_title'),
|
||||
@@ -51,9 +51,8 @@ class TorrentController extends Controller
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$with = ['user', 'basic_audio_codec', 'basic_category', 'basic_codec', 'basic_media', 'basic_source', 'basic_standard', 'basic_team'];
|
||||
|
||||
$result = Torrent::query()->with($with)->withCount(['peers', 'thank_users'])->visible()->findOrFail($id);
|
||||
$result = $this->repository->getDetail($id, Auth::user());
|
||||
|
||||
$isBookmarked = Auth::user()->bookmarks()->where('torrentid', $id)->exists();
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ class TorrentResource extends JsonResource
|
||||
'seeders' => $this->seeders,
|
||||
'times_completed' => $this->times_completed,
|
||||
'numfiles' => $this->numfiles,
|
||||
'download_url' => $this->download_url,
|
||||
'user' => new UserResource($this->whenLoaded('user')),
|
||||
'basic_category' => new CategoryResource($this->whenLoaded('basic_category')),
|
||||
];
|
||||
|
||||
@@ -28,7 +28,7 @@ class UserResource extends JsonResource
|
||||
'uploaded_text' => mksize($this->uploaded),
|
||||
'downloaded' => $this->downloaded,
|
||||
'downloaded_text' => mksize($this->downloaded),
|
||||
'seed_bonus' => $this->seedbonus,
|
||||
'bonus' => $this->seedbonus,
|
||||
'seed_points' => floatval($this->seed_points),
|
||||
'seedtime' => $this->seedtime,
|
||||
'seedtime_text' => mkprettytime($this->seedtime),
|
||||
|
||||
@@ -32,6 +32,8 @@ class HitAndRun extends NexusModel
|
||||
self::MODE_GLOBAL => ['text' => 'Global'],
|
||||
];
|
||||
|
||||
const MINIMUM_IGNORE_USER_CLASS = User::CLASS_VIP;
|
||||
|
||||
public function getStatusTextAttribute()
|
||||
{
|
||||
return nexus_trans('hr.status_' . $this->status);
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ class User extends Authenticatable
|
||||
'downloaded_human' => '下载量',
|
||||
'share_ratio' => '分享率',
|
||||
// 'seed_time' => '做种时间',
|
||||
'seed_bonus' => '魔力值',
|
||||
'bonus' => '魔力值',
|
||||
'seed_points' => '做种积分',
|
||||
'invites' => '邀请',
|
||||
];
|
||||
|
||||
@@ -11,7 +11,7 @@ class BaseRepository
|
||||
|
||||
protected function getSortFieldAndType(array $params): array
|
||||
{
|
||||
$field = $params['sort_field'] ?? 'id';
|
||||
$field = !empty($params['sort_field']) ? $params['sort_field'] : 'id';
|
||||
$type = 'desc';
|
||||
if (!empty($params['sort_type']) && Str::startsWith($params['sort_type'], 'asc')) {
|
||||
$type = 'asc';
|
||||
|
||||
@@ -302,6 +302,12 @@ class ExamRepository extends BaseRepository
|
||||
if (!empty($params['exam_id'])) {
|
||||
$query->where('exam_id', $params['exam_id']);
|
||||
}
|
||||
if (isset($params['is_done']) && is_numeric($params['is_done'])) {
|
||||
$query->where('is_done', $params['is_done']);
|
||||
}
|
||||
if (isset($params['status']) && is_numeric($params['status'])) {
|
||||
$query->where('status', $params['status']);
|
||||
}
|
||||
list($sortField, $sortType) = $this->getSortFieldAndType($params);
|
||||
$query->orderBy($sortField, $sortType);
|
||||
$result = $query->with(['user', 'exam'])->paginate();
|
||||
|
||||
@@ -70,7 +70,7 @@ class HitAndRunRepository extends BaseRepository
|
||||
}
|
||||
|
||||
//If is VIP or above, pass
|
||||
if ($row->user->class >= User::CLASS_VIP) {
|
||||
if ($row->user->class >= HitAndRun::MINIMUM_IGNORE_USER_CLASS) {
|
||||
$result = $this->reachedBySpecialUserClass($row);
|
||||
if ($result) {
|
||||
$successCounts++;
|
||||
|
||||
@@ -33,7 +33,7 @@ class TorrentRepository extends BaseRepository
|
||||
* @param array $params
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public function getList(array $params)
|
||||
public function getList(array $params, User $user)
|
||||
{
|
||||
$query = Torrent::query();
|
||||
if (!empty($params['category'])) {
|
||||
@@ -84,9 +84,29 @@ class TorrentRepository extends BaseRepository
|
||||
|
||||
$with = ['user'];
|
||||
$torrents = $query->with($with)->paginate();
|
||||
$userArr = $user->toArray();
|
||||
foreach($torrents as &$item) {
|
||||
$item->download_url = $this->getDownloadUrl($item->id, $userArr);
|
||||
}
|
||||
return $torrents;
|
||||
}
|
||||
|
||||
public function getDetail($id, User $user)
|
||||
{
|
||||
$with = ['user', 'basic_audio_codec', 'basic_category', 'basic_codec', 'basic_media', 'basic_source', 'basic_standard', 'basic_team'];
|
||||
$result = Torrent::query()->with($with)->withCount(['peers', 'thank_users'])->visible()->findOrFail($id);
|
||||
$result->download_url = $this->getDownloadUrl($id, $user->toArray());
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getDownloadUrl($id, array $user): string
|
||||
{
|
||||
return sprintf(
|
||||
'%s/download.php?downhash=%s|%s',
|
||||
getSchemeAndHttpHost(), $user['id'], $this->encryptDownHash($id, $user)
|
||||
);
|
||||
}
|
||||
|
||||
private function handleGetListSort(Builder $query, array $params)
|
||||
{
|
||||
if (empty($params['sort_field']) && empty($params['sort_type'])) {
|
||||
@@ -306,6 +326,9 @@ class TorrentRepository extends BaseRepository
|
||||
|
||||
private function getEncryptDownHashKey($user)
|
||||
{
|
||||
if ($user instanceof User) {
|
||||
$user = $user->toArray();
|
||||
}
|
||||
if (!is_array($user) || empty($user['passkey']) || empty($user['id'])) {
|
||||
$user = User::query()->findOrFail(intval($user), ['id', 'passkey'])->toArray();
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ class UserRepository extends BaseRepository
|
||||
if (!empty($params['email'])) {
|
||||
$query->where('email', 'like',"%{$params['email']}%");
|
||||
}
|
||||
if (!empty($params['class'])) {
|
||||
$query->where('class', $params['class']);
|
||||
}
|
||||
list($sortField, $sortType) = $this->getSortFieldAndType($params);
|
||||
$query->orderBy($sortField, $sortType);
|
||||
return $query->paginate();
|
||||
|
||||
Reference in New Issue
Block a user