feat(worker-hall): 抢单大厅支持分类与全部按钮图标自定义及PNG透明通道修复

This commit is contained in:
yml2213
2026-09-12 20:16:27 +08:00
parent 694d7fff40
commit 1cf790d6ab
11 changed files with 187 additions and 41 deletions
@@ -225,12 +225,23 @@ export function refreshUploadedFileUrls(value: unknown) {
}
}
export const PUBLIC_SCENES = new Set(['category_icon', 'hall_icon', 'public', 'announcement'])
export function isPublicObjectKey(objectKey: string) {
const normalized = normalizeObjectKey(objectKey)
const firstSegment = normalized.split('/')[0] || ''
return PUBLIC_SCENES.has(firstSegment)
}
export function verifyFileAccessSignature(
objectKey: string,
expiresValue: unknown,
signatureValue: unknown,
nowSeconds = Math.floor(Date.now() / 1000),
) {
if (isPublicObjectKey(objectKey)) {
return
}
const expires = Number(expiresValue || 0)
const signature = String(signatureValue || '').trim()
if (!Number.isSafeInteger(expires) || expires < nowSeconds || !signature) {
@@ -388,22 +399,24 @@ async function generateImageVariants(objectKey: string, data: Buffer, contentTyp
for (const config of configs) {
try {
const content = await sharp(data)
.rotate()
.resize({
width: config.maxSide,
height: config.maxSide,
fit: 'inside',
withoutEnlargement: true,
})
.flatten({ background: '#ffffff' })
.jpeg({ quality: config.quality, mozjpeg: true })
.toBuffer()
const isAlpha = contentType === 'image/png' || contentType === 'image/webp'
const pipeline = sharp(data).rotate().resize({
width: config.maxSide,
height: config.maxSide,
fit: 'inside',
withoutEnlargement: true,
})
const content = isAlpha
? await pipeline.webp({ quality: config.quality, alphaQuality: 95 }).toBuffer()
: await pipeline
.flatten({ background: '#ffffff' })
.jpeg({ quality: config.quality, mozjpeg: true })
.toBuffer()
variants.push({
name: config.name,
key: imageVariantKey(objectKey, config.name),
content,
contentType: 'image/jpeg',
contentType: isAlpha ? 'image/webp' : 'image/jpeg',
})
} catch {
return variants