mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
define('REQUEST_ID', $_SERVER['HTTP_X_REQUEST_ID'] ?? $_SERVER['REQUEST_ID'] ?? str_pad(str_replace('.', '', LARAVEL_START), 14, "0", STR_PAD_RIGHT));
|
||||
|
||||
define('IN_NEXUS', false);
|
||||
|
||||
require dirname(__DIR__) . '/include/constants.php';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Create The Application
|
||||
|
||||
@@ -232,6 +232,4 @@ return [
|
||||
|
||||
],
|
||||
|
||||
'nexus_version' => '1.6.0-beta5',
|
||||
|
||||
];
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
<?php
|
||||
define('NEXUS_START', microtime(true));
|
||||
define('IN_TRACKER', true);
|
||||
define("PROJECTNAME","NexusPHP");
|
||||
define("NEXUSPHPURL","http://nexusphp.org");
|
||||
define("NEXUSWIKIURL","http://doc.nexusphp.org");
|
||||
define("VERSION","Powered by <a href=\"aboutnexus.php\">".PROJECTNAME."</a>");
|
||||
define("THISTRACKER","General");
|
||||
$showversion = " - Powered by ".PROJECTNAME;
|
||||
$rootpath= dirname(__DIR__);
|
||||
define('IN_NEXUS', true);
|
||||
$rootpath = dirname(__DIR__) . '/';
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . $rootpath);
|
||||
$rootpath .= "/";
|
||||
require $rootpath . 'include/core.php';
|
||||
require $rootpath . 'classes/class_advertisement.php';
|
||||
require $rootpath . 'classes/class_attendance.php';
|
||||
require $rootpath . 'include/core.php';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
define('NEXUS_START', microtime(true));
|
||||
# IMPORTANT: Do not edit below unless you know what you are doing!
|
||||
define('IN_TRACKER', true);
|
||||
define('IN_NEXUS', true);
|
||||
$rootpath= dirname(__DIR__) . '/';
|
||||
require $rootpath . 'include/functions_announce.php';
|
||||
require $rootpath . 'include/core.php';
|
||||
require $rootpath . 'include/functions_announce.php';
|
||||
|
||||
|
||||
14
include/constants.php
Normal file
14
include/constants.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
define('VERSION_NUMBER', '1.6.0-beta7');
|
||||
define('RELEASE_DATE', '2020-05-15');
|
||||
define('IN_TRACKER', true);
|
||||
define("PROJECTNAME","NexusPHP");
|
||||
define("NEXUSPHPURL","https://nexusphp.org");
|
||||
define("NEXUSWIKIURL","https://doc.nexusphp.org");
|
||||
define("VERSION","Powered by <a href=\"aboutnexus.php\">".PROJECTNAME."</a>");
|
||||
define("THISTRACKER","General");
|
||||
$showversion = " - Powered by ".PROJECTNAME;
|
||||
define('ROOT_PATH', dirname(__DIR__) . '/');
|
||||
define('CURRENT_SCRIPT', strstr(basename($_SERVER['SCRIPT_FILENAME']), '.', true));
|
||||
define('IS_ANNOUNCE', CURRENT_SCRIPT == 'announce');
|
||||
define('REQUEST_ID', $_SERVER['HTTP_X_REQUEST_ID'] ?? $_SERVER['REQUEST_ID'] ?? str_pad(str_replace('.', '', NEXUS_START), 14, "0", STR_PAD_RIGHT));
|
||||
@@ -1,13 +1,5 @@
|
||||
<?php
|
||||
if(!defined('IN_TRACKER')) {
|
||||
die('Hacking attempt!');
|
||||
}
|
||||
define('IN_NEXUS', true);
|
||||
define('ROOT_PATH', $rootpath);
|
||||
define('VERSION_NUMBER', '1.6.0');
|
||||
define('CURRENT_SCRIPT', strstr(basename($_SERVER['SCRIPT_FILENAME']), '.', true));
|
||||
define('IS_ANNOUNCE', CURRENT_SCRIPT == 'announce');
|
||||
define('REQUEST_ID', $_SERVER['HTTP_X_REQUEST_ID'] ?? $_SERVER['REQUEST_ID'] ?? str_pad(str_replace('.', '', NEXUS_START), 14, "0", STR_PAD_RIGHT));;
|
||||
require __DIR__ . '/constants.php';
|
||||
require $rootpath . 'vendor/autoload.php';
|
||||
if (!file_exists($rootpath . '.env')) {
|
||||
$installScriptRelativePath = 'install/install.php';
|
||||
|
||||
@@ -4734,4 +4734,217 @@ function build_table(array $header, array $rows, array $options = [])
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回链接中附件的key
|
||||
*
|
||||
* @param $url
|
||||
* @return string
|
||||
*/
|
||||
function attachmentKey($url)
|
||||
{
|
||||
if (!filter_var($url, FILTER_VALIDATE_URL))
|
||||
{
|
||||
throw new \InvalidArgumentException("URL: '$url' invalid.");
|
||||
}
|
||||
$parsed = parse_url($url);
|
||||
$driver = config('admin.upload.disk');
|
||||
if ($driver == 'qiniu') {
|
||||
return trim($parsed['path'], "/");
|
||||
} elseif ($driver == 'cloudinary') {
|
||||
$parts = explode('/', $parsed['path']);
|
||||
$key = end($parts);
|
||||
if (\Illuminate\Support\Str::contains($key,'.')) {
|
||||
$key = strstr($key, '.', true);
|
||||
}
|
||||
return $key;
|
||||
|
||||
} else {
|
||||
throw new \RuntimeException('不支持的云盘驱动');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据key返回链接
|
||||
*
|
||||
* @param $location
|
||||
* @param null $width
|
||||
* @param null $height
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
function attachmentUrl($location, $width = null, $height = null, $options = [])
|
||||
{
|
||||
return sprintf('%s/attachments/%s', getSchemeAndHttpHost(), trim($location, '/'));
|
||||
}
|
||||
|
||||
|
||||
function strip_all_tags($text)
|
||||
{
|
||||
//替换掉无参数标签
|
||||
$bbTags = [
|
||||
'[*]', '[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[pre]', '[/pre]', '[quote]', '[/quote]',
|
||||
'[/color]', '[/font]', '[/size]', '[/url]'
|
||||
];
|
||||
$text = str_replace($bbTags, '', $text);
|
||||
//替换掉有参数标签
|
||||
$pattern = '/\[url=.*\]|\[color=.*\]|\[font=.*\]|\[size=.*\]/isU';
|
||||
$text = preg_replace($pattern, "", $text);
|
||||
//去掉表情
|
||||
static $emoji = null;
|
||||
if (is_null($emoji)) {
|
||||
$emoji = config('emoji');
|
||||
}
|
||||
// $text = preg_replace("/\[em([1-9][0-9]*)\]/isU", "", $text);
|
||||
$text = preg_replace_callback("/\[em([1-9][0-9]*)\]/isU", function ($matches) use ($emoji) {
|
||||
return $emoji[$matches[1]] ?? '';
|
||||
}, $text);
|
||||
|
||||
$text = strip_tags($text);
|
||||
|
||||
return trim($text);
|
||||
}
|
||||
|
||||
function format_description(string $description)
|
||||
{
|
||||
//替换附件
|
||||
$pattern = '/(\[attach\](.*)\[\/attach\])/isU';
|
||||
$matchCount = preg_match_all($pattern, $description, $matches);
|
||||
if ($matchCount) {
|
||||
$attachments = \App\Models\Attachment::query()->whereIn('dlkey', $matches[2])->get()->keyBy('dlkey');
|
||||
if ($attachments->isNotEmpty()) {
|
||||
$description = preg_replace_callback($pattern, function ($matches) use ($attachments) {
|
||||
$item = $attachments->get($matches[2]);
|
||||
$url = attachmentUrl($item->location);
|
||||
return str_replace($matches[2], $url, $matches[1]);
|
||||
}, $description);
|
||||
}
|
||||
}
|
||||
//去除引用
|
||||
// $pattern = '/\[quote.*\].*\[\/quote\]/is';
|
||||
// $description = preg_replace($pattern, '', $description);
|
||||
|
||||
//去掉引用自
|
||||
$pattern = '/\[quote=.*\]/isU';
|
||||
$description = preg_replace_callback($pattern, function ($matches) {
|
||||
return '[quote]';
|
||||
}, $description);
|
||||
|
||||
//过虑多层引用
|
||||
$delimiter = '__CYLX__';
|
||||
$pattern = '/(\[quote\]){2,}(((?!\[quote\]).)*)\[\/quote\]/isU';
|
||||
$description = preg_replace_callback($pattern, function ($matches) use ($delimiter) {
|
||||
return $delimiter;
|
||||
}, $description);
|
||||
|
||||
$pattern = "/$delimiter(((?!\[quote\]).)+)\[\/quote\]/is";
|
||||
$description = preg_replace_callback($pattern, function ($matches) use ($delimiter) {
|
||||
$arr = array_reverse(explode('[/quote]', $matches[0]));
|
||||
foreach ($arr as $value) {
|
||||
$value = trim(str_replace($delimiter, '', $value));
|
||||
if (!empty($value)) {
|
||||
return "[quote]{$value}[/quote]";
|
||||
}
|
||||
}
|
||||
}, $description);
|
||||
|
||||
|
||||
//匹配不同块
|
||||
$attachPattern = '\[attach\].*\[\/attach\]';
|
||||
$imgPattern = '\[img\].*\[\/img\]';
|
||||
$urlPattern = '\[url=.*\].*\[\/url\]';
|
||||
$quotePattern = '\[quote.*\].*\[\/quote\]';
|
||||
$pattern = "/($attachPattern)|($imgPattern)|($urlPattern)|($quotePattern)/isU";
|
||||
// $pattern = "/($attachPattern)|($imgPattern)|($urlPattern)/isU";
|
||||
$delimiter = '{{||}}';
|
||||
$description = preg_replace_callback($pattern, function ($matches) use ($delimiter) {
|
||||
return $delimiter . $matches[0] . $delimiter;
|
||||
}, $description);
|
||||
|
||||
//再进行分割
|
||||
$descriptionArr = preg_split("/[$delimiter]+/", $description);
|
||||
$results = [];
|
||||
foreach ($descriptionArr as $item) {
|
||||
if (preg_match('/\[attach\](.*)\[\/attach\]/isU', $item, $matches)) {
|
||||
//是否附件
|
||||
$results[] = [
|
||||
'type' => 'attachment',
|
||||
'data' => [
|
||||
'url' => $matches[1]
|
||||
]
|
||||
];
|
||||
} elseif (preg_match('/\[img\](.*)\[\/img\]/isU', $item, $matches)) {
|
||||
//是否图片
|
||||
$results[] = [
|
||||
'type' => 'image',
|
||||
'data' => [
|
||||
'url' => $matches[1]
|
||||
]
|
||||
];
|
||||
} elseif (preg_match('/\[url=(.*)\](.*)\[\/url\]/isU', $item, $matches)) {
|
||||
$results[] = [
|
||||
'type' => 'url',
|
||||
'data' => [
|
||||
'url' => $matches[1],
|
||||
'text' => strip_all_tags($matches[2])
|
||||
]
|
||||
];
|
||||
} elseif (preg_match('/\[quote=?(.*)\](.*)\[\/quote\]/isU', $item, $matches)) {
|
||||
$results[] = [
|
||||
'type' => 'quote',
|
||||
'data' => [
|
||||
'quote_text' => $matches[1],
|
||||
'text' => strip_all_tags($matches[2]),
|
||||
]
|
||||
];
|
||||
} elseif (!empty($item)) {
|
||||
$results[] = [
|
||||
'type' => 'text',
|
||||
'data' => [
|
||||
'text' => strip_all_tags($item)
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
// dd($description, $results);
|
||||
return $results;
|
||||
}
|
||||
|
||||
function get_image_from_description(array $descriptionArr, $first = false)
|
||||
{
|
||||
$imageType = ['attachment', 'image'];
|
||||
$images = [];
|
||||
foreach ($descriptionArr as $value) {
|
||||
if (!in_array($value['type'], $imageType)) {
|
||||
continue;
|
||||
}
|
||||
$url = $value['data']['url'] ?? '';
|
||||
if (!$url) {
|
||||
continue;
|
||||
}
|
||||
if ($first) {
|
||||
return $url;
|
||||
} else {
|
||||
$images[] = $url;
|
||||
}
|
||||
}
|
||||
if ($first) {
|
||||
return getSchemeAndHttpHost() . "/pic/imdb_pic/nophoto.gif";
|
||||
}
|
||||
return $images;
|
||||
}
|
||||
|
||||
function get_share_ratio($uploaded, $downloaded)
|
||||
{
|
||||
if ($downloaded) {
|
||||
$ratio = floor(($uploaded / $downloaded) * 1000) / 1000;
|
||||
} elseif ($uploaded) {
|
||||
//@todo 读语言文件
|
||||
$ratio = '无限';
|
||||
} else {
|
||||
$ratio = '---';
|
||||
}
|
||||
return $ratio;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -422,10 +422,6 @@ function getSchemeAndHttpHost()
|
||||
$protocol = $isHttps ? 'https' : 'http';
|
||||
$port = $_SERVER['SERVER_PORT'];
|
||||
$result = "$protocol://" . $_SERVER['HTTP_HOST'];
|
||||
//HTTP_HOST include port
|
||||
// if ((!$isHttps && $port != 80) || ($isHttps && $port != 443)) {
|
||||
// $result .= ":$port";
|
||||
// }
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ begin_main_frame();
|
||||
begin_frame("<span id=\"version\">".$lang_aboutnexus['text_version']."</span>");
|
||||
print ($lang_aboutnexus['text_version_note']);
|
||||
print ("<br /><br /><table class=\"main\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\" align=\"center\">");
|
||||
tr($lang_aboutnexus['text_main_version'],$mainversion_code,1);
|
||||
tr($lang_aboutnexus['text_sub_version'],$subversion_code,1);
|
||||
tr($lang_aboutnexus['text_release_date'],$releasedate_code,1);
|
||||
tr($lang_aboutnexus['text_main_version'],PROJECTNAME,1);
|
||||
tr($lang_aboutnexus['text_sub_version'],VERSION_NUMBER,1);
|
||||
tr($lang_aboutnexus['text_release_date'],RELEASE_DATE,1);
|
||||
print ("</table>");
|
||||
print ("<br /><br />");
|
||||
end_frame();
|
||||
@@ -56,7 +56,7 @@ end_frame();
|
||||
begin_frame("<span id=\"contact\">".$lang_aboutnexus['text_contact'].PROJECTNAME."</span>");
|
||||
print ($lang_aboutnexus['text_contact_note']);
|
||||
print ("<br /><br /><table class=\"main\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\" align=\"center\">");
|
||||
tr($lang_aboutnexus['text_web_site'],$website_code ? $website_code : "N/A",1);
|
||||
tr($lang_aboutnexus['text_web_site'],'<a href="' . NEXUSPHPURL . '" target="_blank">' . NEXUSPHPURL . '</a>',1);
|
||||
print ("</table>");
|
||||
print ("<br /><br />");
|
||||
end_frame();
|
||||
|
||||
@@ -29,6 +29,22 @@ Route::group(['middleware' => ['auth:sanctum', 'permission', 'locale']], functio
|
||||
Route::post('user-enable', [\App\Http\Controllers\UserController::class, 'enable']);
|
||||
Route::post('user-reset-password', [\App\Http\Controllers\UserController::class, 'resetPassword']);
|
||||
|
||||
Route::get('user-me',[\App\Http\Controllers\UserController::class, 'me'])->name('user.me');
|
||||
Route::get('user-publish-torrent',[\App\Http\Controllers\UserController::class, 'publishTorrent']);
|
||||
Route::get('user-seeding-torrent',[\App\Http\Controllers\UserController::class, 'seedingTorrent']);
|
||||
Route::get('user-leeching-torrent',[\App\Http\Controllers\UserController::class, 'leechingTorrent']);
|
||||
Route::get('user-finished-torrent',[\App\Http\Controllers\UserController::class, 'finishedTorrent']);
|
||||
Route::get('user-not-finished-torrent',[\App\Http\Controllers\UserController::class, 'notFinishedTorrent']);
|
||||
Route::resource('messages', \App\Http\Controllers\MessageController::class);
|
||||
Route::resource('torrents', \App\Http\Controllers\TorrentController::class);
|
||||
Route::resource('comments', \App\Http\Controllers\CommentController::class);
|
||||
Route::resource('peers', \App\Http\Controllers\PeerController::class);
|
||||
Route::resource('files', \App\Http\Controllers\FileController::class);
|
||||
Route::resource('thanks', \App\Http\Controllers\ThankController::class);
|
||||
Route::resource('snatches', \App\Http\Controllers\SnatchController::class);
|
||||
Route::get('search-box', [\App\Http\Controllers\TorrentController::class, 'searchBox']);
|
||||
|
||||
|
||||
Route::resource('exams', \App\Http\Controllers\ExamController::class);
|
||||
Route::get('exam-indexes', [\App\Http\Controllers\ExamController::class, 'indexes']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user