v7.0.0 release
This commit is contained in:
1 parent
0e7fa04b03
commit
c4ea9a6cd1
3582 files changed
+626189
-160151
No files matched your search
@@ -59,14 +59,45 @@ class PublicLayoutController extends PublicBaseController
|
||||
}
|
||||
|
||||
try {
|
||||
// 캐시 버전을 키에 포함하여 모듈/플러그인 변경 시 캐시 무효화
|
||||
$cacheVersion = request()->query('v', 0);
|
||||
// 캐시 버전을 키에 포함하여 모듈/플러그인 변경 시 캐시 무효화.
|
||||
//
|
||||
// 서버 캐시 키에는 **정수 버전만** 쓴다(소수 nonce 제거). 레이아웃 편집기는 같은 세션의
|
||||
// 저장·버전 복원 직후 브라우저 HTTP 캐시를 우회하려고 `?v={cacheVersion}.{nonce}` 형식으로
|
||||
// 요청한다(클라이언트 cache-bust nonce). 그런데 `serve` 가 이 문자열을 그대로 캐시 키에
|
||||
// 쓰면 키가 `...v{cacheVersion}.{nonce}.meta` 가 되는데, 저장 경로
|
||||
// `LayoutService::clearPublicServingCache` 는 `(int) ext.cache_version` 으로 nonce 없는
|
||||
// 키만 forget 하므로 키 형식이 어긋나 무효화가 빗나간다(저장/복원 후 편집기 캔버스만
|
||||
// stale). nonce 는 브라우저 HTTP 캐시 우회용(URL·ETag 차이로 이미 달성)이고, 서버 캐시 키
|
||||
// 정합은 정수 버전이 SSoT 다. `(int)` 캐스팅은 PHP 가 소수점에서 절단해 정수부만 남긴다.
|
||||
$cacheVersion = (int) request()->query('v', 0);
|
||||
|
||||
// 서버 측 캐싱 (1시간 유효)
|
||||
// 편집기 출처 메타 옵션
|
||||
// - 옵션이 truthy 면 각 노드에 `__source` 메타를 부여한 응답을 반환
|
||||
// - 일반 사이트 렌더는 옵션을 전달하지 않으므로 응답 형식 종전과 100% 동일
|
||||
$withSourceMeta = (bool) request()->query('with_source_meta', false);
|
||||
|
||||
// 출처 메타 요청은 편집 권한 필요 — 일반 사용자가 메타를 보면 안 됨
|
||||
// @since engine-v1.50.0
|
||||
if ($withSourceMeta) {
|
||||
$user = request()->user();
|
||||
if ($user === null) {
|
||||
return $this->unauthorized('auth.layout_guest_permission_denied', [
|
||||
'required_permissions' => 'core.templates.layouts.edit',
|
||||
]);
|
||||
}
|
||||
if (! PermissionHelper::check('core.templates.layouts.edit', $user)) {
|
||||
return $this->forbidden('auth.layout_permission_denied', [
|
||||
'required_permissions' => 'core.templates.layouts.edit',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 서버 측 캐싱 (1시간 유효) — 메타 포함/미포함은 별도 캐시 키
|
||||
// getLayout()을 사용하여 레이아웃 로드, 병합, 확장 적용을 한 번에 수행
|
||||
$metaSuffix = $withSourceMeta ? '.meta' : '';
|
||||
$mergedLayout = $this->cached(
|
||||
"layout.{$templateIdentifier}.{$layoutName}.v{$cacheVersion}",
|
||||
fn () => $this->layoutService->getLayout($templateIdentifier, $layoutName),
|
||||
"layout.{$templateIdentifier}.{$layoutName}.v{$cacheVersion}{$metaSuffix}",
|
||||
fn () => $this->layoutService->getLayout($templateIdentifier, $layoutName, $withSourceMeta),
|
||||
self::CACHE_TTL
|
||||
);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class PublicModuleController extends PublicBaseController
|
||||
* @param ServeModuleAssetRequest $request 검증된 요청 (경로, 확장자 검증 완료)
|
||||
* @param string $identifier 모듈 식별자 (vendor-module 형식)
|
||||
* @param string $path 에셋 경로 (dist/js/module.iife.js 등)
|
||||
* @return BinaryFileResponse|JsonResponse|Response
|
||||
* @return BinaryFileResponse|JsonResponse|Response 파일 응답 또는 에러 응답
|
||||
*/
|
||||
public function serveAsset(
|
||||
ServeModuleAssetRequest $request,
|
||||
@@ -55,4 +55,57 @@ class PublicModuleController extends PublicBaseController
|
||||
// 파일 반환 (ETag 및 환경별 캐싱 헤더 포함, 1년 캐시)
|
||||
return $this->fileResponse($result['filePath'], $result['mimeType'], 31536000);
|
||||
}
|
||||
|
||||
/**
|
||||
* 모듈 편집기 스펙 조회 — editor-spec.json 반환
|
||||
*
|
||||
* 활성 모듈만 대상으로 하며, 활성 디렉토리 → _bundled 폴백 순으로 읽어
|
||||
* 템플릿 serveEditorSpec 과 동일한 응답 형태(`data.spec`)로 반환한다.
|
||||
* 비활성/미존재 모듈은 404. 파일 미작성은 spec=null 정상 응답.
|
||||
*
|
||||
* @param string $identifier 모듈 식별자 (vendor-module 형식)
|
||||
* @return JsonResponse 편집기 스펙 응답
|
||||
*/
|
||||
public function serveEditorSpec(string $identifier): JsonResponse
|
||||
{
|
||||
$this->logApiUsage('modules.editor_spec', ['identifier' => $identifier]);
|
||||
|
||||
$result = $this->moduleService->getEditorSpec($identifier);
|
||||
|
||||
if (! $result['success']) {
|
||||
return $this->notFound(__('modules.errors.not_found', ['module' => $identifier]));
|
||||
}
|
||||
|
||||
$message = $result['spec'] === null
|
||||
? __('templates.messages.editor_spec_empty')
|
||||
: __('templates.messages.editor_spec_retrieved');
|
||||
|
||||
return $this->success($message, [
|
||||
'identifier' => $identifier,
|
||||
'spec' => $result['spec'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 모듈 컴포넌트 정의 파일 서빙 — components.json 반환
|
||||
*
|
||||
* 편집 모드 부팅 시 ComponentRegistry 가 활성 확장 매니페스트를 네임스페이스
|
||||
* 병합하기 위해 fetch 한다. 미생성(구버전 모듈) 시 빈 components 로
|
||||
* 폴백한다(무손실 보존 디그레이드).
|
||||
*
|
||||
* @param string $identifier 모듈 식별자
|
||||
* @return JsonResponse 컴포넌트 정의 응답
|
||||
*/
|
||||
public function serveComponents(string $identifier): JsonResponse
|
||||
{
|
||||
$this->logApiUsage('modules.components', ['identifier' => $identifier]);
|
||||
|
||||
$result = $this->moduleService->getComponents($identifier);
|
||||
|
||||
if (! $result['success']) {
|
||||
return $this->notFound(__('modules.errors.not_found', ['module' => $identifier]));
|
||||
}
|
||||
|
||||
return $this->cachedJsonResponse($result['components'] ?? new \stdClass, 3600);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ class PublicPluginController extends PublicBaseController
|
||||
* @param ServePluginAssetRequest $request 검증된 요청 (경로, 확장자 검증 완료)
|
||||
* @param string $identifier 플러그인 식별자 (vendor-plugin 형식)
|
||||
* @param string $path 에셋 경로 (dist/js/plugin.iife.js 등)
|
||||
* @return BinaryFileResponse|JsonResponse|Response
|
||||
* @return BinaryFileResponse|JsonResponse|Response 파일 응답 또는 에러 응답
|
||||
*/
|
||||
public function serveAsset(
|
||||
ServePluginAssetRequest $request,
|
||||
@@ -55,4 +55,57 @@ class PublicPluginController extends PublicBaseController
|
||||
// 파일 반환 (ETag 및 환경별 캐싱 헤더 포함, 1년 캐시)
|
||||
return $this->fileResponse($result['filePath'], $result['mimeType'], 31536000);
|
||||
}
|
||||
|
||||
/**
|
||||
* 플러그인 편집기 스펙 조회 — editor-spec.json 반환
|
||||
*
|
||||
* 활성 플러그인만 대상으로 하며, 활성 디렉토리 → _bundled 폴백 순으로 읽어
|
||||
* 템플릿 serveEditorSpec 과 동일한 응답 형태(`data.spec`)로 반환한다.
|
||||
* 비활성/미존재 플러그인은 404. 파일 미작성은 spec=null 정상 응답.
|
||||
*
|
||||
* @param string $identifier 플러그인 식별자 (vendor-plugin 형식)
|
||||
* @return JsonResponse 편집기 스펙 응답
|
||||
*/
|
||||
public function serveEditorSpec(string $identifier): JsonResponse
|
||||
{
|
||||
$this->logApiUsage('plugins.editor_spec', ['identifier' => $identifier]);
|
||||
|
||||
$result = $this->pluginService->getEditorSpec($identifier);
|
||||
|
||||
if (! $result['success']) {
|
||||
return $this->notFound(__('plugins.errors.not_found', ['plugin' => $identifier]));
|
||||
}
|
||||
|
||||
$message = $result['spec'] === null
|
||||
? __('templates.messages.editor_spec_empty')
|
||||
: __('templates.messages.editor_spec_retrieved');
|
||||
|
||||
return $this->success($message, [
|
||||
'identifier' => $identifier,
|
||||
'spec' => $result['spec'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 플러그인 컴포넌트 정의 파일 서빙 — components.json 반환
|
||||
*
|
||||
* 편집 모드 부팅 시 ComponentRegistry 가 활성 확장 매니페스트를 네임스페이스
|
||||
* 병합하기 위해 fetch 한다. 미생성(구버전 플러그인) 시 빈 components 로
|
||||
* 폴백한다(무손실 보존 디그레이드).
|
||||
*
|
||||
* @param string $identifier 플러그인 식별자
|
||||
* @return JsonResponse 컴포넌트 정의 응답
|
||||
*/
|
||||
public function serveComponents(string $identifier): JsonResponse
|
||||
{
|
||||
$this->logApiUsage('plugins.components', ['identifier' => $identifier]);
|
||||
|
||||
$result = $this->pluginService->getComponents($identifier);
|
||||
|
||||
if (! $result['success']) {
|
||||
return $this->notFound(__('plugins.errors.not_found', ['plugin' => $identifier]));
|
||||
}
|
||||
|
||||
return $this->cachedJsonResponse($result['components'] ?? new \stdClass, 3600);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,12 @@
|
||||
namespace App\Http\Controllers\Api\Public;
|
||||
|
||||
use App\Enums\ExtensionStatus;
|
||||
use App\Extension\Helpers\EditorSpecAssembler;
|
||||
use App\Extension\Traits\ClearsTemplateCaches;
|
||||
use App\Http\Controllers\Api\Base\PublicBaseController;
|
||||
use App\Http\Requests\Public\Template\ServeTemplateAssetRequest;
|
||||
use App\Models\TemplateLayoutAttachment;
|
||||
use App\Services\TemplateLayoutAttachmentService;
|
||||
use App\Services\TemplateService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Response;
|
||||
@@ -17,7 +20,8 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
class PublicTemplateController extends PublicBaseController
|
||||
{
|
||||
public function __construct(
|
||||
private TemplateService $templateService
|
||||
private TemplateService $templateService,
|
||||
private TemplateLayoutAttachmentService $layoutAttachmentService,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -26,6 +30,7 @@ class PublicTemplateController extends PublicBaseController
|
||||
* 템플릿 라우트 정보 조회 (활성화된 모듈의 routes 포함)
|
||||
*
|
||||
* @param string $identifier 템플릿 식별자 (vendor-name 형식)
|
||||
* @return JsonResponse 라우트 정보 응답
|
||||
*/
|
||||
public function getRoutes(string $identifier): JsonResponse
|
||||
{
|
||||
@@ -82,6 +87,11 @@ class PublicTemplateController extends PublicBaseController
|
||||
|
||||
/**
|
||||
* 템플릿 정적 파일 서빙
|
||||
*
|
||||
* @param ServeTemplateAssetRequest $request 요청 (FormRequest 검증)
|
||||
* @param string $identifier 템플릿 식별자
|
||||
* @param string $path 요청 경로
|
||||
* @return BinaryFileResponse|JsonResponse|Response 파일 응답 또는 에러
|
||||
*/
|
||||
public function serveAsset(ServeTemplateAssetRequest $request, string $identifier, string $path): BinaryFileResponse|JsonResponse|Response
|
||||
{
|
||||
@@ -110,6 +120,7 @@ class PublicTemplateController extends PublicBaseController
|
||||
* 컴포넌트 정의 파일 서빙
|
||||
*
|
||||
* @param string $identifier 템플릿 식별자
|
||||
* @return JsonResponse 컴포넌트 정의 응답
|
||||
*/
|
||||
public function serveComponents(string $identifier): JsonResponse
|
||||
{
|
||||
@@ -140,6 +151,7 @@ class PublicTemplateController extends PublicBaseController
|
||||
* error_config 등 템플릿 메타데이터를 프론트엔드에 제공합니다.
|
||||
*
|
||||
* @param string $identifier 템플릿 식별자
|
||||
* @return JsonResponse 템플릿 설정 응답
|
||||
*/
|
||||
public function serveConfig(string $identifier): JsonResponse
|
||||
{
|
||||
@@ -207,6 +219,7 @@ class PublicTemplateController extends PublicBaseController
|
||||
*
|
||||
* @param string $identifier 템플릿 식별자
|
||||
* @param string $locale 로케일 (ko, en 등)
|
||||
* @return JsonResponse 다국어 데이터 응답
|
||||
*/
|
||||
public function serveLanguage(string $identifier, string $locale): JsonResponse
|
||||
{
|
||||
@@ -262,4 +275,68 @@ class PublicTemplateController extends PublicBaseController
|
||||
// 성공 응답 (JSON 데이터 직접 반환, 래핑 없음)
|
||||
return $this->cachedJsonResponse($languageData['data'], 3600);
|
||||
}
|
||||
|
||||
/**
|
||||
* 편집기 스펙 조회 — 템플릿 editor-spec.json 파일 반환
|
||||
*
|
||||
* Phase 3 S5a-1 에서 `nesting` 블록이 추가되었다. 본 엔드포인트는
|
||||
* 활성 디렉토리 → _bundled 폴백 순으로 editor-spec.json 을 읽어 반환한다.
|
||||
* 파일 미존재 시 spec=null 로 폴백 (편집기는 spec 미제공 안내).
|
||||
*
|
||||
* @param string $identifier 템플릿 식별자
|
||||
* @return JsonResponse 편집기 스펙 응답
|
||||
*/
|
||||
public function serveEditorSpec(string $identifier): JsonResponse
|
||||
{
|
||||
$this->logApiUsage('templates.editor_spec', ['identifier' => $identifier]);
|
||||
|
||||
// 분할 editor-spec.json 은 manifest + `$include` 블록으로 구성된다.
|
||||
// 활성 디렉토리만 기준으로 합본한 단일 spec 을 반환한다(_bundled 폴백 없음).
|
||||
// 합본 결과는 분할 전 단일 파일과 동일 형태(프론트엔드 로더 무영향).
|
||||
// 미분할 파일은 원본 반환(하위 호환), 미존재 시 null.
|
||||
$spec = EditorSpecAssembler::assemble(
|
||||
base_path("templates/{$identifier}/editor-spec.json")
|
||||
);
|
||||
|
||||
$message = $spec === null
|
||||
? __('templates.messages.editor_spec_empty')
|
||||
: __('templates.messages.editor_spec_retrieved');
|
||||
|
||||
return $this->success(
|
||||
$message,
|
||||
[
|
||||
'identifier' => $identifier,
|
||||
'spec' => $spec,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 레이아웃 첨부 이미지 파일 서빙.
|
||||
*
|
||||
* 발행된 배경 이미지는 일반 사이트 방문자에게도 로드되어야 하므로 인증 불필요한
|
||||
* 공개 엔드포인트로 둔다. 첨부는 비공개 `attachments` 디스크에 저장되므로 직접
|
||||
* 공개 URL 이 없어, 본 라우트가 파일을 캐싱 헤더와 함께 인라인 스트림한다.
|
||||
* 첨부가 경로의 템플릿 소속이 아니거나 파일이 없으면 404.
|
||||
*
|
||||
* @param string $identifier 템플릿 식별자
|
||||
* @param TemplateLayoutAttachment $attachment 라우트 모델 바인딩된 첨부
|
||||
* @return BinaryFileResponse|Response|JsonResponse 파일 응답 또는 404
|
||||
*/
|
||||
public function serveFile(string $identifier, TemplateLayoutAttachment $attachment): BinaryFileResponse|Response|JsonResponse
|
||||
{
|
||||
$filePath = $this->layoutAttachmentService->getServableFilePath($identifier, $attachment);
|
||||
|
||||
if ($filePath === null) {
|
||||
return $this->notFound('templates.layout_attachments.errors.not_found');
|
||||
}
|
||||
|
||||
// 이미지/일반 파일 모두 캐싱 헤더와 함께 인라인 응답 (레이아웃 캐시 TTL, 기본 24시간).
|
||||
// PublicAttachmentController 의 이미지 서빙과 동일한 fileResponse(ETag/Cache-Control) 사용.
|
||||
return $this->fileResponse(
|
||||
$filePath,
|
||||
$attachment->mime_type,
|
||||
(int) g7_core_settings('cache.layout_ttl', 86400)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user