TipitakaReadingRequest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. /**
  5. * `GET /v3/tipitaka-reading/{channel}` 的入参。
  6. *
  7. * **只有 channel 是必填的,而且它在路径上。** 这里全是可选的过滤与分页参数,
  8. * 所以不带任何查询串就能出结果——那就是「取这个 channel 的全部译文」,
  9. * 下载场景要的正是这个。
  10. *
  11. * `book` 只在跟 `chapter` / `para` 一起用时才必填:那两个是书内的段落号,
  12. * 没有 book 就没有意义。这是唯一一条参数间依赖,不是 v2 那种 `view=` 开关。
  13. */
  14. class TipitakaReadingRequest extends FormRequest
  15. {
  16. /**
  17. * 公开的阅读接口,不需要登录。
  18. */
  19. public function authorize(): bool
  20. {
  21. return true;
  22. }
  23. /**
  24. * @return array<string, array<int, mixed>>
  25. */
  26. public function rules(): array
  27. {
  28. return [
  29. 'book' => ['integer', 'min:1', 'required_with:chapter,para,to'],
  30. // 章节起始段落号;服务端按 pali_texts 的 chapter_len 展开成段落区间
  31. 'chapter' => ['integer', 'min:1', 'prohibits:para,to'],
  32. 'para' => ['integer', 'min:1'],
  33. 'to' => ['integer', 'min:1'],
  34. // 游标,形如 "9002-15"(book-para)。由 meta.next_cursor 给出,
  35. // 客户端原样回传即可,不要自己拼
  36. 'after' => ['string', 'regex:/^\d+-\d+$/'],
  37. 'page_size' => ['integer', 'min:1'],
  38. 'unit' => ['string', 'in:para,byte'],
  39. 'format' => ['string', 'in:html,markdown,react,text'],
  40. 'include' => ['string', 'in:display,sentences,all'],
  41. ];
  42. }
  43. }