mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-15 04:52:18 +08:00
exam support valid multiple
This commit is contained in:
110
app/Http/Controllers/HitAndRunController.php
Normal file
110
app/Http/Controllers/HitAndRunController.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\HitAndRunResource;
|
||||
use App\Models\HitAndRun;
|
||||
use App\Repositories\HitAndRunRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class HitAndRunController extends Controller
|
||||
{
|
||||
private $repository;
|
||||
|
||||
public function __construct(HitAndRunRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
private function getRules(): array
|
||||
{
|
||||
return [
|
||||
'family_id' => 'required|numeric',
|
||||
'name' => 'required|string',
|
||||
'peer_id' => 'required|string',
|
||||
'agent' => 'required|string',
|
||||
'comment' => 'required|string',
|
||||
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$result = $this->repository->getList($request->all());
|
||||
$resource = HitAndRunResource::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)
|
||||
{
|
||||
$request->validate($this->getRules());
|
||||
$result = $this->repository->store($request->all());
|
||||
$resource = new HitAndRunResource($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$result = $this->repository->getDetail($id);
|
||||
$resource = new HitAndRunResource($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$request->validate($this->getRules());
|
||||
$result = $this->repository->update($request->all(), $id);
|
||||
$resource = new HitAndRunResource($result);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return array
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$result = $this->repository->delete($id);
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
public function listStatus(): array
|
||||
{
|
||||
$result = $this->repository->listStatus();
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
public function pardon($id): array
|
||||
{
|
||||
$result = $this->repository->pardon($id, Auth::user());
|
||||
return $this->success($result);
|
||||
}
|
||||
}
|
||||
@@ -25,9 +25,10 @@ class Locale
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$language = $request->user()->language;
|
||||
$user = $request->user();
|
||||
$language = $user->language;
|
||||
$locale = self::$languageMaps[$language->site_lang_folder] ?? 'en';
|
||||
do_log("set locale: " . $locale);
|
||||
do_log("user: {$user->id}, language: {$language->id}, set locale: $locale");
|
||||
App::setLocale($locale);
|
||||
Carbon::setLocale($locale);
|
||||
|
||||
|
||||
38
app/Http/Resources/HitAndRunResource.php
Normal file
38
app/Http/Resources/HitAndRunResource.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class HitAndRunResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$out = [
|
||||
'id' => $this->id,
|
||||
'uid' => $this->uid,
|
||||
'user' => new UserResource($this->whenLoaded('user')),
|
||||
'torrent_id' => $this->torrent_id,
|
||||
'torrent' => new TorrentResource($this->whenLoaded('torrent')),
|
||||
'snatched_id' => $this->snatched_id,
|
||||
'snatch' => new SnatchResource($this->whenLoaded('snatch')),
|
||||
'status' => $this->status,
|
||||
'status_text' => $this->status_text,
|
||||
'comment' => $this->comment,
|
||||
'created_at' => format_datetime($this->created_at),
|
||||
'updated_at' => format_datetime($this->updated_at),
|
||||
'seed_time_required' => $this->seedTimeRequired,
|
||||
'inspect_time_left' => $this->inspectTimeLeft,
|
||||
];
|
||||
if (nexus()->isPlatformAdmin()) {
|
||||
$out['comment'] = nl2br(trim($out['comment']));
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SnatchResource extends PeerResource
|
||||
class SnatchResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
@@ -20,10 +20,10 @@ class SnatchResource extends PeerResource
|
||||
'upload_text' => $this->upload_text,
|
||||
'download_text' => $this->download_text,
|
||||
'share_ratio' => $this->share_ratio,
|
||||
'seed_time' => $this->seed_time,
|
||||
'leech_time' => $this->leech_time,
|
||||
'completed_at_human' => $this->completed_at_human,
|
||||
'last_action_human' => $this->last_action_human,
|
||||
'seed_time' => mkprettytime($this->seedtime),
|
||||
'leech_time' => mkprettytime($this->leechtime),
|
||||
'completed_at_human' => $this->completedat ? $this->completedat->diffForHumans() : '',
|
||||
'last_action_human' => $this->last_action ? $this->last_action->diffForHumans() : '',
|
||||
'user' => new UserResource($this->whenLoaded('user')),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Models\Attachment;
|
||||
use App\Models\Torrent;
|
||||
use Carbon\CarbonInterface;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Nexus\Nexus;
|
||||
|
||||
class TorrentResource extends JsonResource
|
||||
{
|
||||
@@ -69,6 +70,10 @@ class TorrentResource extends JsonResource
|
||||
$out['peers_count'] = $this->peers_count;
|
||||
$out['reward_logs_count'] = $this->reward_logs_count;
|
||||
}
|
||||
if (nexus()->isPlatformAdmin()) {
|
||||
$out['details_url'] = sprintf('%s/details.php?id=%s', getSchemeAndHttpHost(), $this->id);
|
||||
}
|
||||
|
||||
// $out['upload_peers_count'] = $this->upload_peers_count;
|
||||
// $out['download_peers_count'] = $this->download_peers_count;
|
||||
// $out['finish_peers_count'] = $this->finish_peers_count;
|
||||
|
||||
Reference in New Issue
Block a user