Skip to content

Commit e9ed0e8

Browse files
committed
fix: thumbnails cache not working when digest suffix is enabled
1 parent 57c1fc2 commit e9ed0e8

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

packages/builder/src/photo/cache-manager.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import path from 'node:path'
21

32
import { thumbnailExists } from '../image/thumbnail.js'
43
import type { PhotoManifestItem } from '../types/photo.js'
@@ -19,13 +18,11 @@ export interface CacheableData {
1918
* 考虑文件更新状态和缓存存在性
2019
*/
2120
export async function shouldProcessPhoto(
22-
photoKey: string,
21+
photoId: string,
2322
existingItem: PhotoManifestItem | undefined,
2423
obj: { LastModified?: Date; ETag?: string },
2524
options: PhotoProcessorOptions,
2625
): Promise<{ shouldProcess: boolean; reason: string }> {
27-
const photoId = path.basename(photoKey, path.extname(photoKey))
28-
2926
// 强制模式下总是处理
3027
if (options.isForceMode) {
3128
return { shouldProcess: true, reason: '强制模式' }

packages/builder/src/photo/image-pipeline.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export async function processImageWithSharp(
133133
* @param s3Key S3键
134134
* @returns 带摘要后缀的ID
135135
*/
136-
function generatePhotoId(s3Key: string): string {
136+
async function generatePhotoId(s3Key: string): Promise<string> {
137137
const { options } = defaultBuilder.getConfig()
138138
const { digestSuffixLength } = options
139139
if (!digestSuffixLength || digestSuffixLength <= 0) {
@@ -157,7 +157,7 @@ export async function executePhotoProcessingPipeline(
157157
const loggers = getGlobalLoggers()
158158

159159
// Generate the actual photo ID with digest suffix
160-
const photoId = generatePhotoId(photoKey)
160+
const photoId = await generatePhotoId(photoKey)
161161

162162
try {
163163
// 1. 预处理图片
@@ -256,9 +256,11 @@ export async function processPhotoWithPipeline(
256256
const { photoKey, existingItem, obj, options } = context
257257
const loggers = getGlobalLoggers()
258258

259+
const photoId = await generatePhotoId(photoKey)
260+
259261
// 检查是否需要处理
260262
const { shouldProcess, reason } = await shouldProcessPhoto(
261-
photoKey,
263+
photoId,
262264
existingItem,
263265
obj,
264266
options,

0 commit comments

Comments
 (0)