fix: gallery preview retries and avoid caching failed image responses
Verify storage files before serving from the index, disable CDN caching on image 404/403 and host-isolation blocks, and retry gallery thumbnails after transient load failures.
This commit is contained in:
1 parent
b0a5fbfca5
commit
f25c89855f
4 files changed
+59
-6
No files matched your search
@@ -1,7 +1,10 @@
|
||||
import { shouldBlockImageHostRequest, shouldBlockSiteHostImageRequest } from '../utils/host-isolation'
|
||||
|
||||
const HOST_ISOLATION_CACHE_CONTROL = 'private, no-cache, max-age=0'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
if (shouldBlockImageHostRequest(event) || shouldBlockSiteHostImageRequest(event)) {
|
||||
setHeader(event, 'Cache-Control', HOST_ISOLATION_CACHE_CONTROL)
|
||||
throw createError({ statusCode: 404, statusMessage: 'Not Found' })
|
||||
}
|
||||
})
|
||||
@@ -20,7 +20,7 @@ import { getBackendRowForKey } from './storage/resolver'
|
||||
* - Referer 可被非浏览器客户端伪造,本方案防普通网站盗链,不是身份认证
|
||||
*/
|
||||
|
||||
const ERROR_CACHE_CONTROL = 'public, max-age=60'
|
||||
const ERROR_CACHE_CONTROL = 'private, no-cache, max-age=0'
|
||||
|
||||
function getAllowedHosts(event: H3Event): Set<string> {
|
||||
const hosts = new Set<string>()
|
||||
|
||||
+12
-3
@@ -53,13 +53,22 @@ export async function putImage(
|
||||
}
|
||||
|
||||
export async function headImage(key: string): Promise<StoredImage | null> {
|
||||
const indexed = getImageIndexAsStored(key)
|
||||
if (indexed) return indexed
|
||||
|
||||
const backend = await getBackendForKey(key)
|
||||
const stored = await backend.head(key)
|
||||
if (!stored) return null
|
||||
|
||||
const indexed = getImageIndexAsStored(key)
|
||||
if (indexed) {
|
||||
return {
|
||||
...stored,
|
||||
backendId: backend.id,
|
||||
originalName: indexed.originalName,
|
||||
contentType: indexed.contentType,
|
||||
uploadedAt: indexed.uploadedAt,
|
||||
userId: indexed.userId
|
||||
}
|
||||
}
|
||||
|
||||
insertImageIndex({
|
||||
key: stored.key,
|
||||
backendId: backend.id,
|
||||
|
||||
Reference in new issue
Block a user