0.1.2
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Helper\ZhConversion;
|
||||
use App\Jobs\ImageUpsert;
|
||||
use App\Jobs\RemotePrefetch;
|
||||
use App\Models\Author;
|
||||
use App\Models\Chapter;
|
||||
use App\Models\Comic;
|
||||
use App\Models\Image;
|
||||
use App\Remote\CopyManga;
|
||||
use App\Remote\ImageFetcher;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
@@ -22,13 +23,26 @@ use Illuminate\Support\Facades\Cache;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
/**
|
||||
* Comic Controller
|
||||
*/
|
||||
class ComicController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @param CopyManga $copyManga
|
||||
* @param ZhConversion $zhConversion
|
||||
*/
|
||||
public function __construct(private readonly CopyManga $copyManga, private readonly ZhConversion $zhConversion)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert SC to ZH
|
||||
*
|
||||
* @param mixed $string
|
||||
* @return mixed
|
||||
*/
|
||||
protected function scToZh(mixed $string): mixed
|
||||
{
|
||||
if (gettype($string) !== 'string') {
|
||||
@@ -323,24 +337,8 @@ class ComicController extends Controller
|
||||
$chapterObj = Chapter::where('chapter_uuid', $chapter['chapter']['uuid'])->first();
|
||||
$comicObj = Comic::where('pathword', $pathword)->first();
|
||||
|
||||
$arrayForUpsert = [];
|
||||
|
||||
foreach ($chapter['sorted'] as $k => $image) {
|
||||
$metadata = $chapter;
|
||||
unset($metadata['sorted']);
|
||||
unset($metadata['chapter']['contents'], $metadata['chapter']['words']);
|
||||
|
||||
$arrayForUpsert[] = [
|
||||
'comic_id' => $comicObj->id,
|
||||
'chapter_id' => $chapterObj->id,
|
||||
'order' => $k,
|
||||
'url' => $image['url'],
|
||||
'metadata' => json_encode($metadata),
|
||||
];
|
||||
}
|
||||
|
||||
// Do an upsert
|
||||
Image::upsert($arrayForUpsert, uniqueBy: 'url');
|
||||
// Image Upsert
|
||||
ImageUpsert::dispatch($comicObj->id, $chapterObj->id, $chapter);
|
||||
|
||||
// Update history
|
||||
$request->user()->readingHistories()->attach($chapterObj->id, ['comic_id' => $comicObj->id]);
|
||||
@@ -348,6 +346,15 @@ class ComicController extends Controller
|
||||
// Get chapters from DB
|
||||
$chapters = $comicObj->chapters()->where('metadata->group_path_word', $chapter['chapter']['group_path_word'])->orderBy('order')->get(['name', 'chapter_uuid']);
|
||||
|
||||
// Do remote prefetch if needed
|
||||
if ($chapter['chapter']['next'] !== null) {
|
||||
try {
|
||||
Chapter::where('chapter_uuid', $chapter['chapter']['next'])->firstOrFail()->images()->firstOrFail();
|
||||
} catch (ModelNotFoundException $e) {
|
||||
RemotePrefetch::dispatch('chapter', ['pathword' => $pathword, 'uuid' => $chapter['chapter']['next']]);
|
||||
}
|
||||
}
|
||||
|
||||
return Inertia::render('Comic/Read', [
|
||||
'comic' => $this->scToZh($comic),
|
||||
'chapter' => $this->scToZh($chapter),
|
||||
|
||||
Reference in New Issue
Block a user