|
@@ -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;
|