v7.0.0-beta.2 release
This commit is contained in:
1 parent
6595fd0eb5
commit
fa8eba7a0d
1165 files changed
+107118
-762127
No files matched your search
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Plugins\Sirsoft\Ckeditor5\Http\Controllers;
|
||||
|
||||
use App\Helpers\ResponseHelper;
|
||||
use App\Http\Controllers\Api\Base\PublicBaseController;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Plugins\Sirsoft\Ckeditor5\Services\ImageServeService;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
/**
|
||||
* CKEditor5 이미지 서빙 컨트롤러
|
||||
*
|
||||
* plugins 디스크에 저장된 이미지를 공개 API를 통해 서빙합니다.
|
||||
* 인증 없이 접근 가능한 공개 엔드포인트입니다.
|
||||
*/
|
||||
class ImageServeController extends PublicBaseController
|
||||
{
|
||||
public function __construct(
|
||||
private ImageServeService $imageServeService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 이미지 서빙
|
||||
*
|
||||
* @param string $hash 이미지 해시 (12자)
|
||||
* @return StreamedResponse|JsonResponse 이미지 스트림 또는 에러 응답
|
||||
*/
|
||||
public function serve(string $hash): StreamedResponse|JsonResponse
|
||||
{
|
||||
$image = $this->imageServeService->findByHash($hash);
|
||||
|
||||
if (! $image) {
|
||||
return ResponseHelper::notFound('messages.image.not_found', [], 'sirsoft-ckeditor5');
|
||||
}
|
||||
|
||||
$response = $this->imageServeService->serve($image);
|
||||
|
||||
if (! $response) {
|
||||
return ResponseHelper::notFound('messages.image.not_found', [], 'sirsoft-ckeditor5');
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Plugins\Sirsoft\Ckeditor5\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Api\Base\AdminBaseController;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Plugins\Sirsoft\Ckeditor5\Http\Requests\ImageUploadRequest;
|
||||
use Plugins\Sirsoft\Ckeditor5\Services\ImageUploadService;
|
||||
|
||||
/**
|
||||
* CKEditor5 이미지 업로드 컨트롤러
|
||||
*
|
||||
* CKEditor5 SimpleUploadAdapter가 요구하는 형식으로 이미지를 저장하고
|
||||
* 공개 URL을 반환합니다.
|
||||
*
|
||||
* 응답 형식: { "url": "https://..." }
|
||||
* ResponseHelper 사용 불가 — CKEditor SimpleUploadAdapter는 최상위 { url } 키를 요구합니다.
|
||||
*/
|
||||
class ImageUploadController extends AdminBaseController
|
||||
{
|
||||
public function __construct(
|
||||
private ImageUploadService $imageUploadService
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 이미지를 업로드하고 공개 URL을 반환합니다.
|
||||
*
|
||||
* CKEditor5 SimpleUploadAdapter 규격:
|
||||
* - 성공: HTTP 201, { "url": "..." }
|
||||
* - 실패: HTTP 4xx/5xx, { "error": { "message": "..." } }
|
||||
*
|
||||
* @param ImageUploadRequest $request 업로드 요청
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function upload(ImageUploadRequest $request): JsonResponse
|
||||
{
|
||||
$uploadPermission = $request->query('permission', '');
|
||||
|
||||
$user = $this->getCurrentUser();
|
||||
if ($uploadPermission && $user && ! $user->hasPermission($uploadPermission)) {
|
||||
return response()->json([
|
||||
'error' => ['message' => __('sirsoft-ckeditor5::messages.upload.forbidden')],
|
||||
], 403);
|
||||
}
|
||||
|
||||
try {
|
||||
$image = $this->imageUploadService->upload(
|
||||
$request->file('upload'),
|
||||
$user?->id
|
||||
);
|
||||
|
||||
// CKEditor SimpleUploadAdapter가 요구하는 최상위 { url } 형식
|
||||
return response()->json(['url' => $image->download_url], 201);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('[sirsoft-ckeditor5] 이미지 업로드 실패', [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'error' => ['message' => __('sirsoft-ckeditor5::messages.upload.failed')],
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user