파생 이미지 캐시 재검증 적용
This commit is contained in:
@@ -2,6 +2,7 @@ const postCardThumbnailUrlPattern = /^\/uploads\/posts\/\d{4}\/\d{2}\/thumbs\/[^
|
||||
const pageCoverThumbnailUrlPattern = /^\/uploads\/posts\/\d{4}\/\d{2}\/thumbs\/[^/?#]+-page-cover\.webp$/i
|
||||
const postBodyThumbnailUrlPattern = /^\/uploads\/posts\/\d{4}\/\d{2}\/thumbs\/[^/?#]+-(?:body(?:-720)?|lightbox)\.webp$/i
|
||||
const postUploadImageUrlPattern = /^\/uploads\/posts\/\d{4}\/\d{2}\/[^/?#]+\.(?:jpe?g|png|webp)$/i
|
||||
const generatedImageCacheVersion = '20260702-1'
|
||||
|
||||
/**
|
||||
* 게시물 원본 이미지 URL에 대응하는 파생 이미지 URL을 만든다.
|
||||
@@ -52,6 +53,36 @@ export const isPostBodyThumbnailUrl = (imageUrl) => Boolean(
|
||||
imageUrl && postBodyThumbnailUrlPattern.test(String(imageUrl))
|
||||
)
|
||||
|
||||
/**
|
||||
* 자동 생성 이미지 URL인지 확인한다.
|
||||
* @param {string|null|undefined} imageUrl - 검사할 이미지 URL
|
||||
* @returns {boolean} 자동 생성 이미지이면 true
|
||||
*/
|
||||
export const isGeneratedPostImageUrl = (imageUrl) => isPostCardThumbnailUrl(imageUrl)
|
||||
|| isPageCoverThumbnailUrl(imageUrl)
|
||||
|| isPostBodyThumbnailUrl(imageUrl)
|
||||
|
||||
/**
|
||||
* 자동 생성 이미지 URL에 캐시 우회 쿼리를 붙인다.
|
||||
* @param {string|null|undefined} imageUrl - 이미지 URL
|
||||
* @param {string} [version] - 캐시 버전
|
||||
* @returns {string} 표시용 이미지 URL
|
||||
*/
|
||||
export const withGeneratedImageCacheVersion = (imageUrl, version = generatedImageCacheVersion) => {
|
||||
const url = String(imageUrl || '')
|
||||
|
||||
if (!isGeneratedPostImageUrl(url)) {
|
||||
return url
|
||||
}
|
||||
|
||||
const hashIndex = url.indexOf('#')
|
||||
const baseUrl = hashIndex >= 0 ? url.slice(0, hashIndex) : url
|
||||
const hash = hashIndex >= 0 ? url.slice(hashIndex) : ''
|
||||
const separator = baseUrl.includes('?') ? '&' : '?'
|
||||
|
||||
return `${baseUrl}${separator}v=${encodeURIComponent(version)}${hash}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 게시물 원본 이미지 URL에 대응하는 본문 표시용 이미지 URL을 만든다.
|
||||
* @param {string|null|undefined} imageUrl - 원본 이미지 URL
|
||||
|
||||
Reference in New Issue
Block a user