Search
This commit is contained in:
@@ -77,15 +77,9 @@ class ComicController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$params = [];
|
||||
if ($request->has('tag')) {
|
||||
$params['theme'] = $request->get('tag');
|
||||
}
|
||||
|
||||
$comics = $this->copyManga->comics(30, $request->header('offset', 0), $request->get('top', 'all'), $params);
|
||||
|
||||
// Internal function for Upsert comics to db
|
||||
protected function comicsUpsert($comics): void
|
||||
{
|
||||
// Prep the array for upsert
|
||||
$comicsUpsertArray = [];
|
||||
$authorsUpsertArray = [];
|
||||
@@ -98,7 +92,7 @@ class ComicController extends Controller
|
||||
'alias' => '{}',
|
||||
'description' => '',
|
||||
'cover' => $comic['cover'],
|
||||
'upstream_updated_at' => $comic['datetime_updated'],
|
||||
'upstream_updated_at' => $comic['datetime_updated'] ?? null,
|
||||
];
|
||||
|
||||
foreach ($comic['author'] as $author) {
|
||||
@@ -122,6 +116,17 @@ class ComicController extends Controller
|
||||
$comicObj->authors()->sync($authorObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$params = [];
|
||||
if ($request->has('tag')) {
|
||||
$params['theme'] = $request->get('tag');
|
||||
}
|
||||
|
||||
$comics = $this->copyManga->comics(30, $request->header('offset', 0), $request->get('top', 'all'), $params);
|
||||
$this->comicsUpsert($comics);
|
||||
|
||||
return Inertia::render('Comic/Index', [
|
||||
'comics' => $comics,
|
||||
@@ -129,18 +134,57 @@ class ComicController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function author(Request $request, string $author): Response
|
||||
{
|
||||
$params = [];
|
||||
$params['author'] = $author;
|
||||
|
||||
$comics = $this->copyManga->comics(30, $request->header('offset', 0), $request->get('top', 'all'), $params);
|
||||
$this->comicsUpsert($comics);
|
||||
|
||||
return Inertia::render('Comic/Index', [
|
||||
'comics' => $comics,
|
||||
'offset' => $request->header('offset', 0)
|
||||
]);
|
||||
}
|
||||
|
||||
public function search(Request $request, string $search): Response
|
||||
{
|
||||
$comics = $this->copyManga->search($search, 30, $request->header('offset', 0));
|
||||
|
||||
// Seacrh API is limited, no upsert
|
||||
|
||||
return Inertia::render('Comic/Index', [
|
||||
'comics' => $comics,
|
||||
'offset' => $request->header('offset', 0)
|
||||
]);
|
||||
}
|
||||
|
||||
public function chapters(Request $request, string $pathword = ''): Response
|
||||
{
|
||||
$comic = $this->copyManga->comic($pathword);
|
||||
$chapters = $this->copyManga->chapters($pathword, 200, 0, [], $request->get('group', 'default'));
|
||||
|
||||
// Get the comic object and fill other parameters
|
||||
$comicObject = Comic::where('pathword', $pathword)->first();
|
||||
$comicObject->uuid = $comic['comic']['uuid'];
|
||||
$comicObject->alias = explode(',', $comic['comic']['alias']);
|
||||
$comicObject->description = $comic['comic']['brief'];
|
||||
$comicObject->metadata = $comic;
|
||||
$comicObject->save();
|
||||
try {
|
||||
$comicObject = Comic::where('pathword', $pathword)->firstOrFail();
|
||||
$comicObject->uuid = $comic['comic']['uuid'];
|
||||
$comicObject->alias = explode(',', $comic['comic']['alias']);
|
||||
$comicObject->description = $comic['comic']['brief'];
|
||||
$comicObject->metadata = $comic;
|
||||
$comicObject->save();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
$comicObject = Comic::create([
|
||||
'name' => $comic['comic']['name'],
|
||||
'pathword' => $comic['comic']['path_word'],
|
||||
'cover' => $comic['comic']['cover'],
|
||||
'upstream_updated_at' => $comic['comic']['datetime_updated'],
|
||||
'uuid' => $comic['comic']['uuid'],
|
||||
'alias' => explode(',', $comic['comic']['alias']),
|
||||
'description' => $comic['comic']['brief'],
|
||||
'metadata' => $comic
|
||||
]);
|
||||
}
|
||||
|
||||
// Get the authors and update the pathword
|
||||
foreach ($comic['comic']['author'] as $author) {
|
||||
|
||||
Reference in New Issue
Block a user