mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
torrent api + swip constants
This commit is contained in:
@@ -60,6 +60,9 @@ class Test extends Command
|
||||
// $disk = Storage::disk('google_dirve');
|
||||
// $r = $disk->put('/', base_path('composer.json'));
|
||||
// $r = DB::table('users')->where('id', 1)->update(['modcomment' => DB::raw("concat_ws(',', 'ddddd', modcomment)")]);
|
||||
$user = User::query()->find(1);
|
||||
$r = $user->peer_torrents;
|
||||
dd($r);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
70
app/Http/Controllers/CommentController.php
Normal file
70
app/Http/Controllers/CommentController.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\CommentResource;
|
||||
use App\Models\Comment;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CommentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$torrentId = $request->torrent_id;
|
||||
$with = ['create_user', 'update_user'];
|
||||
$comments = Comment::query()->with($with)->where('torrent', $torrentId)->paginate();
|
||||
$resource = CommentResource::collection($comments);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
70
app/Http/Controllers/FileController.php
Normal file
70
app/Http/Controllers/FileController.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\FileResource;
|
||||
use App\Models\File;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FileController extends Controller
|
||||
{
|
||||
/**
|
||||
* torrent file list
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$torrentId = $request->torrent_id;
|
||||
$files = File::query()->where('torrent', $torrentId)->get();
|
||||
$resource = FileResource::collection($files);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
74
app/Http/Controllers/MessageController.php
Normal file
74
app/Http/Controllers/MessageController.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\MessageResource;
|
||||
use App\Models\Message;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class MessageController extends Controller
|
||||
{
|
||||
/**
|
||||
* message list
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$messages = Message::query()->where('receiver', $user->id)->with(['send_user'])->paginate();
|
||||
$resource = MessageResource::collection($messages);
|
||||
return $this->success($resource);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$message = Message::query()->with(['send_user'])->findOrFail($id);
|
||||
$resource = new MessageResource($message);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
85
app/Http/Controllers/PeerController.php
Normal file
85
app/Http/Controllers/PeerController.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\PeerResource;
|
||||
use App\Models\Peer;
|
||||
use App\Models\Torrent;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PeerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$torrentId = $request->torrent_id;
|
||||
$peers = Peer::query()->where('torrent', $torrentId)->with(['user', 'relative_torrent'])->get()->groupBy('seeder');
|
||||
$seederResource = [];
|
||||
$leecherResource = [];
|
||||
if ($peers->has(Peer::SEEDER_YES)) {
|
||||
$seederResource = PeerResource::collection($peers->get(Peer::SEEDER_YES));
|
||||
}
|
||||
if ($peers->has(Peer::SEEDER_NO)) {
|
||||
$leecherResource = PeerResource::collection($peers->get(Peer::SEEDER_NO));
|
||||
}
|
||||
|
||||
$response = [
|
||||
'seeder_list' => $seederResource,
|
||||
'leecher_list' => $leecherResource,
|
||||
'card_titles' => Peer::$cardTitles,
|
||||
];
|
||||
|
||||
return $this->success($response);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
71
app/Http/Controllers/SnatchController.php
Normal file
71
app/Http/Controllers/SnatchController.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\PeerResource;
|
||||
use App\Http\Resources\SnatchResource;
|
||||
use App\Models\Peer;
|
||||
use App\Models\Snatch;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SnatchController extends Controller
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$torrentId = $request->torrent_id;
|
||||
$snatches = Snatch::query()->where('torrentid', $torrentId)->with(['user'])->paginate();
|
||||
$resource = SnatchResource::collection($snatches);
|
||||
$resource->additional(['card_titles' => Snatch::$cardTitles]);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
69
app/Http/Controllers/ThankController.php
Normal file
69
app/Http/Controllers/ThankController.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\ThankResource;
|
||||
use App\Models\Thank;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ThankController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$torrentId = $request->torrent_id;
|
||||
$thanks = Thank::query()->where('torrentid', $torrentId)->with(['user'])->paginate();
|
||||
$resource = ThankResource::collection($thanks);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
88
app/Http/Controllers/TorrentController.php
Normal file
88
app/Http/Controllers/TorrentController.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\TorrentResource;
|
||||
use App\Models\Torrent;
|
||||
use App\Repositories\TorrentRepository;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TorrentController extends Controller
|
||||
{
|
||||
private $repository;
|
||||
|
||||
public function __construct(TorrentRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$params = $request->all();
|
||||
$params['visible'] = Torrent::VISIBLE_YES;
|
||||
$result = $this->repository->getList($params);
|
||||
$resource = TorrentResource::collection($result);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$with = ['user', 'basic_audiocodec', '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);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function searchBox()
|
||||
{
|
||||
$result = $this->repository->getSearchBox();
|
||||
|
||||
return $this->success($result);
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,13 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\ExamResource;
|
||||
use App\Http\Resources\InviteResource;
|
||||
use App\Http\Resources\TorrentResource;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Models\Peer;
|
||||
use App\Models\Snatch;
|
||||
use App\Models\User;
|
||||
use App\Repositories\ExamRepository;
|
||||
use App\Repositories\TorrentRepository;
|
||||
use App\Repositories\UserRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
@@ -163,4 +168,105 @@ class UserController extends Controller
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
public function me()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$resource = $this->getUserProfile($user->id);
|
||||
|
||||
$rows = [
|
||||
[
|
||||
['icon' => 'icon-user', 'label' => '种子评论', 'name' => 'comments_count'],
|
||||
['icon' => 'icon-user', 'label' => '论坛坛子', 'name' => 'posts_count'],
|
||||
],[
|
||||
['icon' => 'icon-user', 'label' => '发布种子', 'name' => 'comments_count'],
|
||||
['icon' => 'icon-user', 'label' => '当前做种', 'name' => 'posts_count'],
|
||||
['icon' => 'icon-user', 'label' => '当前下载', 'name' => 'posts_count'],
|
||||
['icon' => 'icon-user', 'label' => '完成种子', 'name' => 'posts_count'],
|
||||
['icon' => 'icon-user', 'label' => '未完成种子', 'name' => 'posts_count'],
|
||||
]
|
||||
];
|
||||
$resource->additional([
|
||||
'card_titles' => User::$cardTitles,
|
||||
'rows' => $rows
|
||||
]);
|
||||
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
private function getUserProfile($id)
|
||||
{
|
||||
$user = User::query()->withCount(['comments', 'posts'])->findOrFail($id);
|
||||
$resource = new UserResource($user);
|
||||
return $resource;
|
||||
}
|
||||
|
||||
public function publishTorrent(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$result = $user->torrents()->orderBy('id', 'desc')->paginate();
|
||||
|
||||
$resource = TorrentResource::collection($result);
|
||||
|
||||
return $resource;
|
||||
|
||||
}
|
||||
|
||||
public function seedingTorrent(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$result = $user->peers_torrents()->where('seeder', Peer::SEEDER_YES)->orderBy('torrent', 'desc')->paginate();
|
||||
|
||||
$resource = TorrentResource::collection($result);
|
||||
|
||||
return $resource;
|
||||
|
||||
}
|
||||
|
||||
public function LeechingTorrent(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$result = $user->peers_torrents()->where('seeder', Peer::SEEDER_NO)->orderBy('torrent', 'desc')->paginate();
|
||||
|
||||
$resource = TorrentResource::collection($result);
|
||||
|
||||
return $resource;
|
||||
|
||||
}
|
||||
|
||||
public function finishedTorrent(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$result = $user->snatched_torrents()
|
||||
->where('owner', '<>', $user->id)
|
||||
->where('finished', Snatch::FINISHED_YES)
|
||||
->orderBy('torrentid', 'desc')
|
||||
->paginate();
|
||||
|
||||
$resource = TorrentResource::collection($result);
|
||||
|
||||
return $resource;
|
||||
|
||||
}
|
||||
|
||||
public function notFinishedTorrent(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$result = $user->snatched_torrents()
|
||||
->where('owner', '<>', $user->id)
|
||||
->where('finished', Snatch::FINISHED_NO)
|
||||
->orderBy('torrentid', 'desc')
|
||||
->paginate();
|
||||
|
||||
$resource = TorrentResource::collection($result);
|
||||
|
||||
return $resource;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
22
app/Http/Resources/AudioCodecResource.php
Normal file
22
app/Http/Resources/AudioCodecResource.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AudioCodecResource 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Http/Resources/CategoryResource.php
Normal file
22
app/Http/Resources/CategoryResource.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CategoryResource 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Http/Resources/CodecResource.php
Normal file
22
app/Http/Resources/CodecResource.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CodecResource 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
29
app/Http/Resources/CommentResource.php
Normal file
29
app/Http/Resources/CommentResource.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CommentResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$descriptionArr = format_description($this->text);
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'description' => $descriptionArr,
|
||||
'images' => get_image_from_description($descriptionArr),
|
||||
'updated_at_human' => format_datetime($this->editdate),
|
||||
'created_at_human' => $this->added->format('Y-m-d H:i'),
|
||||
'create_user' => new UserResource($this->whenLoaded('create_user')),
|
||||
'update_user' => new UserResource($this->whenLoaded('update_user')),
|
||||
];
|
||||
}
|
||||
}
|
||||
23
app/Http/Resources/FileResource.php
Normal file
23
app/Http/Resources/FileResource.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class FileResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'filename' => $this->filename,
|
||||
'size_human' => mksize($this->size),
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Http/Resources/MediaResource.php
Normal file
22
app/Http/Resources/MediaResource.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class MediaResource 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
25
app/Http/Resources/MessageResource.php
Normal file
25
app/Http/Resources/MessageResource.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class MessageResource 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,
|
||||
'msg' => strip_all_tags($this->msg),
|
||||
'added_human' => $this->added->diffForHumans(),
|
||||
'send_user' => new UserResource($this->whenLoaded('send_user')),
|
||||
];
|
||||
}
|
||||
}
|
||||
82
app/Http/Resources/PeerResource.php
Normal file
82
app/Http/Resources/PeerResource.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PeerResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$seconds = $this->started->diff($this->last_action)->s;
|
||||
if ($this->uploaded == 0) {
|
||||
$uploadSpeed = mksize(0) . '/s';
|
||||
} else {
|
||||
$uploadSpeed = mksize(($this->uploaded - $this->uploadoffset) / $seconds) . '/s';
|
||||
}
|
||||
$nowTimestamp = time();
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'connectable_text' => $this->connectableText,
|
||||
|
||||
'upload_text' => sprintf('%s@%s', mksize($this->uploaded), $uploadSpeed),
|
||||
|
||||
'download_text' => sprintf('%s@%s', mksize($this->downloaded), $this->getUploadSpeed($this->resource)),
|
||||
|
||||
'share_ratio' => $this->getShareRatio($this->resource),
|
||||
'download_progress' => $this->getDownloadProgress($this->resource),
|
||||
'connect_time_total' => mkprettytime($nowTimestamp - $this->started->timestamp),
|
||||
'last_action_human' => mkprettytime($nowTimestamp - $this->last_action->timestamp),
|
||||
'agent_human' => htmlspecialchars(get_agent($this->peer_id, $this->agent)),
|
||||
'user' => new UserResource($this->whenLoaded('user')),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得上传速度
|
||||
*
|
||||
* @see viewpeerlist.php
|
||||
*
|
||||
* @param $peer
|
||||
* @return string
|
||||
*/
|
||||
protected function getUploadSpeed($peer)
|
||||
{
|
||||
$diff = $peer->downloaded - $peer->downloadoffset;
|
||||
if ($peer->isSeeder()) {
|
||||
$seconds = $peer->finishedat - $peer->started->getTimestamp();
|
||||
} else {
|
||||
$seconds = $this->started->diff($this->last_action)->s;
|
||||
}
|
||||
|
||||
return mksize($diff / $seconds) . '/s';
|
||||
}
|
||||
|
||||
protected function getShareRatio($peer)
|
||||
{
|
||||
if ($peer->downloaded) {
|
||||
$ratio = floor(($peer->uploaded / $peer->downloaded) * 1000) / 1000;
|
||||
} elseif ($peer->uploaded) {
|
||||
//@todo 读语言文件
|
||||
$ratio = '无限';
|
||||
} else {
|
||||
$ratio = '---';
|
||||
}
|
||||
|
||||
return $ratio;
|
||||
}
|
||||
|
||||
protected function getDownloadProgress($peer)
|
||||
{
|
||||
return sprintf("%.2f%%", 100 * (1 - ($peer->to_go / $peer->relative_torrent->size)));
|
||||
}
|
||||
|
||||
}
|
||||
22
app/Http/Resources/ProcessingResource.php
Normal file
22
app/Http/Resources/ProcessingResource.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ProcessingResource 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
38
app/Http/Resources/SnatchResource.php
Normal file
38
app/Http/Resources/SnatchResource.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SnatchResource extends PeerResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
* @see viewsnatches.php
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$uploaded = mksize($this->uploaded);
|
||||
$downloaded = mksize($this->downloaded);
|
||||
$seedtime = mkprettytime($this->seedtime);
|
||||
$leechtime = mkprettytime($this->leechtime);
|
||||
$uprate = $this->seedtime > 0 ? mksize($this->uploaded / ($this->seedtime + $this->leechtime)) : mksize(0);
|
||||
$downrate = $this->leechtime > 0 ? mksize($this->downloaded / $this->leechtime) : mksize(0);
|
||||
$nowTimestamp = time();
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'upload_text' => $uploaded . "@" . $uprate . "/s",
|
||||
'download_text' => $downloaded . "@" . $downrate . "/s",
|
||||
'share_ratio' => $this->getShareRatio($this->resource),
|
||||
'seed_time' => $seedtime,
|
||||
'leech_time' => $leechtime,
|
||||
'completed_at_human' => mkprettytime($nowTimestamp - $this->completedat->timestamp),
|
||||
'last_action_human' => mkprettytime($nowTimestamp - $this->last_action->timestamp),
|
||||
'user' => new UserResource($this->whenLoaded('user')),
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Http/Resources/SourceResource.php
Normal file
22
app/Http/Resources/SourceResource.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SourceResource 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Http/Resources/StandardResource.php
Normal file
22
app/Http/Resources/StandardResource.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class StandardResource 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Http/Resources/TeamResource.php
Normal file
22
app/Http/Resources/TeamResource.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TeamResource 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,
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Http/Resources/ThankResource.php
Normal file
22
app/Http/Resources/ThankResource.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ThankResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'user' => new UserResource($this->whenLoaded('user')),
|
||||
];
|
||||
}
|
||||
}
|
||||
85
app/Http/Resources/TorrentResource.php
Normal file
85
app/Http/Resources/TorrentResource.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Attachment;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TorrentResource extends JsonResource
|
||||
{
|
||||
protected $imageTypes = ['image', 'attachment'];
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$out = [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'filename' => $this->filename,
|
||||
'small_descr' => $this->small_descr,
|
||||
'comments' => $this->comments,
|
||||
'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,
|
||||
'user' => new UserResource($this->whenLoaded('user')),
|
||||
'basic_category' => new CategoryResource($this->whenLoaded('basic_category')),
|
||||
];
|
||||
|
||||
if ($request->routeIs('torrents.show')) {
|
||||
$baseInfo = [
|
||||
['label' => '大小', '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];
|
||||
}
|
||||
$out['base_info'] = $baseInfo;
|
||||
$descriptionArr = format_description($this->descr);
|
||||
$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['cover'] = get_image_from_description(format_description($this->descr), true);
|
||||
// $out['upload_peers_count'] = $this->upload_peers_count;
|
||||
// $out['download_peers_count'] = $this->download_peers_count;
|
||||
// $out['finish_peers_count'] = $this->finish_peers_count;
|
||||
|
||||
return $out;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@ class UserResource extends JsonResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
$out = [
|
||||
'id' => $this->id,
|
||||
'email' => $this->email,
|
||||
'username' => $this->username,
|
||||
@@ -35,5 +35,17 @@ class UserResource extends JsonResource
|
||||
'leechtime_text' => mkprettytime($this->leechtime),
|
||||
'inviter' => new UserResource($this->whenLoaded('inviter')),
|
||||
];
|
||||
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['seed_bonus'] = $this->seedbonus;
|
||||
$out['invites'] = $this->invites;
|
||||
$out['comments_count'] = $this->comments_count;
|
||||
$out['posts_count'] = $this->posts_count;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
8
app/Models/Attachment.php
Normal file
8
app/Models/Attachment.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Attachment extends NexusModel
|
||||
{
|
||||
|
||||
}
|
||||
9
app/Models/AudioCodec.php
Normal file
9
app/Models/AudioCodec.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class AudioCodec extends NexusModel
|
||||
{
|
||||
protected $table = 'audiocodecs';
|
||||
}
|
||||
9
app/Models/Category.php
Normal file
9
app/Models/Category.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Category extends NexusModel
|
||||
{
|
||||
|
||||
}
|
||||
9
app/Models/Codec.php
Normal file
9
app/Models/Codec.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Codec extends NexusModel
|
||||
{
|
||||
protected $table = 'codecs';
|
||||
}
|
||||
27
app/Models/Comment.php
Normal file
27
app/Models/Comment.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Comment extends NexusModel
|
||||
{
|
||||
protected $casts = [
|
||||
'added' => 'datetime',
|
||||
'editdate' => 'datetime',
|
||||
];
|
||||
|
||||
public function related_torrent()
|
||||
{
|
||||
return $this->belongsTo(Torrent::class, 'torrent');
|
||||
}
|
||||
|
||||
public function create_user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user');
|
||||
}
|
||||
|
||||
public function update_user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'editedby');
|
||||
}
|
||||
}
|
||||
9
app/Models/File.php
Normal file
9
app/Models/File.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class File extends NexusModel
|
||||
{
|
||||
protected $table = 'files';
|
||||
}
|
||||
9
app/Models/Media.php
Normal file
9
app/Models/Media.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Media extends NexusModel
|
||||
{
|
||||
protected $table = 'media';
|
||||
}
|
||||
@@ -9,4 +9,19 @@ class Message extends NexusModel
|
||||
protected $fillable = [
|
||||
'sender', 'receiver', 'added', 'subject', 'msg', 'unread', 'location', 'saved'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'added' => 'datetime',
|
||||
];
|
||||
|
||||
public function send_user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'sender')->withDefault(['id' => 0, 'username' => 'System']);
|
||||
}
|
||||
|
||||
public function receive_user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'receiver');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
73
app/Models/Peer.php
Normal file
73
app/Models/Peer.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class Peer extends NexusModel
|
||||
{
|
||||
const CONNECTABLE_YES = 'yes';
|
||||
|
||||
const CONNECTABLE_NO = 'no';
|
||||
|
||||
protected $casts = [
|
||||
'started' => 'datetime',
|
||||
'last_action' => 'datetime',
|
||||
'prev_action' => 'datetime',
|
||||
];
|
||||
|
||||
public static $connectableText = [
|
||||
self::CONNECTABLE_YES => '是',
|
||||
self::CONNECTABLE_NO => '否',
|
||||
];
|
||||
|
||||
const SEEDER_YES = 'yes';
|
||||
|
||||
const SEEDER_NO = 'no';
|
||||
|
||||
public static $cardTitles = [
|
||||
'upload_text' => '上传',
|
||||
'download_text' => '下载',
|
||||
'share_ratio' => '分享率',
|
||||
'agent_human' => '客户端',
|
||||
'connect_time_total' => '连接时间',
|
||||
'download_progress' => '完成进度',
|
||||
|
||||
];
|
||||
|
||||
public function getConnectableTextAttribute()
|
||||
{
|
||||
return self::$connectableText[$this->connectable] ?? '';
|
||||
}
|
||||
|
||||
public function scopeIsSeeder(Builder $builder)
|
||||
{
|
||||
return $builder->where('seeder', self::SEEDER_YES);
|
||||
}
|
||||
|
||||
public function scopeIsNotSeeder(Builder $builder)
|
||||
{
|
||||
return $builder->where('seeder', self::SEEDER_NO);
|
||||
}
|
||||
|
||||
public function isSeeder()
|
||||
{
|
||||
return $this->seeder == self::SEEDER_YES;
|
||||
}
|
||||
|
||||
public function isNotSeeder()
|
||||
{
|
||||
return $this->seeder == self::SEEDER_NO;
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'userid');
|
||||
}
|
||||
|
||||
public function relative_torrent()
|
||||
{
|
||||
return $this->belongsTo(Torrent::class, 'torrent');
|
||||
}
|
||||
}
|
||||
9
app/Models/Post.php
Normal file
9
app/Models/Post.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Post extends NexusModel
|
||||
{
|
||||
|
||||
}
|
||||
9
app/Models/Processing.php
Normal file
9
app/Models/Processing.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Processing extends NexusModel
|
||||
{
|
||||
protected $table = 'processings';
|
||||
}
|
||||
50
app/Models/Snatch.php
Normal file
50
app/Models/Snatch.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class Snatch extends NexusModel
|
||||
{
|
||||
protected $table = 'snatched';
|
||||
|
||||
protected $casts = [
|
||||
'last_action' => 'datetime',
|
||||
'startdat' => 'datetime',
|
||||
'completedat' => 'datetime',
|
||||
];
|
||||
|
||||
public static $cardTitles = [
|
||||
'upload_text' => '上传',
|
||||
'download_text' => '下载',
|
||||
'share_ratio' => '分享率',
|
||||
'seed_time' => '做种时间',
|
||||
'leech_time' => '下载时间',
|
||||
'completed_at_human' => '完成',
|
||||
];
|
||||
|
||||
const FINISHED_YES = 'yes';
|
||||
|
||||
const FINISHED_NO = 'no';
|
||||
|
||||
public function scopeIsFinished(Builder $builder)
|
||||
{
|
||||
return $builder->where('finished', self::FINISHED_YES);
|
||||
}
|
||||
|
||||
public function scopeIsNotFinished(Builder $builder)
|
||||
{
|
||||
return $builder->where('finished', self::FINISHED_NO);
|
||||
}
|
||||
|
||||
public function torrent()
|
||||
{
|
||||
return $this->belongsTo(Torrent::class, 'torrentid');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'userid');
|
||||
}
|
||||
}
|
||||
8
app/Models/Source.php
Normal file
8
app/Models/Source.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Source extends NexusModel
|
||||
{
|
||||
}
|
||||
9
app/Models/Standard.php
Normal file
9
app/Models/Standard.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Standard extends NexusModel
|
||||
{
|
||||
|
||||
}
|
||||
9
app/Models/Team.php
Normal file
9
app/Models/Team.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Team extends NexusModel
|
||||
{
|
||||
|
||||
}
|
||||
17
app/Models/Thank.php
Normal file
17
app/Models/Thank.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Thank extends NexusModel
|
||||
{
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'userid');
|
||||
}
|
||||
|
||||
public function torrent()
|
||||
{
|
||||
return $this->belongsTo(Torrent::class. 'torrentid');
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,9 @@ class Torrent extends NexusModel
|
||||
const BANNED_YES = 'yes';
|
||||
const BANNED_NO = 'no';
|
||||
|
||||
public $timestamps = true;
|
||||
protected $casts = [
|
||||
'added' => 'datetime'
|
||||
];
|
||||
|
||||
public function checkIsNormal(array $fields = ['visible', 'banned'])
|
||||
{
|
||||
@@ -31,4 +33,104 @@ class Torrent extends NexusModel
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'owner');
|
||||
}
|
||||
|
||||
public function thanks()
|
||||
{
|
||||
return $this->hasMany(Thank::class, 'torrentid');
|
||||
}
|
||||
|
||||
public function thank_users()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'thanks', 'torrentid', 'userid');
|
||||
}
|
||||
|
||||
/**
|
||||
* 同伴
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function peers()
|
||||
{
|
||||
return $this->hasMany(Peer::class, 'torrent');
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成情况
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function snatches()
|
||||
{
|
||||
return $this->hasMany(Snatch::class, 'torrentid');
|
||||
}
|
||||
|
||||
public function upload_peers()
|
||||
{
|
||||
return $this->peers()->where('seeder', Peer::SEEDER_YES);
|
||||
}
|
||||
|
||||
public function download_peers()
|
||||
{
|
||||
return $this->peers()->where('seeder', Peer::SEEDER_NO);
|
||||
}
|
||||
|
||||
public function finish_peers()
|
||||
{
|
||||
return $this->peers()->where('finishedat', '>', 0);
|
||||
}
|
||||
|
||||
public function files()
|
||||
{
|
||||
return $this->hasMany(File::class, 'torrent');
|
||||
}
|
||||
|
||||
public function basic_category()
|
||||
{
|
||||
return $this->belongsTo(Category::class, 'category');
|
||||
}
|
||||
|
||||
public function basic_source()
|
||||
{
|
||||
return $this->belongsTo(Source::class, 'source');
|
||||
}
|
||||
|
||||
public function basic_media()
|
||||
{
|
||||
return $this->belongsTo(Media::class, 'medium');
|
||||
}
|
||||
|
||||
public function basic_codec()
|
||||
{
|
||||
return $this->belongsTo(Codec::class, 'codec');
|
||||
}
|
||||
|
||||
public function basic_standard()
|
||||
{
|
||||
return $this->belongsTo(Standard::class, 'standard');
|
||||
}
|
||||
|
||||
public function basic_processing()
|
||||
{
|
||||
return $this->belongsTo(Processing::class, 'processing');
|
||||
}
|
||||
|
||||
public function basic_team()
|
||||
{
|
||||
return $this->belongsTo(Team::class, 'team');
|
||||
}
|
||||
|
||||
public function basic_audiocodec()
|
||||
{
|
||||
return $this->belongsTo(AudioCodec::class, 'audiocodec');
|
||||
}
|
||||
|
||||
public function scopeVisible($query, $visible = self::VISIBLE_YES)
|
||||
{
|
||||
$query->where('visible', $visible);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,15 @@ class User extends Authenticatable
|
||||
self::CLASS_STAFF_LEADER => ['text' => 'Staff Leader'],
|
||||
];
|
||||
|
||||
public static $cardTitles = [
|
||||
'uploaded_human' => '上传',
|
||||
'downloaded_human' => '下载',
|
||||
'share_ratio' => '分享率',
|
||||
'seed_time' => '做种时间',
|
||||
'seed_bonus' => '魔力值',
|
||||
'invites' => '邀请',
|
||||
];
|
||||
|
||||
public function getClassTextAttribute(): string
|
||||
{
|
||||
return self::$classes[$this->class]['text'] ?? '';
|
||||
@@ -157,6 +166,68 @@ class User extends Authenticatable
|
||||
return $this->belongsTo(User::class, 'invited_by');
|
||||
}
|
||||
|
||||
public function send_messages()
|
||||
{
|
||||
return $this->hasMany(Message::class, 'sender');
|
||||
}
|
||||
|
||||
public function receive_messages()
|
||||
{
|
||||
return $this->hasMany(Message::class, 'receiver');
|
||||
}
|
||||
|
||||
public function comments()
|
||||
{
|
||||
return $this->hasMany(Comment::class, 'user');
|
||||
}
|
||||
|
||||
public function posts()
|
||||
{
|
||||
return $this->hasMany(Post::class, 'userid');
|
||||
}
|
||||
|
||||
public function torrents()
|
||||
{
|
||||
return $this->hasMany(Torrent::class, 'owner');
|
||||
}
|
||||
|
||||
|
||||
public function peers_torrents()
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
Torrent::class,
|
||||
Peer::class,
|
||||
'userid',
|
||||
'id',
|
||||
'id',
|
||||
'torrent');
|
||||
}
|
||||
|
||||
public function snatched_torrents()
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
Torrent::class,
|
||||
Snatch::class,
|
||||
'userid',
|
||||
'id',
|
||||
'id',
|
||||
'torrentid');
|
||||
}
|
||||
|
||||
public function getAvatarAttribute($value)
|
||||
{
|
||||
if ($value) {
|
||||
if (substr($value, 0, 4) == 'http') {
|
||||
return $value;
|
||||
} else {
|
||||
do_log("用户头像: $value 不是 http 地址");
|
||||
}
|
||||
}
|
||||
|
||||
return getSchemeAndHttpHost() . '/pic/default_avatar.png';
|
||||
|
||||
}
|
||||
|
||||
public function updateWithModComment(array $update, $modComment)
|
||||
{
|
||||
if (!$this->exists) {
|
||||
|
||||
@@ -10,13 +10,13 @@ class ToolRepository extends BaseRepository
|
||||
public function getSystemInfo(): array
|
||||
{
|
||||
$systemInfo = [
|
||||
'nexus_version' => config('app.nexus_version'),
|
||||
'nexus_version' => VERSION_NUMBER,
|
||||
'nexus_release_date' => RELEASE_DATE,
|
||||
'laravel_version' => \Illuminate\Foundation\Application::VERSION,
|
||||
'php_version' => PHP_VERSION,
|
||||
'mysql_version' => DB::select(DB::raw('select version() as info'))[0]->info,
|
||||
'os' => PHP_OS,
|
||||
'server_software' => $_SERVER['SERVER_SOFTWARE'],
|
||||
|
||||
];
|
||||
|
||||
return $systemInfo;
|
||||
|
||||
127
app/Repositories/TorrentRepository.php
Normal file
127
app/Repositories/TorrentRepository.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\AudioCodec;
|
||||
use App\Models\Category;
|
||||
use App\Models\Codec;
|
||||
use App\Models\Media;
|
||||
use App\Models\Processing;
|
||||
use App\Models\Source;
|
||||
use App\Models\Standard;
|
||||
use App\Models\Team;
|
||||
use App\Models\Torrent;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TorrentRepository extends BaseRepository
|
||||
{
|
||||
/**
|
||||
* fetch torrent list
|
||||
*
|
||||
* @param array $params
|
||||
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
|
||||
*/
|
||||
public function getList(array $params)
|
||||
{
|
||||
$query = Torrent::query();
|
||||
if (!empty($params['category'])) {
|
||||
$query->where('category', $params['category']);
|
||||
}
|
||||
if (!empty($params['source'])) {
|
||||
$query->where('source', $params['source']);
|
||||
}
|
||||
if (!empty($params['medium'])) {
|
||||
$query->where('medium', $params['medium']);
|
||||
}
|
||||
if (!empty($params['codec'])) {
|
||||
$query->where('codec', $params['codec']);
|
||||
}
|
||||
if (!empty($params['audio_codec'])) {
|
||||
$query->where('audiocodec', $params['audio_codec']);
|
||||
}
|
||||
if (!empty($params['standard'])) {
|
||||
$query->where('standard', $params['standard']);
|
||||
}
|
||||
if (!empty($params['processing'])) {
|
||||
$query->where('processing', $params['processing']);
|
||||
}
|
||||
if (!empty($params['team'])) {
|
||||
$query->where('team', $params['team']);
|
||||
}
|
||||
if (!empty($params['owner'])) {
|
||||
$query->where('owner', $params['owner']);
|
||||
}
|
||||
if (!empty($params['visible'])) {
|
||||
$query->where('visible', $params['visible']);
|
||||
}
|
||||
|
||||
if (!empty($params['query'])) {
|
||||
$query->where(function (Builder $query) use ($params) {
|
||||
$query->where('name', 'like', "%{$params['query']}%")
|
||||
->orWhere('small_descr', 'like', "%{$params['query']}%");
|
||||
});
|
||||
}
|
||||
|
||||
list($sortField, $sortType) = $this->getSortFieldAndType($params);
|
||||
$query->orderBy($sortField, $sortType);
|
||||
|
||||
$with = ['user'];
|
||||
$torrents = $query->with($with)->paginate();
|
||||
return $torrents;
|
||||
}
|
||||
|
||||
public function getSearchBox()
|
||||
{
|
||||
$category = Category::query()->orderBy('sort_index')->orderBy('id')->get();
|
||||
$source = Source::query()->orderBy('sort_index')->orderBy('id')->get();
|
||||
$media = Media::query()->orderBy('sort_index')->orderBy('id')->get();
|
||||
$codec = Codec::query()->orderBy('sort_index')->orderBy('id')->get();
|
||||
$standard = Standard::query()->orderBy('sort_index')->orderBy('id')->get();
|
||||
$processing = Processing::query()->orderBy('sort_index')->orderBy('id')->get();
|
||||
$team = Team::query()->orderBy('sort_index')->orderBy('id')->get();
|
||||
$audioCodec = AudioCodec::query()->orderBy('sort_index')->orderBy('id')->get();
|
||||
|
||||
$modalRows = [];
|
||||
$modalRows[] = $categoryFormatted = $this->formatRow('类型', $category, 'category');
|
||||
$modalRows[] = $this->formatRow('媒介', $source, 'source');
|
||||
$modalRows[] = $this->formatRow('媒介', $media, 'medium');
|
||||
$modalRows[] = $this->formatRow('编码', $codec, 'codec');
|
||||
$modalRows[] = $this->formatRow('音频编码', $audioCodec, 'audio_codec');
|
||||
$modalRows[] = $this->formatRow('分辨率', $standard, 'standard');
|
||||
$modalRows[] = $this->formatRow('处理', $processing, 'processing');
|
||||
$modalRows[] = $this->formatRow('制作组', $team, 'team');
|
||||
|
||||
$results = [];
|
||||
$categories = $categoryFormatted['rows'];
|
||||
$categories[0]['active'] = 1;
|
||||
$results['categories'] = $categories;
|
||||
$results['modal_rows'] = $modalRows;
|
||||
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function formatRow($header, $items, $name)
|
||||
{
|
||||
$result['header'] = $header;
|
||||
$result['rows'][] = [
|
||||
'label' => '全部',
|
||||
'value' => 0,
|
||||
'name' => $name,
|
||||
'active' => 1,
|
||||
];
|
||||
foreach ($items as $value) {
|
||||
$item = [
|
||||
'label' => $value->name,
|
||||
'value' => $value->id,
|
||||
'name' => $name,
|
||||
'active' => 0,
|
||||
];
|
||||
$result['rows'][] = $item;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user