mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
API: torrents upload/list
This commit is contained in:
@@ -4,25 +4,34 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Exceptions\InsufficientPermissionException;
|
||||
use App\Models\Setting;
|
||||
use App\Utils\ApiQueryBuilder;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Http\Resources\MissingValue;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
|
||||
/**
|
||||
* @OA\Info(
|
||||
* title="NexusPHP API",
|
||||
* version="1.0"
|
||||
* )
|
||||
*/
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
public function success($data, $msg = null)
|
||||
protected ?array $extraFields = null;
|
||||
protected ?array $extraSettingNames = null;
|
||||
|
||||
/**
|
||||
* 返回成功信息,这里是旧方法,大部分情况下 $data 已经是 JsonResource
|
||||
* 但很多地方有使用,历史原因保留不动,尽量使用 successJsonResource
|
||||
*
|
||||
* @param $data
|
||||
* @param $msg
|
||||
* @return array
|
||||
*/
|
||||
public function success($data, $msg = null): array
|
||||
{
|
||||
if (is_null($msg)) {
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||
@@ -32,6 +41,34 @@ class Controller extends BaseController
|
||||
return success($msg, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功信息,对于不是 JsonResource 的数据,进行包装。返回的数据在 data.data 中
|
||||
*
|
||||
* @param $data
|
||||
* @param $msg
|
||||
* @return array
|
||||
*/
|
||||
public function successJsonResource($data, $msg = null): array
|
||||
{
|
||||
if (is_null($msg)) {
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||
$caller = $backtrace[1];
|
||||
$msg = $this->getReturnMsg($caller);
|
||||
}
|
||||
if ($data instanceof JsonResource) {
|
||||
return $this->success($data, $msg);
|
||||
}
|
||||
$resource = new JsonResource($data);
|
||||
return $this->success($resource, $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回失败信息,目前对于失败信息不需要包装
|
||||
*
|
||||
* @param $data
|
||||
* @param $msg
|
||||
* @return array
|
||||
*/
|
||||
public function fail($data, $msg = null)
|
||||
{
|
||||
if (is_null($msg)) {
|
||||
@@ -78,6 +115,31 @@ class Controller extends BaseController
|
||||
return [$perPage, ['*'], 'page', $page];
|
||||
}
|
||||
|
||||
protected function hasExtraField($field): bool
|
||||
{
|
||||
if ($this->extraFields === null) {
|
||||
$extraFieldsStr = request()->input("extra_fields", '');
|
||||
$this->extraFields = explode(',', $extraFieldsStr);
|
||||
}
|
||||
do_log(sprintf("field: %s, extraFields: %s", $field, json_encode($this->extraFields)));
|
||||
return in_array($field, $this->extraFields);
|
||||
}
|
||||
|
||||
protected function appendExtraSettings(array &$additional, array $names): void
|
||||
{
|
||||
if ($this->extraSettingNames === null) {
|
||||
$extraSettingStr = request()->input("extra_settings", '');
|
||||
$this->extraSettingNames = explode(',', $extraSettingStr);
|
||||
}
|
||||
$results = [];
|
||||
foreach ($names as $name) {
|
||||
if (in_array($name, $this->extraSettingNames)) {
|
||||
$results[$name] = get_setting($name);
|
||||
}
|
||||
}
|
||||
if (!empty($results)) {
|
||||
$additional['extra_settings'] = $results;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,14 +27,12 @@ class TokenController extends Controller
|
||||
$user = Auth::user();
|
||||
$count = $user->tokens()->count();
|
||||
if ($count >= 5) {
|
||||
throw new NexusException("Token limit exceeded");
|
||||
throw new NexusException(nexus_trans("token.maximum_allow_number_reached"));
|
||||
}
|
||||
$newAccessToken = $user->createToken($request->name, $request->permissions);
|
||||
PersonalAccessTokenPlain::query()->create([
|
||||
'access_token_id' => $newAccessToken->accessToken->getKey(),
|
||||
'plain_text_token' => $newAccessToken->plainTextToken,
|
||||
]);
|
||||
return $this->success(true);
|
||||
$tokenText = $newAccessToken->plainTextToken;
|
||||
$msg = nexus_trans("token.create_success_tip", ['token' => $tokenText]);
|
||||
return $this->successJsonResource(['token' => $tokenText], $msg);
|
||||
} catch (\Exception $exception) {
|
||||
return $this->fail(false, $exception->getMessage());
|
||||
}
|
||||
@@ -47,11 +45,7 @@ class TokenController extends Controller
|
||||
'id' => 'required|integer',
|
||||
]);
|
||||
$user = Auth::user();
|
||||
$token = $user->tokens()->where("id", $request->id)->first();
|
||||
if ($token) {
|
||||
PersonalAccessTokenPlain::query()->where("access_token_id", $token->id)->delete();
|
||||
$token->delete();
|
||||
}
|
||||
$user->tokens()->where("id", $request->id)->delete();
|
||||
return $this->success(true);
|
||||
} catch (\Exception $exception) {
|
||||
return $this->fail(false, $exception->getMessage());
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Models\PluginStore;
|
||||
use App\Repositories\ToolRepository;
|
||||
use App\Repositories\UploadRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
@@ -31,9 +32,9 @@ class ToolController extends Controller
|
||||
|
||||
public function test(Request $request)
|
||||
{
|
||||
$rep = new UploadRepository();
|
||||
$result = $rep->listSections();
|
||||
return $result;
|
||||
$result = ['id' => 1];
|
||||
$resource = new JsonResource($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,10 @@ use App\Models\TorrentDenyReason;
|
||||
use App\Models\TorrentOperationLog;
|
||||
use App\Models\User;
|
||||
use App\Repositories\TorrentRepository;
|
||||
use App\Repositories\UploadRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class TorrentController extends Controller
|
||||
@@ -23,17 +26,10 @@ class TorrentController extends Controller
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
public function index(Request $request, string $section = null)
|
||||
{
|
||||
$params = $request->all();
|
||||
$params['visible'] = Torrent::VISIBLE_YES;
|
||||
$params['category_mode'] = Setting::get('main.browsecat');
|
||||
$result = $this->repository->getList($params, Auth::user());
|
||||
$result = $this->repository->getList($request, Auth::user(), $section);
|
||||
$resource = TorrentResource::collection($result);
|
||||
// $resource->additional([
|
||||
// 'page_title' => nexus_trans('torrent.index.page_title'),
|
||||
// ]);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
@@ -41,18 +37,21 @@ class TorrentController extends Controller
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return array
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
$uploadRep = new UploadRepository();
|
||||
$newTorrent = $uploadRep->upload($request);
|
||||
$resource = new JsonResource(["id" => $newTorrent->id]);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return array
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
@@ -60,17 +59,15 @@ class TorrentController extends Controller
|
||||
* @var User
|
||||
*/
|
||||
$user = Auth::user();
|
||||
$result = $this->repository->getDetail($id, $user);
|
||||
$isBookmarked = $user->bookmarks()->where('torrentid', $id)->exists();
|
||||
|
||||
$resource = new TorrentResource($result);
|
||||
$resource->additional([
|
||||
// 'page_title' => nexus_trans('torrent.show.page_title'),
|
||||
// 'field_labels' => Torrent::getFieldLabels(),
|
||||
'is_bookmarked' => (int)$isBookmarked,
|
||||
'bonus_reward_values' => Torrent::BONUS_REWARD_VALUES,
|
||||
]);
|
||||
|
||||
$torrent = $this->repository->getDetail($id, $user);
|
||||
$resource = new TorrentResource($torrent);
|
||||
$additional = [];
|
||||
if ($this->hasExtraField('bonus_reward_values')) {
|
||||
$additional['bonus_reward_values'] = Torrent::BONUS_REWARD_VALUES;
|
||||
}
|
||||
$extraSettingsNames = ['torrent.claim_torrent_user_counts_up_limit'];
|
||||
$this->appendExtraSettings($additional, $extraSettingsNames);
|
||||
$resource->additional($additional);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\SearchBoxResource;
|
||||
use App\Http\Resources\TorrentResource;
|
||||
use App\Repositories\SearchBoxRepository;
|
||||
use App\Repositories\UploadRepository;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -26,10 +27,4 @@ class UploadController extends Controller
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
public function upload(Request $request)
|
||||
{
|
||||
$user = $request->user();
|
||||
return $this->success("OK");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ use App\Repositories\UserRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use League\OAuth2\Server\Grant\AuthCodeGrant;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
@@ -64,10 +65,15 @@ class UserController extends Controller
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function show($id)
|
||||
public function show($id = null)
|
||||
{
|
||||
$result = $this->repository->getDetail($id);
|
||||
return $this->success($result);
|
||||
$currentUser = Auth::user();
|
||||
if ($id === null) {
|
||||
$id = $currentUser->id;
|
||||
}
|
||||
$result = $this->repository->getDetail($id, $currentUser);
|
||||
$resource = new UserResource($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
abstract class BaseResource extends JsonResource
|
||||
{
|
||||
protected abstract function getResourceName(): string;
|
||||
|
||||
protected function whenIncludeField($field): bool
|
||||
{
|
||||
return $this->whenInclude($field, "include_fields");
|
||||
}
|
||||
|
||||
private function whenInclude($field, $prefix): bool
|
||||
{
|
||||
$fields = request()->input("$prefix." . $this->getResourceName());
|
||||
if (!$fields) {
|
||||
return false;
|
||||
}
|
||||
$fieldsArr = explode(',', $fields);
|
||||
return in_array($field, $fieldsArr);
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,15 @@ class MedalResource extends JsonResource
|
||||
'image_large' => $this->image_large,
|
||||
'image_small' => $this->image_small,
|
||||
'price' => $this->price,
|
||||
'price_human' => number_format($this->price),
|
||||
'duration' => $this->duration,
|
||||
'description' => $this->description,
|
||||
'expire_at' => $this->whenPivotLoaded('user_medals', function () {return $this->pivot->expire_at;}),
|
||||
'user_medal_id' => $this->whenPivotLoaded('user_medals', function () {return $this->pivot->id;}),
|
||||
'wearing_status' => $this->whenPivotLoaded('user_medals', function () {return $this->pivot->status;}),
|
||||
'wearing_status_text' => $this->whenPivotLoaded('user_medals', function () {
|
||||
return nexus_trans("medal.wearing_status_text." . $this->pivot->status);
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,23 +19,20 @@ class SearchBoxResource extends JsonResource
|
||||
$searchBox = $this->resource;
|
||||
$out = [
|
||||
'id' => $this->id,
|
||||
'name' => $this->displaySectionName,
|
||||
'name' => $this->name,
|
||||
'display_name' => $this->displaySectionName,
|
||||
'categories' => CategoryResource::collection($this->whenLoaded('categories')),
|
||||
'tags' => TagResource::collection($this->whenLoaded('tags')),
|
||||
];
|
||||
if ($searchBox->showsubcat) {
|
||||
$subCategories = [];
|
||||
$lang = get_langfolder_cookie();
|
||||
$fields = array_keys(SearchBox::$taxonomies);
|
||||
if (!empty($searchBox->extra['taxonomy_labels'])) {
|
||||
$fields = array_column($searchBox->extra['taxonomy_labels'], 'torrent_field');
|
||||
}
|
||||
foreach ($fields as $field) {
|
||||
$relationName = "taxonomy_$field";
|
||||
if ($searchBox->relationLoaded($relationName)) {
|
||||
$subCategories[] = [
|
||||
'field' => $field,
|
||||
'label' => $item['display_text'][$lang] ?? (nexus_trans("searchbox.sub_category_{$field}_label") ?: ucfirst($field)),
|
||||
'label' => $searchBox->getTaxonomyLabel($field),
|
||||
'data' => MediaResource::collection($searchBox->{$relationName}),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TorrentExtraResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'descr' => $this->descr,
|
||||
'media_info' => $this->media_info,
|
||||
'media_info_summary' => $this->media_info_summary,
|
||||
'nfo' => $this->nfo,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,21 @@
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Attachment;
|
||||
use App\Models\SearchBox;
|
||||
use App\Models\Torrent;
|
||||
use App\Repositories\TorrentRepository;
|
||||
use Carbon\CarbonInterface;
|
||||
use Elasticsearch\Endpoints\Search;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Nexus\Nexus;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TorrentResource extends JsonResource
|
||||
class TorrentResource extends BaseResource
|
||||
{
|
||||
protected $imageTypes = ['image', 'attachment'];
|
||||
const NAME = 'torrent';
|
||||
|
||||
protected static TorrentRepository $torrentRep;
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
@@ -24,72 +31,82 @@ class TorrentResource extends JsonResource
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'filename' => $this->filename,
|
||||
'hash' => preg_replace_callback('/./s', [$this, "hex_esc"], $this->info_hash),
|
||||
'cover' => $this->cover,
|
||||
'small_descr' => $this->small_descr,
|
||||
'comments' => $this->comments,
|
||||
'category' => $this->category,
|
||||
'category_info' => new CategoryResource($this->whenLoaded('basic_category')),
|
||||
'size' => $this->size,
|
||||
'size_human' => mksize($this->size),
|
||||
'added' => $this->added->toDateTimeString(),
|
||||
'added_human' => $this->added->format('Y-m-d H:i'),
|
||||
'ttl' => $this->added->diffForHumans(['syntax' => CarbonInterface::DIFF_ABSOLUTE]),
|
||||
'leechers' => $this->leechers,
|
||||
'seeders' => $this->seeders,
|
||||
'times_completed' => $this->times_completed,
|
||||
'numfiles' => $this->numfiles,
|
||||
'added' => format_datetime($this->added),
|
||||
'added_human' => gettime($this->added),
|
||||
'numfiles' => $this->numfiles ?: 0,
|
||||
'leechers' => $this->leechers ?: 0,
|
||||
'seeders' => $this->seeders ?: 0,
|
||||
'times_completed' => $this->times_completed ?: 0,
|
||||
'views' => $this->views ?: 0,
|
||||
'hits' => $this->hits ?: 0,
|
||||
'comments' => $this->comments ?: 0,
|
||||
'pos_state' => $this->pos_state,
|
||||
'pos_state_until' => format_datetime($this->pos_state_until),
|
||||
'pos_state_until_human' => gettime($this->pos_state_until),
|
||||
'sp_state' => $this->sp_state,
|
||||
'sp_state_real' => $this->sp_state_real,
|
||||
'promotion_info' => $this->promotionInfo,
|
||||
'hr' => $this->hr,
|
||||
'hr' => $this->hr ?: 0,
|
||||
'pick_type' => $this->picktype,
|
||||
'pick_time' => $this->picktime,
|
||||
'pick_info' => $this->pickInfo,
|
||||
'download_url' => $this->download_url,
|
||||
'user' => new UserResource($this->whenLoaded('user')),
|
||||
'anonymous' => $this->anonymous,
|
||||
'basic_category' => new CategoryResource($this->whenLoaded('basic_category')),
|
||||
'last_action' => format_datetime($this->last_action),
|
||||
'last_action_human' => gettime($this->last_action),
|
||||
'thank_users_count' => $this->whenCounted('thank_users'),
|
||||
'reward_logs_count' => $this->whenCounted('reward_logs'),
|
||||
'claims_count' => $this->whenCounted('claims'),
|
||||
'has_bookmarked' => $this->whenHas('has_bookmarked'),
|
||||
'has_claimed' => $this->whenHas('has_claimed'),
|
||||
'has_thanked' => $this->whenHas('has_thanked'),
|
||||
'has_rewarded' => $this->whenHas('has_rewarded'),
|
||||
'description' => $this->whenHas('description'),
|
||||
'images' => $this->whenHas('images'),
|
||||
'download_url' => $this->whenHas('download_url'),
|
||||
'user' => new UserResource($this->whenLoaded('user')),
|
||||
'extra' => new TorrentExtraResource($this->whenLoaded('extra')),
|
||||
'tags' => TagResource::collection($this->whenLoaded('tags')),
|
||||
'thanks' => ThankResource::collection($this->whenLoaded('thanks')),
|
||||
'reward_logs' => RewardResource::collection($this->whenLoaded('reward_logs')),
|
||||
];
|
||||
if ($this->cover) {
|
||||
$cover = $this->cover;
|
||||
} else {
|
||||
$descriptionArr = format_description($this->descr);
|
||||
$cover = get_image_from_description($descriptionArr, true);
|
||||
}
|
||||
$out['cover'] = resize_image($cover, 100, 100);
|
||||
if ($request->routeIs('torrents.show')) {
|
||||
if (!isset($descriptionArr)) {
|
||||
$descriptionArr = format_description($this->descr);
|
||||
$subCategories = [];
|
||||
foreach (SearchBox::$taxonomies as $field => $info) {
|
||||
$relation = "basic_$field";
|
||||
if ($this->resource->{$field} > 0 && $this->resource->relationLoaded($relation)) {
|
||||
$subCategories[$field] = [
|
||||
'label' => $this->resource->getSubCategoryLabel($field),
|
||||
'value' => $this->resource->{$relation}->name ?? '',
|
||||
];
|
||||
}
|
||||
$baseInfo = [
|
||||
['label' => nexus_trans('torrent.show.size'), 'value' => mksize($this->size)],
|
||||
];
|
||||
foreach (Torrent::getBasicInfo() as $relation => $text) {
|
||||
if ($info = $this->whenLoaded($relation)) {
|
||||
$baseInfo[] = ['label' => $text, 'value' => $info->name];
|
||||
}
|
||||
}
|
||||
$out['base_info'] = $baseInfo;
|
||||
|
||||
$out['description'] = $descriptionArr;
|
||||
|
||||
$out['images'] = get_image_from_description($descriptionArr);
|
||||
|
||||
$out['thank_users_count'] = $this->thank_users_count;
|
||||
$out['peers_count'] = $this->peers_count;
|
||||
$out['reward_logs_count'] = $this->reward_logs_count;
|
||||
}
|
||||
if (nexus()->isPlatformAdmin()) {
|
||||
$out['details_url'] = sprintf('%s/details.php?id=%s', getSchemeAndHttpHost(), $this->id);
|
||||
}
|
||||
|
||||
// $out['upload_peers_count'] = $this->upload_peers_count;
|
||||
// $out['download_peers_count'] = $this->download_peers_count;
|
||||
// $out['finish_peers_count'] = $this->finish_peers_count;
|
||||
|
||||
$out['sub_categories'] = empty($subCategories) ? null : $subCategories;
|
||||
return $out;
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function getResourceName(): string
|
||||
{
|
||||
return self::NAME;
|
||||
}
|
||||
|
||||
private function getTorrentRep(): TorrentRepository
|
||||
{
|
||||
if (!isset(self::$torrentRep)) {
|
||||
self::$torrentRep = new TorrentRepository();
|
||||
}
|
||||
return self::$torrentRep;
|
||||
}
|
||||
|
||||
protected function hex_esc($matches) {
|
||||
return sprintf("%02x", ord($matches[0]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
const NAME = 'user';
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
@@ -21,7 +22,9 @@ class UserResource extends JsonResource
|
||||
'status' => $this->status,
|
||||
'enabled' => $this->enabled,
|
||||
'added' => format_datetime($this->added),
|
||||
'added_human' => gettime($this->added),
|
||||
'last_access' => format_datetime($this->last_access),
|
||||
'last_access_human' => gettime($this->last_access),
|
||||
'class' => $this->class,
|
||||
'class_text' => $this->class_text,
|
||||
'avatar' => $this->avatar,
|
||||
@@ -31,8 +34,10 @@ class UserResource extends JsonResource
|
||||
'uploaded_text' => mksize($this->uploaded),
|
||||
'downloaded' => $this->downloaded,
|
||||
'downloaded_text' => mksize($this->downloaded),
|
||||
'bonus' => number_format($this->seedbonus, 1),
|
||||
'seed_points' => number_format($this->seed_points, 1),
|
||||
'bonus' => floatval($this->seedbonus),
|
||||
'bonus_human' => number_format($this->seedbonus, 1),
|
||||
'seed_points' => floatval($this->seed_points),
|
||||
'seed_points_human' => number_format($this->seed_points, 1),
|
||||
'seedtime' => $this->seedtime,
|
||||
'seedtime_text' => mkprettytime($this->seedtime),
|
||||
'leechtime' => $this->leechtime,
|
||||
@@ -40,27 +45,27 @@ class UserResource extends JsonResource
|
||||
'inviter' => new UserResource($this->whenLoaded('inviter')),
|
||||
'valid_medals' => MedalResource::collection($this->whenLoaded('valid_medals')),
|
||||
];
|
||||
if ($request->routeIs('user.me')) {
|
||||
$out['downloaded_human'] = mksize($this->downloaded);
|
||||
$out['uploaded_human'] = mksize($this->uploaded);
|
||||
$out['seed_time'] = mkprettytime($this->seedtime);
|
||||
$out['leech_time'] = mkprettytime($this->leechtime);
|
||||
$out['share_ratio'] = get_share_ratio($this->uploaded, $this->downloaded);
|
||||
$out['comments_count'] = $this->comments_count;
|
||||
$out['posts_count'] = $this->posts_count;
|
||||
$out['torrents_count'] = $this->torrents_count;
|
||||
$out['seeding_torrents_count'] = $this->seeding_torrents_count;
|
||||
$out['leeching_torrents_count'] = $this->leeching_torrents_count;
|
||||
$out['completed_torrents_count'] = $this->completed_torrents_count;
|
||||
$out['incomplete_torrents_count'] = $this->incomplete_torrents_count;
|
||||
}
|
||||
if ($request->routeIs("oauth.user_info")) {
|
||||
$out['name'] = $this->username;
|
||||
}
|
||||
|
||||
if (nexus()->isPlatformAdmin() && $request->routeIs('users.show')) {
|
||||
$out['two_step_secret'] = $this->two_step_secret;
|
||||
}
|
||||
// if ($request->routeIs('user.me')) {
|
||||
// $out['downloaded_human'] = mksize($this->downloaded);
|
||||
// $out['uploaded_human'] = mksize($this->uploaded);
|
||||
// $out['seed_time'] = mkprettytime($this->seedtime);
|
||||
// $out['leech_time'] = mkprettytime($this->leechtime);
|
||||
// $out['share_ratio'] = get_share_ratio($this->uploaded, $this->downloaded);
|
||||
// $out['comments_count'] = $this->comments_count;
|
||||
// $out['posts_count'] = $this->posts_count;
|
||||
// $out['torrents_count'] = $this->torrents_count;
|
||||
// $out['seeding_torrents_count'] = $this->seeding_torrents_count;
|
||||
// $out['leeching_torrents_count'] = $this->leeching_torrents_count;
|
||||
// $out['completed_torrents_count'] = $this->completed_torrents_count;
|
||||
// $out['incomplete_torrents_count'] = $this->incomplete_torrents_count;
|
||||
// }
|
||||
// if ($request->routeIs("oauth.user_info")) {
|
||||
// $out['name'] = $this->username;
|
||||
// }
|
||||
//
|
||||
// if (nexus()->isPlatformAdmin() && $request->routeIs('users.show')) {
|
||||
// $out['two_step_secret'] = $this->two_step_secret;
|
||||
// }
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user