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:
HeuJung committed 2026-08-13 15:15:19 +09:00
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)
);
}