You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.2KB

  1. <?php
  2. namespace App\Http\Controllers\Web\Image;
  3. use App\Exceptions\AppCommonException;
  4. use App\Http\Controllers\Web\WebController;
  5. use App\Kintone\KintoneAccess;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Http\Response;
  8. abstract class ImageController extends WebController
  9. {
  10. public function name(): string
  11. {
  12. return "画像取得";
  13. }
  14. public function description(): string
  15. {
  16. return "KINTONEから画像を取得する";
  17. }
  18. public function __construct(protected ImageParam $param)
  19. {
  20. parent::__construct();
  21. $this->middleware('auth:sanctum');
  22. }
  23. protected function run(Request $request): Response
  24. {
  25. try {
  26. $id = $request->route('id');
  27. if (!$id) {
  28. throw new AppCommonException("パラメータ不正");
  29. }
  30. $access = $this->getAccess();
  31. $file = $access->fileGet($id);
  32. return response($file->body(), 200, [
  33. 'Content-Length' => $file->header('Content-Length'),
  34. 'Content-Type' => $file->header('Content-Type'),
  35. ]);
  36. } catch (Exception $e) {
  37. return response();
  38. }
  39. }
  40. abstract protected function getAccess(): KintoneAccess;
  41. }