ChannelTermImportController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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\ImportTermsRequest;
  6. use App\Http\Resources\V3\TermImportResource;
  7. use App\Models\Channel;
  8. use App\Services\V3\TermExchangeService;
  9. /**
  10. * 向 channel 导入术语(xlsx)。
  11. *
  12. * 取代 `GET /v2/terms-import?view=channel`(`TermExportController@import`)。v2 原样保留。
  13. */
  14. class ChannelTermImportController extends Controller
  15. {
  16. use ResolvesCurrentUser;
  17. public function __construct(private readonly TermExchangeService $exchange) {}
  18. /**
  19. * 向 channel 导入术语
  20. *
  21. * 上传 xlsx(第一行是列名,至少有 word、meaning;可以直接用导出的表格)。所有行都落在这个 channel,
  22. * 语言跟随 channel。有 id 的行改那一条(word / tag 不能改;带 etag 列时与当前不一致就跳过),
  23. * 没有 id 的按 word + tag 找,有就改、没有就建。**部分成功**:出错的行跳过,`errors` 逐行给出原因。
  24. * 能写这个 channel 的人(含团队 editor)才能导入;AI 模型不能导入。最多 5000 行。
  25. *
  26. * @urlParam channel string required channel uid
  27. *
  28. * @bodyParam file file required xlsx 表格,不超过 5MB
  29. *
  30. * @responseStatus 403 不能写这个 channel
  31. */
  32. public function __invoke(ImportTermsRequest $request, Channel $channel)
  33. {
  34. return TermImportResource::make($this->exchange->importToChannel(
  35. $channel,
  36. $this->currentUser($request)['user_uid'],
  37. $request->file('file'),
  38. ));
  39. }
  40. }