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

fix(api): 相似句空 channels 500 且编辑模式只显示整体意思

- SentSimResource 过滤空值/非 uuid channel,避免空 channels 参数导致 500
- CorpusController::pushSent 将 mode 写入句子 props,相似句编辑模式只显示逐词解析的 meaning
visuddhinanda 2 дней назад
Родитель
Сommit
2423824a20

+ 1 - 0
api-v13/app/Http/Controllers/CorpusController.php

@@ -985,6 +985,7 @@ class CorpusController extends Controller
      */
      */
     private function pushSent($result, $sent, $level = 0, $mode = 'read')
     private function pushSent($result, $sent, $level = 0, $mode = 'read')
     {
     {
+        $sent['mode'] = $mode;
 
 
         $sentProps = base64_encode(\json_encode($sent));
         $sentProps = base64_encode(\json_encode($sent));
         if ($mode === 'read') {
         if ($mode === 'read') {

+ 14 - 3
api-v13/app/Http/Resources/SentSimResource.php

@@ -7,6 +7,7 @@ use App\Models\PaliSentence;
 use Illuminate\Contracts\Support\Arrayable;
 use Illuminate\Contracts\Support\Arrayable;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
 use Illuminate\Http\Resources\Json\JsonResource;
 use Illuminate\Http\Resources\Json\JsonResource;
+use Illuminate\Support\Str;
 
 
 class SentSimResource extends JsonResource
 class SentSimResource extends JsonResource
 {
 {
@@ -20,12 +21,22 @@ class SentSimResource extends JsonResource
     {
     {
         // 获取实际句子信息
         // 获取实际句子信息
         $sent = PaliSentence::find($this->sent2);
         $sent = PaliSentence::find($this->sent2);
-        $channels = explode(',', $request->input('channels'));
+        if (! $sent) {
+            return [];
+        }
+
+        // 过滤掉空值或非 uuid 的 channel,避免空 channels 参数导致 500
+        $channels = [];
+        foreach (explode(',', (string) $request->input('channels', '')) as $channel) {
+            if (Str::isUuid($channel)) {
+                $channels[] = $channel;
+            }
+        }
+
         $mode = $request->input('mode', 'read');
         $mode = $request->input('mode', 'read');
         $sentId = $sent->book.'-'.$sent->paragraph.'-'.$sent->word_begin.'-'.$sent->word_end;
         $sentId = $sent->book.'-'.$sent->paragraph.'-'.$sent->word_begin.'-'.$sent->word_end;
         $Sent = new CorpusController;
         $Sent = new CorpusController;
-        $tpl =
-            $data['sent'] = $Sent->getSentTpl($sentId, $channels, $mode);
+        $data['sent'] = $Sent->getSentTpl($sentId, $channels, $mode);
         $data['sim'] = $this->sim;
         $data['sim'] = $this->sim;
 
 
         return $data;
         return $data;