mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
api add page_title
This commit is contained in:
@@ -61,7 +61,7 @@ class Test extends Command
|
||||
// $r = $disk->put('/', base_path('composer.json'));
|
||||
// $r = DB::table('users')->where('id', 1)->update(['modcomment' => DB::raw("concat_ws(',', 'ddddd', modcomment)")]);
|
||||
|
||||
$r = exec('uptime');
|
||||
$r = format_description('[em4] [em27]');
|
||||
dd($r);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ class CommentController extends Controller
|
||||
$with = ['create_user', 'update_user'];
|
||||
$comments = Comment::query()->with($with)->where('torrent', $torrentId)->paginate();
|
||||
$resource = CommentResource::collection($comments);
|
||||
$resource->additional([
|
||||
'page_title' => nexus_trans('comment.index.page_title'),
|
||||
]);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class PeerController extends Controller
|
||||
'seeder_list' => [],
|
||||
'leecher_list' => [],
|
||||
'card_titles' => Peer::$cardTitles,
|
||||
'page_title' => nexus_trans('peer.index.page_title'),
|
||||
];
|
||||
$result = $this->repository->listPeers($request->torrent_id);
|
||||
if ($result['seeder_list']->isNotEmpty()) {
|
||||
|
||||
@@ -28,7 +28,10 @@ class SnatchController extends Controller
|
||||
]);
|
||||
$snatches = $this->repository->listSnatches($request->torrent_id);
|
||||
$resource = SnatchResource::collection($snatches);
|
||||
$resource->additional(['card_titles' => Snatch::$cardTitles]);
|
||||
$resource->additional([
|
||||
'card_titles' => Snatch::$cardTitles,
|
||||
'page_title' => nexus_trans('snatch.index.page_title'),
|
||||
]);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ class TorrentController extends Controller
|
||||
$params['visible'] = Torrent::VISIBLE_YES;
|
||||
$result = $this->repository->getList($params);
|
||||
$resource = TorrentResource::collection($result);
|
||||
$resource->additional([
|
||||
'page_title' => nexus_trans('torrent.index.page_title'),
|
||||
]);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
@@ -45,13 +48,15 @@ class TorrentController extends Controller
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$with = ['user', 'basic_audiocodec', 'basic_category', 'basic_codec', 'basic_media', 'basic_source', 'basic_standard', 'basic_team'];
|
||||
$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);
|
||||
|
||||
// dd($result);
|
||||
|
||||
$resource = new TorrentResource($result);
|
||||
$resource->additional([
|
||||
'page_title' => nexus_trans('torrent.show.page_title'),
|
||||
'field_labels' => Torrent::getFieldLabels(),
|
||||
]);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Attachment;
|
||||
use App\Models\Torrent;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
@@ -38,28 +39,12 @@ class TorrentResource extends JsonResource
|
||||
|
||||
if ($request->routeIs('torrents.show')) {
|
||||
$baseInfo = [
|
||||
['label' => '大小', 'value' => mksize($this->size)],
|
||||
['label' => nexus_trans('torrent.show.size'), 'value' => mksize($this->size)],
|
||||
];
|
||||
if ($info = $this->whenLoaded('basic_category')) {
|
||||
$baseInfo[] = ['label' => '类型', 'value' => $info->name];
|
||||
}
|
||||
if ($info = $this->whenLoaded('basic_audiocodec')) {
|
||||
$baseInfo[] = ['label' => '音频编码', 'value' => $info->name];
|
||||
}
|
||||
if ($info = $this->whenLoaded('basic_codec')) {
|
||||
$baseInfo[] = ['label' => '视频编码', 'value' => $info->name];
|
||||
}
|
||||
if ($info = $this->whenLoaded('basic_media')) {
|
||||
$baseInfo[] = ['label' => '媒介', 'value' => $info->name];
|
||||
}
|
||||
if ($info = $this->whenLoaded('basic_source')) {
|
||||
$baseInfo[] = ['label' => '来源', 'value' => $info->name];
|
||||
}
|
||||
if ($info = $this->whenLoaded('basic_standard')) {
|
||||
$baseInfo[] = ['label' => '分辨率', 'value' => $info->name];
|
||||
}
|
||||
if ($info = $this->whenLoaded('basic_team')) {
|
||||
$baseInfo[] = ['label' => '制作组', 'value' => $info->name];
|
||||
foreach (Torrent::getBasicInfo() as $relation => $text) {
|
||||
if ($info = $this->whenLoaded($relation)) {
|
||||
$baseInfo[] = ['label' => $text, 'value' => $info->name];
|
||||
}
|
||||
}
|
||||
$out['base_info'] = $baseInfo;
|
||||
$descriptionArr = format_description($this->descr);
|
||||
|
||||
+25
-1
@@ -22,6 +22,30 @@ class Torrent extends NexusModel
|
||||
'added' => 'datetime'
|
||||
];
|
||||
|
||||
public static $basicRelations = [
|
||||
'basic_category', 'basic_audio_codec', 'basic_codec', 'basic_media',
|
||||
'basic_source', 'basic_standard', 'basic_team',
|
||||
];
|
||||
|
||||
public static function getBasicInfo(): array
|
||||
{
|
||||
$result = [];
|
||||
foreach (self::$basicRelations as $relation) {
|
||||
$result[$relation] = nexus_trans("torrent.show.$relation");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getFieldLabels(): array
|
||||
{
|
||||
$fields = ['comments', 'times_completed', 'peers_count', 'thank_users_count', 'numfiles'];
|
||||
$result = [];
|
||||
foreach($fields as $field) {
|
||||
$result[$field] = nexus_trans("torrent.show.{$field}_label");
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function checkIsNormal(array $fields = ['visible', 'banned'])
|
||||
{
|
||||
if (in_array('visible', $fields) && $this->getAttribute('visible') != self::VISIBLE_YES) {
|
||||
@@ -124,7 +148,7 @@ class Torrent extends NexusModel
|
||||
return $this->belongsTo(Team::class, 'team');
|
||||
}
|
||||
|
||||
public function basic_audiocodec()
|
||||
public function basic_audio_codec()
|
||||
{
|
||||
return $this->belongsTo(AudioCodec::class, 'audiocodec');
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\Peer;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Torrent;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
@@ -116,7 +117,7 @@ class DashboardRepository extends BaseRepository
|
||||
$result[$name] = [
|
||||
'name' => $name,
|
||||
'text' => nexus_trans("dashboard.user.$name"),
|
||||
'value' => User::query()->count(),
|
||||
'value' => sprintf('%s / %s', User::query()->count(), Setting::get('main.maxusers')),
|
||||
];
|
||||
$name = 'unconfirmed';
|
||||
$result[$name] = [
|
||||
@@ -188,7 +189,7 @@ class DashboardRepository extends BaseRepository
|
||||
'text' => nexus_trans("dashboard.torrent.$name"),
|
||||
'value' => Torrent::query()->count(),
|
||||
];
|
||||
$name = 'deaded';
|
||||
$name = 'dead';
|
||||
$result[$name] = [
|
||||
'name' => $name,
|
||||
'text' => nexus_trans("dashboard.torrent.$name"),
|
||||
@@ -220,7 +221,7 @@ class DashboardRepository extends BaseRepository
|
||||
$result[$name] = [
|
||||
'name' => $name,
|
||||
'text' => nexus_trans("dashboard.torrent.$name"),
|
||||
'value' => $leechers == 0 ? 0 : number_format(($seeders / $leechers) * 100, 2),
|
||||
'value' => $leechers == 0 ? 0 : number_format(($seeders / $leechers) * 100) . '%',
|
||||
];
|
||||
$name = 'active_web_users';
|
||||
$result[$name] = [
|
||||
|
||||
Reference in New Issue
Block a user