Просмотр исходного кода

Merge pull request #2396 from visuddhinanda/development

Development
visuddhinanda 17 часов назад
Родитель
Сommit
e853b0f5da

+ 1 - 1
api-v13/app/Http/Api/ChannelApi.php

@@ -8,7 +8,7 @@ use Illuminate\Support\Facades\Log;
 
 class ChannelApi
 {
-    public static function getById($id)
+    public static function getById(?string $id)
     {
         if (!Str::isUuid($id)) {
             return false;

+ 12 - 3
api-v13/app/Http/Controllers/Library/BookController.php

@@ -16,6 +16,8 @@ use App\Services\PaliTextService;
 use App\Services\OpenSearchService;
 
 use App\DTO\Search\HitItemDTO;
+use App\Http\Api\ChannelApi;
+use App\Http\Api\StudioApi;
 
 
 class BookController extends Controller
@@ -99,7 +101,12 @@ class BookController extends Controller
         try {
             $chapter = HitItemDTO::fromArray($this->searchService->get($openSearchId))->toArray();
         } catch (\Throwable $th) {
-            abort(404);
+            $chapter = [
+                'category' => [],
+                'title' => '',
+                'display' => ''
+
+            ];
         }
 
         [$bookId, $paraId] = explode('-', $id);
@@ -118,10 +125,12 @@ class BookController extends Controller
         $book = [];
 
         $book['toc'] = $this->getBookToc((int)$bookId, (int)$paraId, $channelId, 2, 7);
-
+        $channel = ChannelApi::getById($channelId);
+        $studio = StudioApi::getById($channel['studio_id']);
         $book['categories'] = $chapter['category'];
         $book['title']      = $chapter['title'];
-        $book['author']     = 'author'; // FIXME
+        $book['author']     = $channel['name'];
+        $book['studio']     = $studio;
         $book['tags']       = [];
 
         $book['pagination'] = $this->pagination((int)$bookId, (int)$paraId, $channelId);

+ 24 - 4
api-v13/app/Http/Controllers/Library/TipitakaController.php

@@ -8,10 +8,12 @@ use Illuminate\Support\Facades\Cookie;
 use Illuminate\Support\Facades\File;
 use Illuminate\Support\Facades\Log;
 
+
 use App\Models\PaliText;
 use App\Models\ProgressChapter;
 use App\Services\TermService;
-
+use App\Models\Tag;
+use App\Models\TagMap;
 
 
 class TipitakaController extends Controller
@@ -118,7 +120,7 @@ class TipitakaController extends Controller
         $selectedSort   = request('sort',   'new');
 
         $sortList = [
-            ['key' => 'new',         'label' => '最新',],
+            ['key' => 'new',         'label' => __('library.badge_updated'),],
             ['key' => 'progress',    'label' => '完成度',],
         ];
 
@@ -129,7 +131,7 @@ class TipitakaController extends Controller
             'sort'   => $selectedSort,
         ];
         if ($request->has('book')) {
-            $selected['book'] = $request->get('book');
+            $selected['book'] = $request->input('book');
         }
 
         // ── 书籍列表(过滤+排序,真实实现替换此处) ──────────────
@@ -336,7 +338,7 @@ class TipitakaController extends Controller
             if (empty($title)) {
                 $title = $pali->firstWhere('book', $book->book)->toc;
             }
-            //Log::debug('getBooksInfo', ['book' => $book->book, 'paragraph' => $book->para]);
+
             $pcd_book_id = $pali->first(function ($item) use ($book) {
                 return $item->book == $book->book
                     && $item->paragraph == $book->para;
@@ -349,11 +351,13 @@ class TipitakaController extends Controller
                 $coverUrl = null;
             }
             $colorIdx = $this->colorIndex($book->uid);
+            $subTitle = $this->getBookType($book->book, $book->para);
 
             $categoryBooks[] = [
                 "id" => $book->uid,
                 "title" => $title,
                 "author" => $book->channel->name,
+                'subTitle' => $subTitle,
                 "publisher" => $book->channel->owner,
                 'completed_chapters' => $book->completed_chapters,
                 "type" => __('labels.' . $book->channel->type),
@@ -365,6 +369,22 @@ class TipitakaController extends Controller
         });
         return $categoryBooks;
     }
+
+
+    private function getBookType(int $book, int $para)
+    {
+
+        $paliTextUuid = PaliText::where('book', $book)->where('paragraph', $para)->value('uid');
+        $tagIds = TagMap::where('anchor_id', $paliTextUuid)->select('tag_id')->get();
+        $tags = Tag::whereIn('id', $tagIds)->select('name')->get();
+        foreach ($tags as $key => $tag) {
+            if (in_array($tag->name, ['pāḷi', 'aṭṭhakathā', 'ṭīkā'])) {
+                return __('library.' . $tag->name);
+            }
+        }
+
+        return null;
+    }
     private function loadCategories()
     {
         $json = file_get_contents(public_path("data/category/default.json"));

+ 2 - 2
api-v13/app/Http/Controllers/ProgressController.php

@@ -16,7 +16,7 @@ class ProgressController extends Controller
         //
         switch ($request->input('view')) {
             case 'channel':
-                $table = ProgressChapter::whereIn('channel_id', explode('_', $request->get('channels', '')));
+                $table = ProgressChapter::whereIn('channel_id', explode('_', $request->input('channels', '')));
                 break;
             default:
                 return $this->error('invalid view', 400, 400);
@@ -24,7 +24,7 @@ class ProgressController extends Controller
         }
 
         if ($request->has('lang')) {
-            $table = $table->where('lang', $request->get('lang'));
+            $table = $table->where('lang', $request->input('lang'));
         }
         $count = $table->count();
 

+ 3 - 0
api-v13/resources/lang/zh-Hans/library.php

@@ -131,4 +131,7 @@ return [
     'cancel' => '取消',
     'confirm' => '确定',
     'no_toc' => '此书没有目录',
+    'pāḷi' => '巴利原典',
+    'aṭṭhakathā' => '义注',
+    'ṭīkā' => '复注'
 ];

+ 1 - 1
api-v13/resources/views/components/ui/card-book.blade.php

@@ -17,7 +17,7 @@
             :image="$book['cover'] ?? null"
             :gradient="$book['cover_gradient'] ?? 'linear-gradient(135deg, #2d2010 0%, #1a1208 100%)'"
             :title="$book['title'] ?? ''"
-            :subtitle="'义注'"
+            :subtitle="$book['subTitle'] ?? ''"
             size="md"
             :style3d="false" />
 

+ 3 - 3
api-v13/resources/views/library/book/read.blade.php

@@ -163,9 +163,9 @@
                 <p>
                     <strong>{{ __('library.author') }}:</strong>
                     {{ $book['author'] }}
-                    @if(isset($book['publisher']))
-                    @ <a href="{{ route('blog.index', ['user' => $book['publisher']->username]) }}">
-                        {{ $book['publisher']->nickname }}
+                    @if(isset($book['studio']))
+                    @ <a href="{{ route('blog.index', ['user' => $book['studio']['studioName']]) }}">
+                        {{ $book['studio']['nickName'] }}
                     </a>
                     @endif
                 </p>

+ 1 - 1
api-v13/resources/views/library/tipitaka/category.blade.php

@@ -116,7 +116,7 @@
                 </div>
 
                 {{-- 作者 --}}
-                <div class="tipitaka-filter-row">
+                <div class="tipitaka-filter-row" style="display:none">
                     <span class="tipitaka-filter-label">{{ __('library.author') }}</span>
                     <select class="form-select form-select-sm tipitaka-author-select"
                         onchange="window.location=this.value">