ChannelLinkController.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Http\Controllers\V3;
  3. use App\Http\Controllers\Concerns\ResolvesCurrentUser;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\Requests\V3\UpdateChannelLinksRequest;
  6. use App\Http\Resources\V3\ChannelLinksResource;
  7. use App\Models\Channel;
  8. use App\Services\V3\ChannelLinkService;
  9. use Illuminate\Http\Request;
  10. /**
  11. * channel 之间的关系设置:继承自、降级、捆绑的逐词、术语路径(单例资源,每个 channel 一份)。
  12. *
  13. * 新能力,没有对应的 v2 端点。服务端只记录,降级的拼接、术语的取用由客户端做。
  14. */
  15. class ChannelLinkController extends Controller
  16. {
  17. use ResolvesCurrentUser;
  18. public function __construct(private readonly ChannelLinkService $links) {}
  19. /**
  20. * channel 的关系设置
  21. *
  22. * 能读这个 channel 的人都能看。指向的 channel 已删除、或查看者看不见的,不出现在结果里。
  23. * `can_update` 表示查看者能不能改。
  24. *
  25. * @unauthenticated
  26. *
  27. * @urlParam channel string required channel uid
  28. *
  29. * @responseStatus 403 私有 channel,且看不见
  30. */
  31. public function show(Request $request, Channel $channel)
  32. {
  33. return ChannelLinksResource::make($this->links->get($channel, $this->currentUserUid($request)));
  34. }
  35. /**
  36. * 改 channel 的关系设置
  37. *
  38. * 传了哪个键就整体替换哪一种关系,没传的不动;单值传 null 清掉,列表传 [] 清空。
  39. * 能改 channel 信息的人才能改(拥有者、团队 owner / manager / editor、共享权限 ≥30)。AI 模型不能改。
  40. * 目标必须是你看得见的 channel,且不能是自己。降级版本必须与本 channel 同类型;
  41. * 术语路径只有 translation channel 能设,目标也只能是 translation(传 [] 清空总是允许)。
  42. *
  43. * @urlParam channel string required channel uid
  44. *
  45. * @bodyParam derived_from string|null 继承自哪个 channel(如英文版译自中文版),只记录
  46. * @bodyParam wbw string|null 捆绑的逐词 channel,必须是 wbw 类型;载入时当原文
  47. * @bodyParam fallback string[] 降级 channel,有序,最多 3 个,须与本 channel 同类型;段落没有数据时由客户端改取
  48. * @bodyParam fallback.* string channel uid
  49. * @bodyParam term_source string[] 术语路径,有序,最多 10 个,只能是 translation;只有 translation channel 能设
  50. * @bodyParam term_source.* string channel uid
  51. *
  52. * @responseStatus 403 不能修改
  53. */
  54. public function update(UpdateChannelLinksRequest $request, Channel $channel)
  55. {
  56. return ChannelLinksResource::make($this->links->update(
  57. $channel,
  58. $this->currentUser($request)['user_uid'],
  59. $request->validated(),
  60. ));
  61. }
  62. }