feat(content): 본문 이미지 목록 썸네일·og:image 폴백 전 티어 구현
공개 이슈 https://github.com/gnuboard/g7/issues/22 — 본문에 삽입한 이미지가 카드/갤러리 목록 썸네일과 공유 미리보기(og:image)에 반영되지 않던 공백을 코어+3모듈+2템플릿에서 해소. - 코어 7.0.9: HtmlImageExtractor(내부 이미지 한정, origin 정규화 SSoT 재사용) + seo.og_image_default 사이트 기본 공유 이미지 설정 + SeoMetaResolver 폴백 체인 - board 1.1.0 / ecommerce 1.2.0 / page 1.1.0: content_thumbnail_url 캐시 컬럼, saving 추출(html 모드 한정·첨부 우선·비밀글 게이트 유지), filter_content_thumbnail 훅, 기존 데이터 백필 업그레이드 스텝 - ecommerce 카테고리 og:image 생산자 신설, page og:description 死키 정정 - sirsoft-basic 1.1.2 og 바인딩 정정, admin_basic 1.0.7 SEO 탭 업로더(+ja 팩 2종) - 검수 중 발견한 text 모드 오캐시 결함은 실패 테스트 선행 후 수정
This commit is contained in:
1 parent
14eb2e39e4
commit
1ba67ca7cf
98 files changed
+4640
-101
No files matched your search
@@ -303,7 +303,8 @@ class PostResource extends BaseApiResource
|
||||
* 썸네일 URL을 관계 로딩 상태에 따라 반환합니다.
|
||||
*
|
||||
* thumbnailAttachment(경량 hasOne) 우선, attachments(전체) fallback.
|
||||
* 둘 다 미로딩 시 null 반환 (lazy loading 방지).
|
||||
* 첨부에서 URL 을 얻지 못한 모든 경우 본문 첫 내부 이미지 캐시
|
||||
* (content_thumbnail_url)로 폴백하고, 그것도 없으면 null (공개 이슈 #22).
|
||||
*
|
||||
* @return string|null 썸네일 URL
|
||||
*/
|
||||
@@ -312,28 +313,29 @@ class PostResource extends BaseApiResource
|
||||
// 비밀글은 썸네일 URL 자체를 방출하지 않는다 — 서빙은 이미 차단되어 이미지가 보이지는
|
||||
// 않지만, URL 에 실린 첨부 해시가 목록·상세 응답으로 나가 있었다(KVE-2026-1894).
|
||||
// 판정은 첨부 목록과 같은 SecretContentGate(SSoT)를 쓴다. 필드는 남기고 값만 가린다.
|
||||
// 본문 캐시 폴백도 반드시 이 게이트 뒤 — 에디터 이미지는 공개 hash 서빙이라
|
||||
// 첨부와 달리 서빙측 차단이 없어, 이 게이트가 유일한 차단선이다.
|
||||
if ($this->is_secret && ! $this->canViewSecretContent(request())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$url = null;
|
||||
|
||||
// 목록용 경량 관계 우선 — slug를 직접 전달하여 Board::find() N+1 방지
|
||||
if ($this->relationLoaded('thumbnailAttachment') && $this->thumbnailAttachment) {
|
||||
$attachment = $this->thumbnailAttachment;
|
||||
$slug = request()->route('slug') ?? ($this->relationLoaded('board') ? $this->board?->slug : null);
|
||||
|
||||
if ($slug && $attachment->hash) {
|
||||
return $attachment->previewUrlForSlug($slug);
|
||||
$url = $attachment->previewUrlForSlug($slug);
|
||||
}
|
||||
|
||||
return null;
|
||||
} elseif ($this->relationLoaded('attachments')) {
|
||||
// 상세 페이지 등에서 attachments가 로딩된 경우 fallback
|
||||
$url = $this->getThumbnailUrl();
|
||||
}
|
||||
|
||||
// 상세 페이지 등에서 attachments가 로딩된 경우 fallback
|
||||
if ($this->relationLoaded('attachments')) {
|
||||
return $this->getThumbnailUrl();
|
||||
}
|
||||
|
||||
return null;
|
||||
// 이미지 첨부가 없을 때만 본문 첫 내부 이미지 캐시 폴백 (첨부 우선 정책)
|
||||
return $url ?? ($this->content_thumbnail_url ?: null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,10 +5,12 @@ namespace Modules\Sirsoft\Board\Models;
|
||||
use App\Extension\HookManager;
|
||||
use App\Models\User;
|
||||
use App\Search\Contracts\FulltextSearchable;
|
||||
use App\Support\HtmlImageExtractor;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Laravel\Scout\Searchable;
|
||||
use Modules\Sirsoft\Board\Enums\PostStatus;
|
||||
@@ -30,7 +32,7 @@ class Post extends Model implements FulltextSearchable
|
||||
'content_mode' => ['label_key' => 'sirsoft-board::activity_log.fields.content_mode', 'type' => 'text'],
|
||||
'is_notice' => ['label_key' => 'sirsoft-board::activity_log.fields.is_notice', 'type' => 'boolean'],
|
||||
'is_secret' => ['label_key' => 'sirsoft-board::activity_log.fields.is_secret', 'type' => 'boolean'],
|
||||
'status' => ['label_key' => 'sirsoft-board::activity_log.fields.status', 'type' => 'enum', 'enum' => \Modules\Sirsoft\Board\Enums\PostStatus::class],
|
||||
'status' => ['label_key' => 'sirsoft-board::activity_log.fields.status', 'type' => 'enum', 'enum' => PostStatus::class],
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -64,6 +66,7 @@ class Post extends Model implements FulltextSearchable
|
||||
'title',
|
||||
'content',
|
||||
'content_mode',
|
||||
'content_thumbnail_url',
|
||||
'user_id',
|
||||
'author_name',
|
||||
'password',
|
||||
@@ -105,6 +108,47 @@ class Post extends Model implements FulltextSearchable
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 모델 이벤트 등록
|
||||
*
|
||||
* 본문 첫 내부 이미지 URL 캐시(content_thumbnail_url)는 저장 시점에만 계산한다 —
|
||||
* 목록 쿼리는 content 를 SELECT 하지 않으므로(컬럼 프루닝) 조회 시점 파싱이 불가하다.
|
||||
* Service 가 아닌 모델 saving 이벤트에 두는 이유: 시더·테스트의 Post::create() 직접
|
||||
* 호출과 이커머스 문의 훅 리스너 경유 경로까지 누락 없이 커버되는 유일 지점이기 때문.
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (Post $post) {
|
||||
if ($post->exists && ! $post->isDirty('content') && ! $post->isDirty('content_mode')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// text 모드 본문은 이스케이프되어 렌더된다(상세에 이미지 미표시) — 리터럴
|
||||
// img 마크업을 캐시하면 목록 썸네일만 떠서 상세와 어긋나므로 추출하지 않는다.
|
||||
if ($post->content_mode !== 'html') {
|
||||
$post->content_thumbnail_url = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$content = (string) $post->content;
|
||||
|
||||
// 확장이 후보를 대체(CDN prefix 승격 등)하거나 차단(null)할 수 있는 필터 훅.
|
||||
// 특정 에디터 확장에 의존하지 않는다 — 페이로드는 일반 HTML 파싱 결과뿐이다.
|
||||
$value = HookManager::applyFilters(
|
||||
'sirsoft-board.post.filter_content_thumbnail',
|
||||
HtmlImageExtractor::firstInternal($content),
|
||||
$post,
|
||||
HtmlImageExtractor::candidates($content)
|
||||
);
|
||||
|
||||
// 필터 반환값 방어 — 비문자열/빈 값/컬럼 상한 초과는 null(후보 없음)로 강등
|
||||
$post->content_thumbnail_url = is_string($value) && $value !== '' && mb_strlen($value) <= 1000
|
||||
? $value
|
||||
: null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 게시판과의 관계를 정의합니다.
|
||||
*
|
||||
@@ -181,9 +225,9 @@ class Post extends Model implements FulltextSearchable
|
||||
*
|
||||
* 전체 attachments를 eager loading하는 대신 이미지 1건만 가져와 성능을 확보합니다.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
* @return HasOne
|
||||
*/
|
||||
public function thumbnailAttachment(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
public function thumbnailAttachment(): HasOne
|
||||
{
|
||||
return $this->hasOne(Attachment::class, 'post_id')
|
||||
->where('mime_type', 'like', 'image/%')
|
||||
|
||||
@@ -62,7 +62,7 @@ class PostRepository implements PostRepositoryInterface
|
||||
// 목록 전용 컬럼: content(본문 HTML) 제외 → content_preview로 대체
|
||||
$listColumns = [
|
||||
'id', 'board_id', 'user_id', 'parent_id', 'category',
|
||||
'title', 'author_name', 'content_mode',
|
||||
'title', 'author_name', 'content_mode', 'content_thumbnail_url',
|
||||
'is_notice', 'is_secret', 'status', 'depth',
|
||||
'view_count', 'comments_count', 'replies_count', 'attachments_count',
|
||||
'trigger_type', 'ip_address', 'created_at', 'updated_at', 'deleted_at',
|
||||
|
||||
Reference in new issue
Block a user