fix(core,admin_basic): S3 스토리지 드라이버 실동작 결함 수정 및 S3 호환 스토리지 연결 지원
공개 제보 — 파일 스토리지에서 S3 를 선택해 저장해도 실제 파일 저장이 동작하지 않던 결함의 전면 수정. - S3 어댑터(league/flysystem-aws-s3-v3)·predis 를 코어 기본 의존성으로 포함 — 어댑터 부재 즉사, phpredis 확장 없는 서버의 redis 선택 전면 다운 차단 (부트 시 확장 부재 감지 → predis 자동 폴백) - storage_driver=s3 저장 시 코어 첨부 업로드 디스크를 s3 로 전환 (ATTACHMENT_DISK env 명시가 항상 우선, 기존 행은 저장 당시 disk 로 서빙) - 첨부·템플릿 레이아웃 첨부 서빙을 행 disk 를 따르는 스토리지 스트림으로 교체 — 로컬 절대 경로 전제 fileResponse 는 S3 행에서 filemtime stat 500 (streamedFileResponse: 행 메타 기반 ETag/304/Cache-Control) - S3 호환 스토리지(R2/MinIO/NCP) 연결 지원: 엔드포인트 URL·path-style 설정 신설, 리전 목록 선택 → 자유 입력 전환, 연결 테스트를 실제 저장 경로와 동일 설정(endpoint/path-style)으로 정렬 - 사용 불능 드라이버(어댑터·PHP 확장 부재)의 저장/테스트 요청을 사유와 함께 422 로 차단하는 서버 게이트 신설 (DriverRegistryService 능력 판정) - 웹소켓 연결 테스트에 서버(백엔드 발송용) endpoint 검사 추가 — 클라이언트만 검사해 테스트 성공 + 실제 발송 실패가 가능하던 비대칭 해소 - env 빈 값(`KEY=`) 함정 정규화: AWS_URL/AWS_ENDPOINT/ATTACHMENT_DISK 빈 문자열을 미설정으로 취급 (config 정규화 + 예시 파일 주석 처리) - 플러그인 드라이버 폴백의 log 카테고리 죽은 키(logging.default) 정정 및 websocket 유령 설정 키 제거 - 실 AWS S3 종단 검증 완료 (설정 저장 → 업로드 S3 실저장 → 서빙 200/304)
This commit is contained in:
1 parent
c128a6ea3a
commit
ea58c606a2
56 files changed
+2899
-243
No files matched your search
@@ -9,6 +9,7 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
/**
|
||||
* API 컨트롤러의 최상위 베이스 클래스
|
||||
@@ -174,6 +175,40 @@ abstract class BaseApiController extends Controller
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 스토리지 스트림 응답에 ETag/캐싱 헤더를 부착합니다 (fileResponse 의 디스크 인지 대응).
|
||||
*
|
||||
* fileResponse() 는 로컬 절대 경로 전제(filemtime/filesize)라 S3 등 원격 디스크
|
||||
* 행에는 쓸 수 없습니다. 원격/로컬 공통 서빙은 StorageInterface::response() 가
|
||||
* 만든 스트림에 본 메서드로 동일한 캐싱 계약(ETag/304/Cache-Control/Expires)을
|
||||
* 입힙니다. ETag 는 파일 stat 대신 호출자가 준 결정적 소스(행 메타)로 만듭니다.
|
||||
*
|
||||
* @param StreamedResponse $response 스토리지 인라인 스트림 응답
|
||||
* @param string $etagSource ETag 소스 문자열 (디스크·경로·수정시각·크기 등 행 메타)
|
||||
* @param int $maxAge 캐시 유지 시간 (초)
|
||||
* @return StreamedResponse|Response 스트림 응답 또는 304
|
||||
*/
|
||||
protected function streamedFileResponse(StreamedResponse $response, string $etagSource, int $maxAge): StreamedResponse|Response
|
||||
{
|
||||
$etag = md5($etagSource);
|
||||
|
||||
// If-None-Match 헤더 확인 (ETag 비교)
|
||||
if (request()->header('If-None-Match') === $etag) {
|
||||
return response('', 304)->header('ETag', $etag);
|
||||
}
|
||||
|
||||
// 환경별 캐싱 정책 (fileResponse 와 동일)
|
||||
$cacheControl = app()->environment('production')
|
||||
? "public, max-age={$maxAge}, immutable"
|
||||
: 'no-cache';
|
||||
|
||||
$response->headers->set('ETag', $etag);
|
||||
$response->headers->set('Expires', gmdate('D, d M Y H:i:s', time() + $maxAge).' GMT');
|
||||
$response->headers->set('Cache-Control', $cacheControl);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON 응답을 반환합니다 (캐싱 헤더 포함).
|
||||
*
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
namespace App\Http\Controllers\Api\Public;
|
||||
|
||||
use App\Http\Controllers\Api\Base\PublicBaseController;
|
||||
use App\Http\Requests\Public\Attachment\DownloadAttachmentRequest;
|
||||
use App\Services\AttachmentService;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
@@ -22,7 +22,7 @@ class PublicAttachmentController extends PublicBaseController
|
||||
/**
|
||||
* PublicAttachmentController 생성자
|
||||
*
|
||||
* @param AttachmentService $attachmentService 첨부파일 서비스
|
||||
* @param AttachmentService $attachmentService 첨부파일 서비스
|
||||
*/
|
||||
public function __construct(
|
||||
private AttachmentService $attachmentService
|
||||
@@ -36,11 +36,11 @@ class PublicAttachmentController extends PublicBaseController
|
||||
* 이미지 파일은 캐싱 헤더와 함께 인라인 표시하고,
|
||||
* 그 외 파일은 다운로드 방식으로 제공합니다.
|
||||
*
|
||||
* @param Request $request HTTP 요청
|
||||
* @param string $hash 첨부파일 해시 (12자)
|
||||
* @param DownloadAttachmentRequest $request 다운로드 요청
|
||||
* @param string $hash 첨부파일 해시 (12자)
|
||||
* @return BinaryFileResponse|StreamedResponse|Response|JsonResponse 파일 응답 또는 에러 응답
|
||||
*/
|
||||
public function download(Request $request, string $hash): BinaryFileResponse|StreamedResponse|Response|JsonResponse
|
||||
public function download(DownloadAttachmentRequest $request, string $hash): BinaryFileResponse|StreamedResponse|Response|JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
@@ -48,10 +48,10 @@ class PublicAttachmentController extends PublicBaseController
|
||||
// 파일 정보 조회 (권한 체크 포함)
|
||||
$fileInfo = $this->attachmentService->getFileInfo($hash, $user);
|
||||
|
||||
if (!$fileInfo) {
|
||||
if (! $fileInfo) {
|
||||
$attachment = $this->attachmentService->findByHash($hash);
|
||||
|
||||
if (!$attachment) {
|
||||
if (! $attachment) {
|
||||
return $this->notFound('attachment.not_found');
|
||||
}
|
||||
|
||||
@@ -59,10 +59,11 @@ class PublicAttachmentController extends PublicBaseController
|
||||
}
|
||||
|
||||
// 이미지 파일은 캐싱 헤더와 함께 응답 (환경설정 레이아웃 캐시 TTL 사용, 기본 24시간)
|
||||
// 행 disk 를 따르는 스토리지 스트림 — 로컬 경로 전제 fileResponse 는 S3 행에서 성립하지 않는다 (#99)
|
||||
if (str_starts_with($fileInfo['mime_type'], 'image/')) {
|
||||
return $this->fileResponse(
|
||||
$fileInfo['path'],
|
||||
$fileInfo['mime_type'],
|
||||
return $this->streamedFileResponse(
|
||||
$fileInfo['response'],
|
||||
$fileInfo['etag_source'],
|
||||
(int) g7_core_settings('cache.layout_ttl', 86400)
|
||||
);
|
||||
}
|
||||
@@ -70,7 +71,7 @@ class PublicAttachmentController extends PublicBaseController
|
||||
// 이미지가 아닌 파일은 기존 다운로드 방식 유지
|
||||
$response = $this->attachmentService->download($hash, $user);
|
||||
|
||||
if (!$response) {
|
||||
if (! $response) {
|
||||
return $this->forbidden('attachment.access_denied');
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
/**
|
||||
* 공개 템플릿 API 컨트롤러
|
||||
@@ -340,21 +341,22 @@ class PublicTemplateController extends PublicBaseController
|
||||
*
|
||||
* @param string $identifier 템플릿 식별자
|
||||
* @param TemplateLayoutAttachment $attachment 라우트 모델 바인딩된 첨부
|
||||
* @return BinaryFileResponse|Response|JsonResponse 파일 응답 또는 404
|
||||
* @return StreamedResponse|Response|JsonResponse 파일 응답 또는 404
|
||||
*/
|
||||
public function serveFile(string $identifier, TemplateLayoutAttachment $attachment): BinaryFileResponse|Response|JsonResponse
|
||||
public function serveFile(string $identifier, TemplateLayoutAttachment $attachment): StreamedResponse|Response|JsonResponse
|
||||
{
|
||||
$filePath = $this->layoutAttachmentService->getServableFilePath($identifier, $attachment);
|
||||
$serveInfo = $this->layoutAttachmentService->getServableResponse($identifier, $attachment);
|
||||
|
||||
if ($filePath === null) {
|
||||
if ($serveInfo === null) {
|
||||
return $this->notFound('templates.layout_attachments.errors.not_found');
|
||||
}
|
||||
|
||||
// 이미지/일반 파일 모두 캐싱 헤더와 함께 인라인 응답 (레이아웃 캐시 TTL, 기본 24시간).
|
||||
// PublicAttachmentController 의 이미지 서빙과 동일한 fileResponse(ETag/Cache-Control) 사용.
|
||||
return $this->fileResponse(
|
||||
$filePath,
|
||||
$attachment->mime_type,
|
||||
// PublicAttachmentController 의 이미지 서빙과 동일한 streamedFileResponse(ETag/Cache-Control) 사용
|
||||
// — 행 disk 를 따르는 스토리지 스트림이라 S3 등 원격 디스크 행에서도 성립한다 (#99).
|
||||
return $this->streamedFileResponse(
|
||||
$serveInfo['response'],
|
||||
$serveInfo['etag_source'],
|
||||
(int) g7_core_settings('cache.layout_ttl', 86400)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Public\Attachment;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class DownloadAttachmentRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* 사용자가 이 요청을 수행할 권한이 있는지 확인
|
||||
*
|
||||
* 공개 다운로드 라우트 — 접근 제어는 AttachmentService 의 권한 훅
|
||||
* (core.attachment.download)이 하이브리드로 수행합니다.
|
||||
*
|
||||
* @return bool 항상 true (권한은 서비스 훅 책임)
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 요청에 적용할 검증 규칙
|
||||
*
|
||||
* 해시는 라우트 제약(`[a-zA-Z0-9]{12}`)이 이미 형식을 강제하고,
|
||||
* 그 외 입력 필드가 없는 요청입니다.
|
||||
*
|
||||
* @return array<string, mixed> 검증 규칙 배열
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Requests\Settings;
|
||||
use App\Extension\HookManager;
|
||||
use App\Models\Attachment;
|
||||
use App\Search\Engines\DatabaseFulltextEngine;
|
||||
use App\Services\DriverRegistryService;
|
||||
use App\Support\AllowedExtensions;
|
||||
use App\Support\AssetUrl;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
@@ -30,9 +31,9 @@ class SaveSettingsRequest extends FormRequest
|
||||
private const SUPPORTED_STORAGE_DRIVERS = ['local', 's3'];
|
||||
|
||||
/**
|
||||
* 지원되는 S3 리전 목록
|
||||
* S3 리전 형식 (AWS 리전 코드 + S3 호환 스토리지 임의값 허용 — R2 의 `auto` 등)
|
||||
*/
|
||||
private const SUPPORTED_S3_REGIONS = ['ap-northeast-2', 'ap-northeast-1', 'us-east-1', 'us-west-2', 'eu-west-1'];
|
||||
private const S3_REGION_FORMAT = 'regex:/^[a-z0-9-]+$/';
|
||||
|
||||
/**
|
||||
* 지원되는 캐시 드라이버 목록
|
||||
@@ -54,11 +55,6 @@ class SaveSettingsRequest extends FormRequest
|
||||
*/
|
||||
private const SUPPORTED_WEBSOCKET_SCHEMES = ['http', 'https'];
|
||||
|
||||
/**
|
||||
* 지원되는 검색엔진 드라이버 기본 목록
|
||||
*/
|
||||
private const DEFAULT_SEARCH_ENGINE_DRIVERS = ['mysql-fulltext'];
|
||||
|
||||
/**
|
||||
* 지원되는 로그 드라이버 목록
|
||||
*/
|
||||
@@ -313,22 +309,24 @@ class SaveSettingsRequest extends FormRequest
|
||||
'advanced.pagination_max_page' => ['nullable', 'integer', 'min:'.config('core.settings_limits.advanced_pagination_max_page_min', 0), 'max:'.config('core.settings_limits.advanced_pagination_max_page_max', 100000)],
|
||||
|
||||
// 드라이버 설정 (drivers 탭)
|
||||
'drivers.storage_driver' => $this->getTabRules($tab, 'drivers', [Rule::in(self::SUPPORTED_STORAGE_DRIVERS)]),
|
||||
'drivers.storage_driver' => $this->getTabRules($tab, 'drivers', [Rule::in(self::SUPPORTED_STORAGE_DRIVERS), $this->getDriverUsabilityRule('storage')]),
|
||||
'drivers.s3_bucket' => ['nullable', 'string', 'max:255'],
|
||||
'drivers.s3_region' => ['nullable', Rule::in(self::SUPPORTED_S3_REGIONS)],
|
||||
'drivers.s3_region' => ['nullable', 'string', 'max:64', self::S3_REGION_FORMAT],
|
||||
'drivers.s3_access_key' => ['nullable', 'string', 'max:255'],
|
||||
'drivers.s3_secret_key' => ['nullable', 'string', 'max:255'],
|
||||
'drivers.s3_url' => ['nullable', 'url', 'max:500'],
|
||||
'drivers.cache_driver' => $this->getTabRules($tab, 'drivers', [Rule::in(self::SUPPORTED_CACHE_DRIVERS)]),
|
||||
'drivers.s3_endpoint' => ['nullable', 'url', 'max:500'],
|
||||
'drivers.s3_use_path_style' => ['nullable', 'boolean'],
|
||||
'drivers.cache_driver' => $this->getTabRules($tab, 'drivers', [Rule::in(self::SUPPORTED_CACHE_DRIVERS), $this->getDriverUsabilityRule('cache')]),
|
||||
'drivers.redis_host' => ['nullable', 'string', 'max:255'],
|
||||
'drivers.redis_port' => ['nullable', 'integer', 'min:'.config('core.settings_limits.drivers_redis_port_min', 1), 'max:'.config('core.settings_limits.drivers_redis_port_max', 65535)],
|
||||
'drivers.redis_password' => ['nullable', 'string', 'max:255'],
|
||||
'drivers.redis_database' => ['nullable', 'integer', 'min:'.config('core.settings_limits.drivers_redis_database_min', 0), 'max:'.config('core.settings_limits.drivers_redis_database_max', 15)],
|
||||
'drivers.memcached_host' => ['nullable', 'string', 'max:255'],
|
||||
'drivers.memcached_port' => ['nullable', 'integer', 'min:'.config('core.settings_limits.drivers_memcached_port_min', 1), 'max:'.config('core.settings_limits.drivers_memcached_port_max', 65535)],
|
||||
'drivers.session_driver' => $this->getTabRules($tab, 'drivers', [Rule::in(self::SUPPORTED_SESSION_DRIVERS)]),
|
||||
'drivers.session_driver' => $this->getTabRules($tab, 'drivers', [Rule::in(self::SUPPORTED_SESSION_DRIVERS), $this->getDriverUsabilityRule('session')]),
|
||||
'drivers.session_lifetime' => ['nullable', 'integer', 'min:'.config('core.settings_limits.drivers_session_lifetime_min', 1), 'max:'.config('core.settings_limits.drivers_session_lifetime_max', 43200)], // 1분 ~ 30일
|
||||
'drivers.queue_driver' => $this->getTabRules($tab, 'drivers', [Rule::in(self::SUPPORTED_QUEUE_DRIVERS)]),
|
||||
'drivers.queue_driver' => $this->getTabRules($tab, 'drivers', [Rule::in(self::SUPPORTED_QUEUE_DRIVERS), $this->getDriverUsabilityRule('queue')]),
|
||||
'drivers.websocket_enabled' => ['nullable', 'boolean'],
|
||||
'drivers.websocket_app_id' => [Rule::requiredIf(fn () => $this->boolean('drivers.websocket_enabled')), 'nullable', 'string', 'max:255'],
|
||||
'drivers.websocket_app_key' => [Rule::requiredIf(fn () => $this->boolean('drivers.websocket_enabled')), 'nullable', 'string', 'max:255'],
|
||||
@@ -478,6 +476,34 @@ class SaveSettingsRequest extends FormRequest
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 드라이버 가용성 검증 rule 을 반환합니다.
|
||||
*
|
||||
* 선택된 드라이버가 현재 서버에서 실제로 동작 가능한지(어댑터 클래스·PHP 확장 존재)를
|
||||
* 저장 시점에 검사합니다. 사용 불능 드라이버가 저장되면 사이트 전면 다운으로 이어질 수
|
||||
* 있으므로(예: phpredis 확장 없는 서버의 redis) 서버 게이트로 차단합니다.
|
||||
*
|
||||
* @param string $category 드라이버 카테고리 (storage, cache, session, queue)
|
||||
* @return \Closure 검증 클로저
|
||||
*/
|
||||
private function getDriverUsabilityRule(string $category): \Closure
|
||||
{
|
||||
return function ($attribute, $value, $fail) use ($category) {
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$registry = app(DriverRegistryService::class);
|
||||
|
||||
if (! $registry->isDriverUsable($category, $value)) {
|
||||
$fail(__('validation.settings.driver_unusable', [
|
||||
'driver' => $value,
|
||||
'reason' => $registry->usabilityFailureReason($category, $value),
|
||||
]));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 추가 검증을 위해 validator after 콜백을 등록합니다.
|
||||
*
|
||||
@@ -734,11 +760,15 @@ class SaveSettingsRequest extends FormRequest
|
||||
'drivers.storage_driver.required' => __('validation.settings.storage_driver_required'),
|
||||
'drivers.storage_driver.in' => __('validation.settings.storage_driver_invalid'),
|
||||
'drivers.s3_bucket.max' => __('validation.settings.s3_bucket_max'),
|
||||
'drivers.s3_region.in' => __('validation.settings.s3_region_invalid'),
|
||||
'drivers.s3_region.regex' => __('validation.settings.s3_region_invalid'),
|
||||
'drivers.s3_region.max' => __('validation.settings.s3_region_max'),
|
||||
'drivers.s3_access_key.max' => __('validation.settings.s3_access_key_max'),
|
||||
'drivers.s3_secret_key.max' => __('validation.settings.s3_secret_key_max'),
|
||||
'drivers.s3_url.url' => __('validation.settings.s3_url_invalid'),
|
||||
'drivers.s3_url.max' => __('validation.settings.s3_url_max'),
|
||||
'drivers.s3_endpoint.url' => __('validation.settings.s3_endpoint_invalid'),
|
||||
'drivers.s3_endpoint.max' => __('validation.settings.s3_endpoint_max'),
|
||||
'drivers.s3_use_path_style.boolean' => __('validation.settings.s3_use_path_style_boolean'),
|
||||
'drivers.cache_driver.required' => __('validation.settings.cache_driver_required'),
|
||||
'drivers.cache_driver.in' => __('validation.settings.cache_driver_invalid'),
|
||||
'drivers.redis_host.max' => __('validation.settings.redis_host_max'),
|
||||
@@ -916,6 +946,8 @@ class SaveSettingsRequest extends FormRequest
|
||||
'drivers.s3_access_key' => __('validation.attributes.s3_access_key'),
|
||||
'drivers.s3_secret_key' => __('validation.attributes.s3_secret_key'),
|
||||
'drivers.s3_url' => __('validation.attributes.s3_url'),
|
||||
'drivers.s3_endpoint' => __('validation.attributes.s3_endpoint'),
|
||||
'drivers.s3_use_path_style' => __('validation.attributes.s3_use_path_style'),
|
||||
'drivers.cache_driver' => __('validation.attributes.cache_driver'),
|
||||
'drivers.redis_host' => __('validation.attributes.redis_host'),
|
||||
'drivers.redis_port' => __('validation.attributes.redis_port'),
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Http\Requests\Settings;
|
||||
|
||||
use App\Extension\HookManager;
|
||||
use App\Services\DriverRegistryService;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
@@ -20,9 +22,9 @@ class TestDriverConnectionRequest extends FormRequest
|
||||
private const SUPPORTED_STORAGE_DRIVERS = ['local', 's3'];
|
||||
|
||||
/**
|
||||
* 지원되는 S3 리전 목록
|
||||
* S3 리전 형식 (AWS 리전 코드 + S3 호환 스토리지 임의값 허용 — R2 의 `auto` 등)
|
||||
*/
|
||||
private const SUPPORTED_S3_REGIONS = ['ap-northeast-2', 'ap-northeast-1', 'us-east-1', 'us-west-2', 'eu-west-1'];
|
||||
private const S3_REGION_FORMAT = 'regex:/^[a-z0-9-]+$/';
|
||||
|
||||
/**
|
||||
* 지원되는 캐시 드라이버 목록
|
||||
@@ -57,24 +59,26 @@ class TestDriverConnectionRequest extends FormRequest
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$rules = [
|
||||
// 드라이버 선택
|
||||
'storage_driver' => ['nullable', Rule::in(self::SUPPORTED_STORAGE_DRIVERS)],
|
||||
'cache_driver' => ['nullable', Rule::in(self::SUPPORTED_CACHE_DRIVERS)],
|
||||
'session_driver' => ['nullable', Rule::in(self::SUPPORTED_SESSION_DRIVERS)],
|
||||
'queue_driver' => ['nullable', Rule::in(self::SUPPORTED_QUEUE_DRIVERS)],
|
||||
'storage_driver' => ['nullable', Rule::in(self::SUPPORTED_STORAGE_DRIVERS), $this->getDriverUsabilityRule('storage')],
|
||||
'cache_driver' => ['nullable', Rule::in(self::SUPPORTED_CACHE_DRIVERS), $this->getDriverUsabilityRule('cache')],
|
||||
'session_driver' => ['nullable', Rule::in(self::SUPPORTED_SESSION_DRIVERS), $this->getDriverUsabilityRule('session')],
|
||||
'queue_driver' => ['nullable', Rule::in(self::SUPPORTED_QUEUE_DRIVERS), $this->getDriverUsabilityRule('queue')],
|
||||
'websocket_enabled' => ['nullable', 'boolean'],
|
||||
|
||||
// S3 설정
|
||||
's3_bucket' => ['nullable', 'string', 'max:255'],
|
||||
's3_region' => ['nullable', Rule::in(self::SUPPORTED_S3_REGIONS)],
|
||||
's3_region' => ['nullable', 'string', 'max:64', self::S3_REGION_FORMAT],
|
||||
's3_access_key' => ['nullable', 'string', 'max:255'],
|
||||
's3_secret_key' => ['nullable', 'string', 'max:255'],
|
||||
's3_url' => ['nullable', 'url', 'max:500'],
|
||||
's3_endpoint' => ['nullable', 'url', 'max:500'],
|
||||
's3_use_path_style' => ['nullable', 'boolean'],
|
||||
|
||||
// Redis 설정
|
||||
'redis_host' => ['nullable', 'string', 'max:255'],
|
||||
@@ -86,11 +90,14 @@ class TestDriverConnectionRequest extends FormRequest
|
||||
'memcached_host' => ['nullable', 'string', 'max:255'],
|
||||
'memcached_port' => ['nullable', 'integer', 'min:1', 'max:65535'],
|
||||
|
||||
// Websocket 설정
|
||||
// Websocket 설정 — client(브라우저 접속) / server(백엔드 broadcast HTTP API) endpoint 분리
|
||||
'websocket_app_key' => ['nullable', 'string', 'max:255'],
|
||||
'websocket_host' => ['nullable', 'string', 'max:255'],
|
||||
'websocket_port' => ['nullable', 'integer', 'min:1', 'max:65535'],
|
||||
'websocket_scheme' => ['nullable', Rule::in(self::SUPPORTED_WEBSOCKET_SCHEMES)],
|
||||
'websocket_server_host' => ['nullable', 'string', 'max:255'],
|
||||
'websocket_server_port' => ['nullable', 'integer', 'min:1', 'max:65535'],
|
||||
'websocket_server_scheme' => ['nullable', Rule::in(self::SUPPORTED_WEBSOCKET_SCHEMES)],
|
||||
];
|
||||
|
||||
// 모듈/플러그인이 validation rules를 동적으로 추가할 수 있도록 훅 제공
|
||||
@@ -107,11 +114,15 @@ class TestDriverConnectionRequest extends FormRequest
|
||||
return [
|
||||
'storage_driver.in' => __('validation.settings.storage_driver_invalid'),
|
||||
's3_bucket.max' => __('validation.settings.s3_bucket_max'),
|
||||
's3_region.in' => __('validation.settings.s3_region_invalid'),
|
||||
's3_region.regex' => __('validation.settings.s3_region_invalid'),
|
||||
's3_region.max' => __('validation.settings.s3_region_max'),
|
||||
's3_access_key.max' => __('validation.settings.s3_access_key_max'),
|
||||
's3_secret_key.max' => __('validation.settings.s3_secret_key_max'),
|
||||
's3_url.url' => __('validation.settings.s3_url_invalid'),
|
||||
's3_url.max' => __('validation.settings.s3_url_max'),
|
||||
's3_endpoint.url' => __('validation.settings.s3_endpoint_invalid'),
|
||||
's3_endpoint.max' => __('validation.settings.s3_endpoint_max'),
|
||||
's3_use_path_style.boolean' => __('validation.settings.s3_use_path_style_boolean'),
|
||||
'cache_driver.in' => __('validation.settings.cache_driver_invalid'),
|
||||
'redis_host.max' => __('validation.settings.redis_host_max'),
|
||||
'redis_port.integer' => __('validation.settings.redis_port_integer'),
|
||||
@@ -134,6 +145,38 @@ class TestDriverConnectionRequest extends FormRequest
|
||||
'websocket_port.min' => __('validation.settings.websocket_port_min'),
|
||||
'websocket_port.max' => __('validation.settings.websocket_port_max'),
|
||||
'websocket_scheme.in' => __('validation.settings.websocket_scheme_invalid'),
|
||||
'websocket_server_host.max' => __('validation.settings.websocket_server_host_max'),
|
||||
'websocket_server_port.integer' => __('validation.settings.websocket_server_port_integer'),
|
||||
'websocket_server_port.min' => __('validation.settings.websocket_server_port_min'),
|
||||
'websocket_server_port.max' => __('validation.settings.websocket_server_port_max'),
|
||||
'websocket_server_scheme.in' => __('validation.settings.websocket_server_scheme_invalid'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 드라이버 가용성 검증 rule 을 반환합니다.
|
||||
*
|
||||
* 저장 게이트(SaveSettingsRequest)와 동일 판정 — 사용 불능 드라이버는 테스트 요청
|
||||
* 단계에서도 422 로 차단해 어느 경로로도 통과하지 못하게 합니다.
|
||||
*
|
||||
* @param string $category 드라이버 카테고리 (storage, cache, session, queue)
|
||||
* @return \Closure 검증 클로저
|
||||
*/
|
||||
private function getDriverUsabilityRule(string $category): \Closure
|
||||
{
|
||||
return function ($attribute, $value, $fail) use ($category) {
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$registry = app(DriverRegistryService::class);
|
||||
|
||||
if (! $registry->isDriverUsable($category, $value)) {
|
||||
$fail(__('validation.settings.driver_unusable', [
|
||||
'driver' => $value,
|
||||
'reason' => $registry->usabilityFailureReason($category, $value),
|
||||
]));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -269,14 +269,14 @@ class CoreServiceProvider extends ServiceProvider
|
||||
$this->app->when(AttachmentService::class)
|
||||
->needs(StorageInterface::class)
|
||||
->give(function () {
|
||||
return new CoreStorageDriver(config('attachment.disk', 'local'));
|
||||
return new CoreStorageDriver(config('attachment.disk', 'attachments'));
|
||||
});
|
||||
|
||||
// TemplateLayoutAttachmentService용 CoreStorageDriver 바인딩
|
||||
$this->app->when(TemplateLayoutAttachmentService::class)
|
||||
->needs(StorageInterface::class)
|
||||
->give(function () {
|
||||
return new CoreStorageDriver(config('attachment.disk', 'local'));
|
||||
return new CoreStorageDriver(config('attachment.disk', 'attachments'));
|
||||
});
|
||||
|
||||
// 코어 서비스용 CoreCacheDriver 바인딩
|
||||
@@ -888,7 +888,8 @@ class CoreServiceProvider extends ServiceProvider
|
||||
$configKey = $driverRegistry->getConfigKey($category);
|
||||
|
||||
if ($configKey && $defaultDriver) {
|
||||
Config::set($configKey, $defaultDriver);
|
||||
// log 카테고리의 적용 키(stack.channels)는 배열형 — 형태 변환은 레지스트리가 담당
|
||||
Config::set($configKey, $driverRegistry->getConfigValueForDriver($category, $defaultDriver));
|
||||
}
|
||||
|
||||
Log::warning("플러그인 드라이버 '{$selectedDriver}'가 '{$category}' 카테고리에서 사용 불가능합니다. 기본 드라이버 '{$defaultDriver}'로 폴백합니다.");
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Repositories\JsonConfigRepository;
|
||||
use App\Support\AllowedExtensions;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Predis\Client;
|
||||
|
||||
/**
|
||||
* 설정 서비스 프로바이더
|
||||
@@ -48,7 +49,6 @@ class SettingsServiceProvider extends ServiceProvider
|
||||
$this->applyAppConfig($configRepository);
|
||||
$this->applyDebugConfig($configRepository);
|
||||
$this->applyDriverConfig($configRepository);
|
||||
$this->applyCacheConfig($configRepository);
|
||||
$this->applyUploadConfig($configRepository);
|
||||
$this->applyCoreUpdateConfig($configRepository);
|
||||
$this->applyGeoIpConfig($configRepository);
|
||||
@@ -342,6 +342,16 @@ class SettingsServiceProvider extends ServiceProvider
|
||||
Config::set('filesystems.default', $driverSettings['storage_driver']);
|
||||
}
|
||||
|
||||
// 코어 첨부 업로드 디스크: ATTACHMENT_DISK env 명시가 항상 우선하고,
|
||||
// 미설정 시 storage_driver=s3 를 따른다. env() 직접 호출은 config:cache 환경에서
|
||||
// null 로 고정되므로 config 에 태운 attachment.disk_explicit 로 판별한다.
|
||||
// 빈 문자열도 미명시로 취급한다 — `ATTACHMENT_DISK=` 가 복사된 .env 에서
|
||||
// 빈 값을 명시로 읽으면 전환이 영구 미발동한다 (config 정규화의 2차 방어).
|
||||
// 기존 행은 행 disk 로 서빙되므로 신구 디스크 혼재는 안전하다.
|
||||
if (($driverSettings['storage_driver'] ?? null) === 's3' && in_array(config('attachment.disk_explicit'), [null, ''], true)) {
|
||||
Config::set('attachment.disk', 's3');
|
||||
}
|
||||
|
||||
// 웹소켓 설정
|
||||
$this->applyWebsocketConfig($driverSettings);
|
||||
|
||||
@@ -359,6 +369,16 @@ class SettingsServiceProvider extends ServiceProvider
|
||||
*/
|
||||
private function applyRedisConfig(array $driverSettings): void
|
||||
{
|
||||
// phpredis 확장이 없는 서버에서 redis 드라이버 선택 시 `Class "Redis" not found` 로
|
||||
// 사이트 전면 다운되는 결함 방어 — 설정된 클라이언트가 phpredis 인데 확장이 없고
|
||||
// predis 가 있으면 predis 로 폴백한다. 확장이 있으면 기존 phpredis 경로 그대로다.
|
||||
// env('REDIS_CLIENT') 미명시 판별은 무효였다: .env.example 이 REDIS_CLIENT=phpredis
|
||||
// 를 활성 배포하므로 표준 설치에서 영구 미발동이었고, env() 직접 호출은
|
||||
// config:cache 환경에서 null 로 고정된다 (A8 disk_explicit 와 동형 함정).
|
||||
if ($this->shouldFallBackToPredis(extension_loaded('redis'))) {
|
||||
Config::set('database.redis.client', 'predis');
|
||||
}
|
||||
|
||||
if (! empty($driverSettings['redis_host'])) {
|
||||
Config::set('database.redis.default.host', $driverSettings['redis_host']);
|
||||
Config::set('database.redis.cache.host', $driverSettings['redis_host']);
|
||||
@@ -380,6 +400,25 @@ class SettingsServiceProvider extends ServiceProvider
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redis 클라이언트를 predis 로 폴백해야 하는지 판정합니다.
|
||||
*
|
||||
* 설정된 클라이언트(config — env 시점 값이 config:cache 에도 박제됨)가 phpredis 를
|
||||
* 가리키는데 확장이 로드되어 있지 않고 predis 가 존재하면 참. phpredis 명시 설정이라도
|
||||
* 확장이 없으면 어차피 동작 불가이므로 predis 전환이 유일한 동작 경로다 (#99 A2).
|
||||
* 확장 로드 여부는 인자로 받는다 — 확장 설치 머신에서 부재 상태를 재현할 수 없어
|
||||
* 판정 자체를 단위 검증 가능하게 분리한 것 (테스트가 양 분기를 주입 검증).
|
||||
*
|
||||
* @param bool $phpredisLoaded phpredis 확장 로드 여부 (extension_loaded('redis'))
|
||||
* @return bool predis 로 폴백해야 하면 true
|
||||
*/
|
||||
private function shouldFallBackToPredis(bool $phpredisLoaded): bool
|
||||
{
|
||||
return config('database.redis.client', 'phpredis') !== 'predis'
|
||||
&& ! $phpredisLoaded
|
||||
&& class_exists(Client::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Memcached 연결 설정을 적용합니다.
|
||||
*/
|
||||
@@ -418,6 +457,16 @@ class SettingsServiceProvider extends ServiceProvider
|
||||
if (! empty($driverSettings['s3_url'])) {
|
||||
Config::set('filesystems.disks.s3.url', $driverSettings['s3_url']);
|
||||
}
|
||||
|
||||
// S3 호환 스토리지(R2/MinIO/NCP 등)의 API 요청 대상 — s3_url(공개 URL base)과 별개 축이다.
|
||||
// endpoint 미주입 시 SDK 는 AWS 리전 도메인으로만 요청하므로 호환 스토리지 연결이 불가능하다.
|
||||
if (! empty($driverSettings['s3_endpoint'])) {
|
||||
Config::set('filesystems.disks.s3.endpoint', $driverSettings['s3_endpoint']);
|
||||
}
|
||||
|
||||
if (! empty($driverSettings['s3_use_path_style'])) {
|
||||
Config::set('filesystems.disks.s3.use_path_style_endpoint', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -619,26 +668,6 @@ class SettingsServiceProvider extends ServiceProvider
|
||||
Config::set('settings.identity', $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* 캐시 설정을 Laravel config에 적용합니다.
|
||||
*/
|
||||
private function applyCacheConfig(JsonConfigRepository $configRepository): void
|
||||
{
|
||||
$cacheSettings = $configRepository->getCategory('cache');
|
||||
|
||||
if (empty($cacheSettings)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! empty($cacheSettings['driver'])) {
|
||||
Config::set('cache.default', $cacheSettings['driver']);
|
||||
}
|
||||
|
||||
if (! empty($cacheSettings['prefix'])) {
|
||||
Config::set('cache.prefix', $cacheSettings['prefix']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 업로드 설정을 Laravel config에 적용합니다.
|
||||
*/
|
||||
@@ -650,10 +679,6 @@ class SettingsServiceProvider extends ServiceProvider
|
||||
return;
|
||||
}
|
||||
|
||||
if (! empty($uploadSettings['disk'])) {
|
||||
Config::set('filesystems.default', $uploadSettings['disk']);
|
||||
}
|
||||
|
||||
// 관리자 설정은 MB, config/attachment.* 는 KB — 변환은 이 지점 단 한 곳에서만 수행한다.
|
||||
// (기존에는 존재하지 않는 키 `max_size` 를 읽어 설정이 어디에도 반영되지 않았다)
|
||||
if (! empty($uploadSettings['max_file_size'])) {
|
||||
|
||||
@@ -270,12 +270,15 @@ class AttachmentService
|
||||
/**
|
||||
* 이미지 파일 정보 조회 (캐싱 응답용)
|
||||
*
|
||||
* 권한 체크 후 파일 경로와 메타 정보를 반환합니다.
|
||||
* 컨트롤러에서 fileResponse()로 캐싱 헤더와 함께 응답할 수 있습니다.
|
||||
* 권한 체크 후 인라인 스트림 응답과 캐싱용 메타를 반환합니다.
|
||||
* 로컬 절대 경로 조립(getBasePath) 방식은 S3 등 원격 디스크 행에서 성립하지
|
||||
* 않으므로(#99 — filemtime stat 실패 500), 행 disk 를 그대로 따르는
|
||||
* StorageInterface::response() 스트림으로 서빙합니다. 컨트롤러는
|
||||
* streamedFileResponse() 로 캐싱 헤더(ETag/304)를 입혀 응답합니다.
|
||||
*
|
||||
* @param string $hash 첨부파일 해시
|
||||
* @param User|null $user 요청한 사용자 (null이면 비로그인)
|
||||
* @return array{path: string, mime_type: string, filename: string}|null 파일 정보 또는 null
|
||||
* @return array{response: StreamedResponse, etag_source: string, mime_type: string, filename: string}|null 서빙 정보 또는 null
|
||||
*
|
||||
* @throws AuthorizationException 기능 레벨 권한이 없는 경우
|
||||
*/
|
||||
@@ -293,9 +296,19 @@ class AttachmentService
|
||||
// 필터 훅 - 다운로드 전 처리
|
||||
$attachment = HookManager::applyFilters('core.attachment.before_download', $attachment, $user);
|
||||
|
||||
// 파일 존재 확인
|
||||
$diskStorage = $this->storage->withDisk($attachment->disk);
|
||||
if (! $diskStorage->exists('', $attachment->path)) {
|
||||
// 행 disk 기준 인라인 스트림 (존재 검사는 response() 내부에서 수행)
|
||||
// Content-Type/Length 를 행 메타로 선지정해 원격 디스크의 추가 메타 조회를 생략한다.
|
||||
$response = $this->storage->withDisk($attachment->disk)->response(
|
||||
'',
|
||||
$attachment->path,
|
||||
$attachment->original_filename,
|
||||
[
|
||||
'Content-Type' => $attachment->mime_type,
|
||||
'Content-Length' => (string) $attachment->size,
|
||||
]
|
||||
);
|
||||
|
||||
if (! $response) {
|
||||
Log::error('첨부파일 스토리지에 없음', [
|
||||
'attachment_id' => $attachment->id,
|
||||
'path' => $attachment->path,
|
||||
@@ -305,7 +318,14 @@ class AttachmentService
|
||||
}
|
||||
|
||||
return [
|
||||
'path' => $diskStorage->getBasePath('').DIRECTORY_SEPARATOR.$attachment->path,
|
||||
'response' => $response,
|
||||
// 파일 stat 없이 결정적인 ETag 소스 (업로드 파일은 경로당 불변)
|
||||
'etag_source' => implode('|', [
|
||||
$attachment->disk,
|
||||
$attachment->path,
|
||||
(string) $attachment->updated_at?->getTimestamp(),
|
||||
(string) $attachment->size,
|
||||
]),
|
||||
'mime_type' => $attachment->mime_type,
|
||||
'filename' => $attachment->original_filename,
|
||||
];
|
||||
|
||||
@@ -8,6 +8,7 @@ use Aws\S3\S3Client;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
|
||||
use Predis\Client;
|
||||
|
||||
/**
|
||||
@@ -101,9 +102,19 @@ class DriverConnectionTester
|
||||
];
|
||||
}
|
||||
|
||||
// Flysystem S3 어댑터 존재 선검사 — 테스트는 SDK 직접 경로지만 실제 파일 I/O 는
|
||||
// Storage::disk('s3') → 어댑터를 경유하므로, 어댑터가 없으면 테스트가 성공해도
|
||||
// 실경로가 즉사한다 (#99 의 결함 은폐 구조). sdk_missing 검사와 대칭.
|
||||
if (! class_exists(AwsS3V3Adapter::class)) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => __('settings.s3_adapter_missing'),
|
||||
];
|
||||
}
|
||||
|
||||
$startTime = microtime(true);
|
||||
|
||||
$client = new S3Client([
|
||||
$clientOptions = [
|
||||
'version' => 'latest',
|
||||
'region' => $region,
|
||||
'credentials' => [
|
||||
@@ -114,7 +125,18 @@ class DriverConnectionTester
|
||||
'timeout' => 5,
|
||||
'connect_timeout' => 3,
|
||||
],
|
||||
]);
|
||||
];
|
||||
|
||||
// S3 호환 스토리지(R2/MinIO 등) — 실경로(applyS3Config 주입)와 동일하게
|
||||
// endpoint/path-style 을 반영해야 테스트가 실제 연결 대상과 일치한다.
|
||||
if (! empty($config['s3_endpoint'])) {
|
||||
$clientOptions['endpoint'] = $config['s3_endpoint'];
|
||||
}
|
||||
if (! empty($config['s3_use_path_style'])) {
|
||||
$clientOptions['use_path_style_endpoint'] = true;
|
||||
}
|
||||
|
||||
$client = new S3Client($clientOptions);
|
||||
|
||||
// 버킷 존재 확인
|
||||
$client->headBucket(['Bucket' => $bucket]);
|
||||
@@ -372,15 +394,53 @@ class DriverConnectionTester
|
||||
* @return array 테스트 결과
|
||||
*/
|
||||
public function testWebsocket(array $config): array
|
||||
{
|
||||
$clientHost = $config['websocket_host'] ?? 'localhost';
|
||||
$clientPort = (int) ($config['websocket_port'] ?? 8080);
|
||||
$clientScheme = $config['websocket_scheme'] ?? 'https';
|
||||
|
||||
// 서버(백엔드 broadcast HTTP API) endpoint — 빈 값은 클라이언트 값으로 폴백한다
|
||||
// (SettingsServiceProvider::applyWebsocketConfig 와 동일 규칙). 백엔드 송신은
|
||||
// server endpoint 를 쓰므로 client 만 검사하면 "테스트 성공 + 실제 발송 실패" 가 된다.
|
||||
$serverHost = ($config['websocket_server_host'] ?? '') !== '' ? $config['websocket_server_host'] : $clientHost;
|
||||
$serverPort = (int) ($config['websocket_server_port'] ?? 0) > 0 ? (int) $config['websocket_server_port'] : $clientPort;
|
||||
$serverScheme = ($config['websocket_server_scheme'] ?? '') !== '' ? $config['websocket_server_scheme'] : $clientScheme;
|
||||
|
||||
$clientUrl = sprintf('%s://%s:%d', $clientScheme, $clientHost, $clientPort);
|
||||
$serverUrl = sprintf('%s://%s:%d', $serverScheme, $serverHost, $serverPort);
|
||||
|
||||
// 클라이언트 endpoint 검사
|
||||
$clientResult = $this->probeWebsocketEndpoint($clientUrl);
|
||||
|
||||
if (! $clientResult['success']) {
|
||||
return $clientResult;
|
||||
}
|
||||
|
||||
// 서버 endpoint 검사 (클라이언트와 동일 주소면 중복 요청 생략)
|
||||
if ($serverUrl !== $clientUrl) {
|
||||
$serverResult = $this->probeWebsocketEndpoint($serverUrl);
|
||||
|
||||
if (! $serverResult['success']) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => __('settings.websocket_server_test_failed'),
|
||||
'error' => $serverResult['error'] ?? ($serverResult['message'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $clientResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Websocket(Reverb) HTTP endpoint 하나를 probe 합니다.
|
||||
*
|
||||
* @param string $url 검사할 endpoint URL
|
||||
* @return array 테스트 결과
|
||||
*/
|
||||
private function probeWebsocketEndpoint(string $url): array
|
||||
{
|
||||
try {
|
||||
$host = $config['websocket_host'] ?? 'localhost';
|
||||
$port = (int) ($config['websocket_port'] ?? 8080);
|
||||
$scheme = $config['websocket_scheme'] ?? 'https';
|
||||
|
||||
// Reverb 서버 상태 확인 (기본 HTTP 엔드포인트)
|
||||
$url = sprintf('%s://%s:%d', $scheme, $host, $port);
|
||||
|
||||
// Reverb 는 통상 localhost·사내 IP 에서 동작하므로 사설 주소 자체는 정상 구성이다.
|
||||
// 다만 이 진단 요청을 임의 목적지 탐색에 전용하지 못하도록, 정상 설정에서는 나올 수
|
||||
// 없는 값(userinfo 위장, http/https 이외 scheme, 제어문자 주입)은 거부한다.
|
||||
@@ -426,6 +486,7 @@ class DriverConnectionTester
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Log::warning('Websocket connection test failed', [
|
||||
'url' => $url,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ namespace App\Services;
|
||||
use App\Extension\HookManager;
|
||||
use App\Repositories\JsonConfigRepository;
|
||||
use Illuminate\Support\Facades\Lang;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
|
||||
use Predis\Client;
|
||||
|
||||
/**
|
||||
* 코어 드라이버 레지스트리 서비스
|
||||
@@ -59,7 +60,10 @@ class DriverRegistryService
|
||||
'cache' => 'cache.default',
|
||||
'session' => 'session.driver',
|
||||
'queue' => 'queue.default',
|
||||
'log' => 'logging.default',
|
||||
// 실제 적용 키 — SettingsServiceProvider::applyLogConfig() 가 기록하는 키와 동일해야
|
||||
// 플러그인 로그 드라이버 폴백이 실효한다 (logging.default 는 어디에서도 읽지 않는 죽은 키였다).
|
||||
// 이 키의 값은 채널 "배열" 이다 — getConfigValueForDriver() 로 형태를 맞춘다.
|
||||
'log' => 'logging.channels.stack.channels',
|
||||
'websocket' => 'broadcasting.default',
|
||||
'mail' => 'mail.default',
|
||||
];
|
||||
@@ -75,7 +79,9 @@ class DriverRegistryService
|
||||
'session' => ['category' => 'drivers', 'key' => 'session_driver'],
|
||||
'queue' => ['category' => 'drivers', 'key' => 'queue_driver'],
|
||||
'log' => ['category' => 'drivers', 'key' => 'log_driver'],
|
||||
'websocket' => ['category' => 'drivers', 'key' => 'websocket_driver'],
|
||||
// websocket 은 드라이버 ID 선택 설정이 없다 (불리언 websocket_enabled 뿐) —
|
||||
// 종전의 'websocket_driver' 는 어떤 저장 경로에도 없는 유령 키라 항상 skip 이었다.
|
||||
// 카테고리 제외로 같은 동작을 명시화한다 (getSettingsKey('websocket') === null).
|
||||
'mail' => ['category' => 'mail', 'key' => 'mailer'],
|
||||
];
|
||||
|
||||
@@ -237,6 +243,70 @@ class DriverRegistryService
|
||||
return $inUse;
|
||||
}
|
||||
|
||||
/**
|
||||
* 주어진 드라이버가 현재 서버에서 실제로 동작 가능한지 판정합니다.
|
||||
*
|
||||
* isDriverAvailable() 이 "등록 여부"(카탈로그 소속)를 보는 것과 달리, 이 메서드는
|
||||
* 어댑터 클래스·PHP 확장 등 런타임 능력의 존재를 검사합니다. 사용 불능 드라이버가
|
||||
* 저장되면 다음 부팅에서 사이트 전면 다운으로 이어질 수 있으므로 저장/테스트
|
||||
* FormRequest 의 서버 게이트가 이 판정을 사용합니다.
|
||||
*
|
||||
* @param string $category 드라이버 카테고리 (storage, cache, session, queue 등)
|
||||
* @param string $driverId 드라이버 ID
|
||||
* @return bool 동작 가능하면 true
|
||||
*/
|
||||
public function isDriverUsable(string $category, string $driverId): bool
|
||||
{
|
||||
return $this->usabilityFailureReason($category, $driverId) === null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 드라이버 사용 불능 사유를 반환합니다.
|
||||
*
|
||||
* 판정은 드라이버 ID 가 요구하는 런타임 능력 기준입니다. 코어가 능력을 모르는
|
||||
* 드라이버(플러그인 등록 드라이버 포함)는 null(사용 가능) — 플러그인 드라이버의
|
||||
* 가용성은 그 플러그인의 ServiceProvider 가 보증합니다.
|
||||
*
|
||||
* @param string $category 드라이버 카테고리
|
||||
* @param string $driverId 드라이버 ID
|
||||
* @return string|null 사용 불능 사유 (다국어), 사용 가능하면 null
|
||||
*/
|
||||
public function usabilityFailureReason(string $category, string $driverId): ?string
|
||||
{
|
||||
return match ($driverId) {
|
||||
's3' => class_exists(AwsS3V3Adapter::class)
|
||||
? null
|
||||
: __('settings.driver_unusable_s3_adapter'),
|
||||
// redis 는 설정된 클라이언트 기준으로 판정한다 — predis 명시 설정이면 predis
|
||||
// 존재만 본다. phpredis 설정은 확장 부재여도 부트 폴백(SettingsServiceProvider::
|
||||
// shouldFallBackToPredis)이 predis 로 전환하므로 predis 존재까지 사용 가능이다.
|
||||
'redis' => (config('database.redis.client', 'phpredis') === 'predis'
|
||||
? class_exists(Client::class)
|
||||
: (extension_loaded('redis') || class_exists(Client::class)))
|
||||
? null
|
||||
: __('settings.driver_unusable_redis_client'),
|
||||
'memcached' => extension_loaded('memcached')
|
||||
? null
|
||||
: __('settings.driver_unusable_memcached_extension'),
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 카테고리의 Config 키에 기록할 값 형태로 드라이버 ID 를 변환합니다.
|
||||
*
|
||||
* log 카테고리의 적용 키(logging.channels.stack.channels)는 채널 배열이므로
|
||||
* 배열로 감싸고, 그 외 카테고리는 드라이버 ID 문자열 그대로입니다.
|
||||
*
|
||||
* @param string $category 드라이버 카테고리
|
||||
* @param string $driverId 드라이버 ID
|
||||
* @return string|array<int, string> Config 기록 값
|
||||
*/
|
||||
public function getConfigValueForDriver(string $category, string $driverId): string|array
|
||||
{
|
||||
return $category === 'log' ? [$driverId] : $driverId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 지원되는 카테고리 목록을 반환합니다.
|
||||
*
|
||||
|
||||
@@ -13,6 +13,7 @@ use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
/**
|
||||
* 템플릿 레이아웃 첨부 파일 서비스
|
||||
@@ -169,17 +170,17 @@ class TemplateLayoutAttachmentService
|
||||
}
|
||||
|
||||
/**
|
||||
* 서빙 가능한 첨부 파일의 절대 경로를 돌려줍니다.
|
||||
* 서빙 가능한 첨부의 인라인 스트림 응답과 캐싱 메타를 돌려줍니다.
|
||||
*
|
||||
* 첨부가 주어진 템플릿 소속인지 검증하고, 스토리지에 파일이 실제로 존재하면
|
||||
* 컨트롤러가 스트림할 수 있는 절대 파일시스템 경로를 반환한다. 소속 불일치 /
|
||||
* 파일 부재 시 null (컨트롤러가 404).
|
||||
* 첨부가 주어진 템플릿 소속인지 검증하고, 행 disk 를 따르는 스토리지 스트림
|
||||
* 응답을 반환한다 (S3 등 원격 디스크 행 포함 — 로컬 절대 경로 방식은 #99 에서
|
||||
* filemtime 500). 소속 불일치 / 파일 부재 시 null (컨트롤러가 404).
|
||||
*
|
||||
* @param string $templateIdentifier 요청 경로의 템플릿 식별자
|
||||
* @param TemplateLayoutAttachment $attachment 서빙 대상 첨부
|
||||
* @return string|null 절대 파일 경로 또는 null
|
||||
* @return array{response: StreamedResponse, etag_source: string}|null 서빙 정보 또는 null
|
||||
*/
|
||||
public function getServableFilePath(string $templateIdentifier, TemplateLayoutAttachment $attachment): ?string
|
||||
public function getServableResponse(string $templateIdentifier, TemplateLayoutAttachment $attachment): ?array
|
||||
{
|
||||
$template = $this->templateRepository->findByIdentifier($templateIdentifier);
|
||||
// 경로 식별자와 첨부의 소속 템플릿이 일치해야 한다 (교차 템플릿 접근 차단).
|
||||
@@ -187,12 +188,31 @@ class TemplateLayoutAttachmentService
|
||||
return null;
|
||||
}
|
||||
|
||||
$driver = $this->storage->withDisk($attachment->disk);
|
||||
if (! $driver->exists(self::STORAGE_CATEGORY, $attachment->path)) {
|
||||
// 행 disk 기준 인라인 스트림 (존재 검사는 response() 내부에서 수행).
|
||||
// 로컬 절대 경로 조립(getBasePath)은 S3 등 원격 디스크 행에서 성립하지 않는다 (#99).
|
||||
$response = $this->storage->withDisk($attachment->disk)->response(
|
||||
self::STORAGE_CATEGORY,
|
||||
$attachment->path,
|
||||
$attachment->original_name ?? basename($attachment->path),
|
||||
[
|
||||
'Content-Type' => $attachment->mime_type,
|
||||
'Content-Length' => (string) $attachment->size,
|
||||
]
|
||||
);
|
||||
|
||||
if (! $response) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 절대 경로 — {category base}/{relative path}. fileResponse 가 절대 경로를 요구.
|
||||
return rtrim($driver->getBasePath(self::STORAGE_CATEGORY), '/\\').'/'.$attachment->path;
|
||||
return [
|
||||
'response' => $response,
|
||||
// 파일 stat 없이 결정적인 ETag 소스 (업로드 파일은 경로당 불변)
|
||||
'etag_source' => implode('|', [
|
||||
$attachment->disk,
|
||||
$attachment->path,
|
||||
(string) $attachment->updated_at?->getTimestamp(),
|
||||
(string) $attachment->size,
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -178,10 +178,12 @@ class ParameterDescriber
|
||||
'memcached_host' => 'Memcached 호스트 주소',
|
||||
'memcached_port' => 'Memcached 포트 번호',
|
||||
's3_bucket' => 'S3 버킷명',
|
||||
's3_region' => 'S3 리전',
|
||||
's3_region' => 'S3 리전 (소문자 영숫자·하이픈 — AWS 리전 코드 또는 S3 호환 스토리지 값, R2 는 auto)',
|
||||
's3_access_key' => 'S3 액세스 키',
|
||||
's3_secret_key' => 'S3 시크릿 키',
|
||||
's3_url' => 'S3 엔드포인트 URL',
|
||||
's3_url' => 'S3 공개 URL(CDN) base — 파일 URL 생성용 (API 요청 주소 아님)',
|
||||
's3_endpoint' => 'S3 API 엔드포인트 — S3 호환 스토리지(R2/MinIO 등)용, AWS S3 는 미입력',
|
||||
's3_use_path_style' => 'S3 path-style 주소 사용 여부 (MinIO 등)',
|
||||
'ses_key' => 'SES 액세스 키',
|
||||
'ses_secret' => 'SES 시크릿 키',
|
||||
'ses_region' => 'SES 리전',
|
||||
|
||||
Reference in new issue
Block a user