mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
API add more log
This commit is contained in:
@@ -28,8 +28,11 @@ class TorrentController extends Controller
|
|||||||
|
|
||||||
public function index(Request $request, string $section = null)
|
public function index(Request $request, string $section = null)
|
||||||
{
|
{
|
||||||
|
do_log("controller torrent index entry");
|
||||||
$result = $this->repository->getList($request, Auth::user(), $section);
|
$result = $this->repository->getList($request, Auth::user(), $section);
|
||||||
|
do_log("controller torrent index getList");
|
||||||
$resource = TorrentResource::collection($result);
|
$resource = TorrentResource::collection($result);
|
||||||
|
do_log("controller torrent index prepare resource");
|
||||||
return $this->success($resource);
|
return $this->success($resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,11 +58,13 @@ class TorrentController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
|
do_log("controller torrent show entry");
|
||||||
/**
|
/**
|
||||||
* @var User
|
* @var User
|
||||||
*/
|
*/
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
$torrent = $this->repository->getDetail($id, $user);
|
$torrent = $this->repository->getDetail($id, $user);
|
||||||
|
do_log("controller torrent show getDetail");
|
||||||
$resource = new TorrentResource($torrent);
|
$resource = new TorrentResource($torrent);
|
||||||
$additional = [];
|
$additional = [];
|
||||||
if ($this->hasExtraField('bonus_reward_values')) {
|
if ($this->hasExtraField('bonus_reward_values')) {
|
||||||
@@ -68,6 +73,7 @@ class TorrentController extends Controller
|
|||||||
$extraSettingsNames = ['torrent.claim_torrent_user_counts_up_limit'];
|
$extraSettingsNames = ['torrent.claim_torrent_user_counts_up_limit'];
|
||||||
$this->appendExtraSettings($additional, $extraSettingsNames);
|
$this->appendExtraSettings($additional, $extraSettingsNames);
|
||||||
$resource->additional($additional);
|
$resource->additional($additional);
|
||||||
|
do_log("controller torrent show prepare resource");
|
||||||
return $this->success($resource);
|
return $this->success($resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,7 +152,9 @@ class TorrentRepository extends BaseRepository
|
|||||||
if (!$apiQueryBuilder->hasSort() || !$apiQueryBuilder->hasSort('id')) {
|
if (!$apiQueryBuilder->hasSort() || !$apiQueryBuilder->hasSort('id')) {
|
||||||
$query->orderBy("id", "DESC");
|
$query->orderBy("id", "DESC");
|
||||||
}
|
}
|
||||||
|
do_log("before query torrent list");
|
||||||
$torrents = $query->paginate($this->getPerPageFromRequest($request));
|
$torrents = $query->paginate($this->getPerPageFromRequest($request));
|
||||||
|
do_log("after query torrent list");
|
||||||
return $this->appendIncludeFields($apiQueryBuilder, $user, $torrents);
|
return $this->appendIncludeFields($apiQueryBuilder, $user, $torrents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +177,9 @@ class TorrentRepository extends BaseRepository
|
|||||||
->allowIncludeCounts($allowIncludeCounts)
|
->allowIncludeCounts($allowIncludeCounts)
|
||||||
->allowIncludeFields($allowIncludeFields)
|
->allowIncludeFields($allowIncludeFields)
|
||||||
;
|
;
|
||||||
|
do_log("before query torrent detail");
|
||||||
$torrent = $apiQueryBuilder->build()->findOrFail($id);
|
$torrent = $apiQueryBuilder->build()->findOrFail($id);
|
||||||
|
do_log("before query torrent detail");
|
||||||
$torrentList = $this->appendIncludeFields($apiQueryBuilder, $user, [$torrent]);
|
$torrentList = $this->appendIncludeFields($apiQueryBuilder, $user, [$torrent]);
|
||||||
return $torrentList[0];
|
return $torrentList[0];
|
||||||
}
|
}
|
||||||
@@ -199,6 +203,7 @@ class TorrentRepository extends BaseRepository
|
|||||||
if ($hasFieldHasRewarded = $apiQueryBuilder->hasIncludeField('has_rewarded')) {
|
if ($hasFieldHasRewarded = $apiQueryBuilder->hasIncludeField('has_rewarded')) {
|
||||||
$rewardData = $user->reward_torrent_logs()->whereIn('torrentid', $torrentIdArr)->get()->keyBy('torrentid');
|
$rewardData = $user->reward_torrent_logs()->whereIn('torrentid', $torrentIdArr)->get()->keyBy('torrentid');
|
||||||
}
|
}
|
||||||
|
do_log("after prepare has data");
|
||||||
|
|
||||||
foreach ($torrentList as $torrent) {
|
foreach ($torrentList as $torrent) {
|
||||||
$id = $torrent->id;
|
$id = $torrent->id;
|
||||||
@@ -216,7 +221,9 @@ class TorrentRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($apiQueryBuilder->hasIncludeField('description') && $apiQueryBuilder->hasInclude('extra')) {
|
if ($apiQueryBuilder->hasIncludeField('description') && $apiQueryBuilder->hasInclude('extra')) {
|
||||||
|
do_log("before format_description of torrent: {$torrent->id}");
|
||||||
$descriptionArr = format_description($torrent->extra->descr ?? '');
|
$descriptionArr = format_description($torrent->extra->descr ?? '');
|
||||||
|
do_log("after format_description of torrent: {$torrent->id}");
|
||||||
$torrent->description = $descriptionArr;
|
$torrent->description = $descriptionArr;
|
||||||
$torrent->images = get_image_from_description($descriptionArr);
|
$torrent->images = get_image_from_description($descriptionArr);
|
||||||
}
|
}
|
||||||
@@ -224,6 +231,7 @@ class TorrentRepository extends BaseRepository
|
|||||||
$torrent->download_url = $this->getDownloadUrl($id, $user);
|
$torrent->download_url = $this->getDownloadUrl($id, $user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
do_log("after fill has data");
|
||||||
return $torrentList;
|
return $torrentList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -542,6 +542,7 @@ function nexus_json_encode($data)
|
|||||||
|
|
||||||
function api(...$args)
|
function api(...$args)
|
||||||
{
|
{
|
||||||
|
do_log("api begin");
|
||||||
if (func_num_args() < 3) {
|
if (func_num_args() < 3) {
|
||||||
//参数少于3个时,默认为错误状态。
|
//参数少于3个时,默认为错误状态。
|
||||||
$ret = -1;
|
$ret = -1;
|
||||||
@@ -555,6 +556,7 @@ function api(...$args)
|
|||||||
if ($data instanceof \Illuminate\Http\Resources\Json\JsonResource) {
|
if ($data instanceof \Illuminate\Http\Resources\Json\JsonResource) {
|
||||||
$data = $data->response()->getData(true);
|
$data = $data->response()->getData(true);
|
||||||
}
|
}
|
||||||
|
do_log("api after prepare data");
|
||||||
// dd($data);
|
// dd($data);
|
||||||
$time = (float)number_format(microtime(true) - nexus()->getStartTimestamp(), 3);
|
$time = (float)number_format(microtime(true) - nexus()->getStartTimestamp(), 3);
|
||||||
$count = null;
|
$count = null;
|
||||||
@@ -583,7 +585,7 @@ function api(...$args)
|
|||||||
$results['recordsTotal'] = $count;
|
$results['recordsTotal'] = $count;
|
||||||
$results['recordsFiltered'] = $count;
|
$results['recordsFiltered'] = $count;
|
||||||
}
|
}
|
||||||
|
do_log("api end");
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -599,6 +601,7 @@ function success(...$args)
|
|||||||
$msg = $args[0];
|
$msg = $args[0];
|
||||||
$data = $args[1];
|
$data = $args[1];
|
||||||
}
|
}
|
||||||
|
do_log("success before api");
|
||||||
return api($ret, $msg, $data);
|
return api($ret, $msg, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user