feat(core,extensions): 구동 에셋 자체 제공 · 자산 실패 폴백 · 운영자 추가 에셋(custom/)

공개 저장소 이슈 gnuboard/g7 (@bigmsg) 제보에서 출발한 작업이다.

브라우저가 화면을 그리려고 제3자 CDN 에 도달해야 하면, 그 도달 실패는 예외도 로그도
남기지 않고 화면 기능만 조용히 사라진다. 폐쇄망·방화벽·광고차단기에서 재현되는데
자체 서버 로그에는 흔적이 없어 운영자가 원인을 특정할 수 없다. 제보된 것은 편집기
하나였지만 같은 구조가 아이콘·글꼴·코드편집기·압축 라이브러리·설치 마법사·개발
대시보드에 똑같이 있었으므로, 번들 확장과 템플릿 전체를 자체 제공으로 옮겼다.
런타임에 외부로 나가는 것은 주소 검색 서비스 하나만 남았다.

자체 제공만으로는 부족하다 — 자기 서버에서 받는 파일도 실패할 수 있고, 종전에는 그
실패가 무음이었다. CSS 경로에 재시도 계층을 세우고(스크립트 경로와 동형), 서버가 HTML
에 직접 심는 externals 까지 실패를 붙잡아 안내 배너와 [다시 시도]로 표면화했다.
편집기·코드편집기는 확보 실패 시 평문 입력으로 내려앉되 저장 계약을 유지한다.

두 번째 축은 운영자가 CSS 를 덧붙일 자리가 없던 문제다(sir.kr 문의). 확장 디렉토리의
custom/ 을 운영자 소유로 정해, 확장 교체가 그 디렉토리만은 보존하게 했다. 출처에
의존하지 않는 서술자로 해석하므로 나중에 다른 출처가 붙어도 소비자는 바뀌지 않는다.
확장 자산과 같은 메커니즘으로 정적 게시되어 CSS 내부 상대 url 도 해석되고, 파일을
고치면 그 변경을 감지해 재게시까지 예약된다.

FTP 접근이 없는 운영자에게는 그 자리도 없는 것과 같으므로 레이아웃 편집기에서 직접
넣고 고칠 수 있게 했다. 모듈·플러그인·템플릿이 한 엔드포인트를 공유한다 — 타입별로
나누면 같은 검증이 세 벌로 갈리고 그중 약한 하나가 우회로가 된다. 여기서 올린
스크립트는 그 레이아웃 한 장이 아니라 사이트 전 화면에서 실행되므로 레이아웃 편집과
분리된 전용 권한으로 연다. 운영자 CSS 가 화면을 조작 불능으로 만들면 그것을 고칠
화면에도 같은 CSS 가 실려 스스로 갇히므로, 서버가 목록을 비우는 탈출구(?custom=off)를
함께 뒀다.

동봉 자산은 재생성 경로에 버전 대조 가드를 붙였다. 선언과 다른 버전을 버전 디렉토리에
써 넣는 조용한 거짓말은 배포된 뒤에는 드러나지 않는다.
This commit is contained in:
HeuJung committed 2026-08-27 16:47:14 +09:00
1 parent 72f2e94c1a
commit 3945b6f1b3
1042 files changed
+107435 -947

No files matched your search

+96 -67
View File
@@ -13,6 +13,7 @@ use App\Enums\ExtensionStatus;
use App\Enums\LayoutSourceType;
use App\Extension\Cache\CoreCacheDriver;
use App\Extension\Helpers\ExtensionBackupHelper;
use App\Extension\Helpers\ExtensionInstallRollbackHelper;
use App\Extension\Helpers\ExtensionPendingHelper;
use App\Extension\Helpers\ExtensionStatusGuard;
use App\Extension\Helpers\GithubHelper;
@@ -425,6 +426,12 @@ class TemplateManager implements TemplateManagerInterface
);
}
// 검증(2단계)은 복사된 활성 디렉토리를 읽어야 해서 복사보다 뒤에 온다. 그래서 검증이
// 실패하면 방금 만든 활성 디렉토리가 고아로 남는다 — DB 행이 없어 목록에도 뜨지 않고
// 오류도 남지 않은 채 디스크만 점유한다. 이번 호출이 만든 것이면 되돌린다.
$rollbackActivePath = $this->templatesPath.DIRECTORY_SEPARATOR.$templateName;
$rollbackDirExisted = File::isDirectory($rollbackActivePath);
// 1. _pending/_bundled에서 활성 디렉토리로 복사 (활성 디렉토리에 없는 경우)
// force=true 시 활성 디렉토리가 있어도 원본으로 덮어씀 (불완전 설치 복구)
$onProgress?->__invoke('copy', '파일 복사 중...');
@@ -435,79 +442,90 @@ class TemplateManager implements TemplateManagerInterface
// 2. 검증
$onProgress?->__invoke('validate', '검증 중...');
return DB::transaction(function () use ($templateName, $onProgress) {
$template = $this->getTemplate($templateName);
if (! $template) {
throw new \Exception(__('templates.errors.not_found', ['template' => $templateName]));
}
try {
return DB::transaction(function () use ($templateName, $onProgress) {
$template = $this->getTemplate($templateName);
if (! $template) {
throw new \Exception(__('templates.errors.not_found', ['template' => $templateName]));
}
// 의존성 확인
$this->checkDependencies($template);
// 의존성 확인
$this->checkDependencies($template);
// SEO 설정 검증 (설치 전 seo-config.json 유효성 검사)
$this->validateSeoConfig($templateName);
// SEO 설정 검증 (설치 전 seo-config.json 유효성 검사)
$this->validateSeoConfig($templateName);
// 레이아웃 검증 (설치 전 모든 레이아웃 파일 유효성 검사)
$this->validateLayouts($templateName);
// 레이아웃 검증 (설치 전 모든 레이아웃 파일 유효성 검사)
$this->validateLayouts($templateName);
// name과 description 다국어 변환 (역호환성)
$name = $this->convertToMultilingual($template['name']);
$description = $this->convertToMultilingual($template['description'] ?? '');
// name과 description 다국어 변환 (역호환성)
$name = $this->convertToMultilingual($template['name']);
$description = $this->convertToMultilingual($template['description'] ?? '');
// 활성 언어팩의 manifest seed(ja 등)를 name/description 다국어 필드에 주입
$manifest = HookManager::applyFilters(
"template.{$templateName}.manifest.translations",
['name' => $name, 'description' => $description]
);
$name = $manifest['name'] ?? $name;
$description = $manifest['description'] ?? $description;
// 활성 언어팩의 manifest seed(ja 등)를 name/description 다국어 필드에 주입
$manifest = HookManager::applyFilters(
"template.{$templateName}.manifest.translations",
['name' => $name, 'description' => $description]
);
$name = $manifest['name'] ?? $name;
$description = $manifest['description'] ?? $description;
// 3. DB 등록
$onProgress?->__invoke('db', 'DB 등록 중...');
// 3. DB 등록
$onProgress?->__invoke('db', 'DB 등록 중...');
// 템플릿 레코드 생성 또는 업데이트
$templateRecord = $this->templateRepository->updateOrCreate(
['identifier' => $templateName],
[
'vendor' => $template['vendor'],
'name' => $name,
'version' => $template['version'],
'type' => $template['type'],
'description' => $description,
'github_url' => $template['github_url'] ?? null,
'metadata' => $template['metadata'] ?? null,
'status' => ExtensionStatus::Inactive->value,
'created_by' => Auth::id(),
'updated_by' => Auth::id(),
]
// 템플릿 레코드 생성 또는 업데이트
$templateRecord = $this->templateRepository->updateOrCreate(
['identifier' => $templateName],
[
'vendor' => $template['vendor'],
'name' => $name,
'version' => $template['version'],
'type' => $template['type'],
'description' => $description,
'github_url' => $template['github_url'] ?? null,
'metadata' => $template['metadata'] ?? null,
'status' => ExtensionStatus::Inactive->value,
'created_by' => Auth::id(),
'updated_by' => Auth::id(),
]
);
// 4. 레이아웃 등록
$onProgress?->__invoke('layout', '레이아웃 등록 중...');
// 레이아웃 JSON 파일 일괄 등록
$this->registerLayouts($templateName, $templateRecord->id);
// 모듈 레이아웃 오버라이드 등록
$this->registerLayoutOverrides($templateName, $templateRecord->id);
// Extension 오버라이드 등록 (모듈/플러그인 Extension 커스터마이징)
$this->registerExtensionOverrides($templateName, $templateRecord->id);
// 에러 레이아웃 검증 (레이아웃 등록 후 수행)
$this->validateErrorLayouts($templateName, $template);
// 템플릿 상태 캐시 무효화
self::invalidateTemplateStatusCache();
// 확장 캐시 버전 증가 (프론트엔드가 새로운 캐시로 요청하도록)
$this->incrementExtensionCacheVersion();
// 훅 발행: 템플릿 설치 완료
HookManager::doAction('core.templates.installed', $templateName);
return true;
});
} catch (\Throwable $e) {
ExtensionInstallRollbackHelper::removeIfCreatedByThisInstall(
$rollbackActivePath,
$rollbackDirExisted,
$templateName,
'template',
);
// 4. 레이아웃 등록
$onProgress?->__invoke('layout', '레이아웃 등록 중...');
// 레이아웃 JSON 파일 일괄 등록
$this->registerLayouts($templateName, $templateRecord->id);
// 모듈 레이아웃 오버라이드 등록
$this->registerLayoutOverrides($templateName, $templateRecord->id);
// Extension 오버라이드 등록 (모듈/플러그인 Extension 커스터마이징)
$this->registerExtensionOverrides($templateName, $templateRecord->id);
// 에러 레이아웃 검증 (레이아웃 등록 후 수행)
$this->validateErrorLayouts($templateName, $template);
// 템플릿 상태 캐시 무효화
self::invalidateTemplateStatusCache();
// 확장 캐시 버전 증가 (프론트엔드가 새로운 캐시로 요청하도록)
$this->incrementExtensionCacheVersion();
// 훅 발행: 템플릿 설치 완료
HookManager::doAction('core.templates.installed', $templateName);
return true;
});
throw $e;
}
}
/**
@@ -731,12 +749,20 @@ class TemplateManager implements TemplateManagerInterface
*
* @param string $templateName 제거할 템플릿명 (identifier)
* @param \Closure|null $onProgress 진행 콜백 (?string $step, string $message)
* @param array<int, array{directory: string, archive: string}>|null $preservedBackups
* 삭제 전에 보관한 운영자 소유 디렉토리(`custom/`)의 사본 경로가 담기는 out 파라미터.
* 운영자에게 "지웠지만 사본은 여기 있다" 를 알리기 위한 것이므로 호출부가 노출해야 한다.
* @return bool 제거 성공 여부
*
* @throws \Exception 템플릿을 찾을 수 없을 때
*/
public function uninstallTemplate(string $templateName, ?\Closure $onProgress = null): bool
{
public function uninstallTemplate(
string $templateName,
?\Closure $onProgress = null,
?array &$preservedBackups = null,
): bool {
$preservedBackups = [];
// 1. 캐시 삭제
$onProgress?->__invoke('cache', '캐시 삭제 중...');
@@ -782,7 +808,10 @@ class TemplateManager implements TemplateManagerInterface
$onProgress?->__invoke('files', '파일 삭제 중...');
// 활성 템플릿 디렉토리 전체 삭제 (_pending/_bundled에 원본 보존되므로 재설치 가능)
ExtensionPendingHelper::deleteExtensionDirectory($this->templatesPath, $templateName);
$preservedBackups = ExtensionPendingHelper::deleteExtensionDirectory(
$this->templatesPath,
$templateName
);
// 메모리에서 템플릿 제거
unset($this->templates[$templateName]);