mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-15 05:00:49 +08:00
API: upload sections list
This commit is contained in:
18
app/Http/Controllers/SearchBoxController.php
Normal file
18
app/Http/Controllers/SearchBoxController.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\SearchBoxResource;
|
||||
use App\Repositories\SearchBoxRepository;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SearchBoxController extends Controller
|
||||
{
|
||||
private $repository;
|
||||
|
||||
public function __construct(SearchBoxRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\PluginStore;
|
||||
use App\Repositories\ToolRepository;
|
||||
use App\Repositories\UploadRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\Process\Process;
|
||||
@@ -30,7 +31,9 @@ class ToolController extends Controller
|
||||
|
||||
public function test(Request $request)
|
||||
{
|
||||
|
||||
$rep = new UploadRepository();
|
||||
$result = $rep->listSections();
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
29
app/Http/Controllers/UploadController.php
Normal file
29
app/Http/Controllers/UploadController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\SearchBoxResource;
|
||||
use App\Repositories\SearchBoxRepository;
|
||||
use App\Repositories\UploadRepository;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UploadController extends Controller
|
||||
{
|
||||
private $repository;
|
||||
|
||||
private $searchBoxRepository;
|
||||
|
||||
public function __construct(UploadRepository $repository, SearchBoxRepository $searchBoxRepository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->searchBoxRepository = $searchBoxRepository;
|
||||
}
|
||||
|
||||
public function sections(Request $request)
|
||||
{
|
||||
$sections = $this->searchBoxRepository->listSections();
|
||||
$resource = SearchBoxResource::collection($sections);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
}
|
||||
44
app/Http/Resources/SearchBoxResource.php
Normal file
44
app/Http/Resources/SearchBoxResource.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\SearchBox;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SearchBoxResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
/** @var SearchBox $resource */
|
||||
$searchBox = $this->resource;
|
||||
$out = [
|
||||
'id' => $this->id,
|
||||
'name' => $this->displaySectionName,
|
||||
'categories' => CategoryResource::collection($this->whenLoaded('categories')),
|
||||
];
|
||||
$subCategories = [];
|
||||
$lang = get_langfolder_cookie();
|
||||
$fields = array_keys(SearchBox::$taxonomies);
|
||||
if (!empty($searchBox->extra['taxonomy_labels'])) {
|
||||
$fields = array_column($searchBox->extra['taxonomy_labels'], 'torrent_field');
|
||||
}
|
||||
foreach ($fields as $field) {
|
||||
$relationName = "taxonomy_$field";
|
||||
if ($searchBox->relationLoaded($relationName)) {
|
||||
$subCategories[] = [
|
||||
'field' => $field,
|
||||
'label' => $item['display_text'][$lang] ?? (nexus_trans("searchbox.sub_category_{$field}_label") ?: ucfirst($field)),
|
||||
'data' => MediaResource::collection($searchBox->{$relationName}),
|
||||
];
|
||||
}
|
||||
}
|
||||
$out['sub_categories'] = $this->when($this->showsubcat, $subCategories);
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user