mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
oauth response array
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\ForumResource;
|
||||
use App\Models\Forum;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ForumController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$forId = $request->forid;
|
||||
$query = Forum::query()->orderBy("sort", "asc")->with("moderators");
|
||||
if ($forId) {
|
||||
$query->where("forid", $forId);
|
||||
}
|
||||
$list = $query->get();
|
||||
$resource = ForumResource::collection($list);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\OverForum $overForum
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(OverForum $overForum)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\OverForum $overForum
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(OverForum $overForum)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\OverForum $overForum
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, OverForum $overForum)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\OverForum $overForum
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(OverForum $overForum)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,6 @@ class OauthController extends Controller
|
||||
{
|
||||
$user = Auth::user();
|
||||
$resource = new UserResource($user);
|
||||
return $this->success($resource);
|
||||
return $resource->response()->getData(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\OverForumResource;
|
||||
use App\Models\OverForum;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class OverForumController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$list = OverForum::query()->orderBy("sort", "asc")->get();
|
||||
$resource = OverForumResource::collection($list);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\OverForum $overForum
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(OverForum $overForum)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\OverForum $overForum
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(OverForum $overForum)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\OverForum $overForum
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, OverForum $overForum)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\OverForum $overForum
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(OverForum $overForum)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\ForumResource;
|
||||
use App\Http\Resources\TopicResource;
|
||||
use App\Models\Forum;
|
||||
use App\Models\Topic;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TopicController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$forumId = $request->forum_id;
|
||||
$query = Topic::query()
|
||||
->orderBy("sticky", "desc")
|
||||
->with("user", "firstPost", "lastPost")
|
||||
;
|
||||
if ($forumId) {
|
||||
$query->where("forumid", $forumId);
|
||||
}
|
||||
$list = $query->get();
|
||||
$resource = TopicResource::collection($list);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\OverForum $overForum
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(OverForum $overForum)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\OverForum $overForum
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(OverForum $overForum)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\OverForum $overForum
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, OverForum $overForum)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\OverForum $overForum
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(OverForum $overForum)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ForumResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'postcount' => $this->postcount,
|
||||
'topiccount' => $this->topiccount,
|
||||
'moderators' => UserResource::collection($this->whenLoaded("moderators")),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class OverForumResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PostResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'added' => format_datetime($this->added),
|
||||
'body' => $this->body,
|
||||
'user' => new UserResource($this->whenLoaded('user')),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TopicResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'subject' => $this->subject,
|
||||
'locked' => $this->locked,
|
||||
'forumid' => $this->forumid,
|
||||
'sticky' => $this->sticky,
|
||||
'hlcolor' => $this->hlcolor,
|
||||
'views' => $this->views,
|
||||
'user' => new UserResource($this->whenLoaded('user')),
|
||||
'lastPost' => new PostResource($this->whenLoaded('lastPost')),
|
||||
'firstPost' => new PostResource($this->whenLoaded('firstPost')),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,9 @@ class UserResource extends JsonResource
|
||||
$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;
|
||||
|
||||
@@ -7,4 +7,8 @@ class Forum extends NexusModel
|
||||
{
|
||||
protected $fillable = ['sort', 'name', 'description', 'minclassread', 'minclasswrite', 'postcount', 'topiccount', 'minclasscreate', 'forid'];
|
||||
|
||||
public function moderators()
|
||||
{
|
||||
return $this->belongsToMany(User::class, "forummods", "forumid", "userid");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OverForum extends NexusModel
|
||||
{
|
||||
protected $table = "overforums";
|
||||
|
||||
|
||||
}
|
||||
@@ -16,4 +16,14 @@ class Topic extends NexusModel
|
||||
{
|
||||
return $this->belongsTo(Forum::class. 'forumid');
|
||||
}
|
||||
|
||||
public function firstPost()
|
||||
{
|
||||
return $this->belongsTo(Post::class, "firstpost");
|
||||
}
|
||||
|
||||
public function lastPost()
|
||||
{
|
||||
return $this->belongsTo(Post::class, "lastpost");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.12');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-04-03');
|
||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-04-05');
|
||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||
|
||||
@@ -5774,7 +5774,7 @@ function get_share_ratio($uploaded, $downloaded)
|
||||
$ratio = floor(($uploaded / $downloaded) * 1000) / 1000;
|
||||
} elseif ($uploaded) {
|
||||
//@todo 读语言文件
|
||||
$ratio = '无限';
|
||||
$ratio = 'Infinity';
|
||||
} else {
|
||||
$ratio = '---';
|
||||
}
|
||||
|
||||
@@ -43,6 +43,9 @@ Route::group(['middleware' => ['auth:sanctum', 'locale']], function () {
|
||||
Route::post('polls-vote', [\App\Http\Controllers\PollController::class, 'vote']);
|
||||
Route::resource('rewards', \App\Http\Controllers\RewardController::class);
|
||||
Route::get('notifications', [\App\Http\Controllers\ToolController::class, 'notifications']);
|
||||
Route::resource('over-forums', \App\Http\Controllers\OverForumController::class);
|
||||
Route::resource('forums', \App\Http\Controllers\ForumController::class);
|
||||
Route::resource('topics', \App\Http\Controllers\TopicController::class);
|
||||
});
|
||||
|
||||
Route::group(['middleware' => ['admin']], function () {
|
||||
|
||||
Reference in New Issue
Block a user