Add unit tests for LoginButton component with comprehensive coverage
All checks were successful
Gitea Actions Demo / build-and-push (push) Successful in 46s
All checks were successful
Gitea Actions Demo / build-and-push (push) Successful in 46s
This commit is contained in:
@@ -9,6 +9,7 @@ export async function getCachedImageUrl(
|
||||
if (!imageId) throw new Error('imageId required')
|
||||
|
||||
// reuse existing object URL if created in this session
|
||||
console.log('Checking existing object URL for imageId:', imageId)
|
||||
const existing = objectUrlMap.get(imageId)
|
||||
if (existing) return existing
|
||||
|
||||
@@ -23,6 +24,7 @@ export async function getCachedImageUrl(
|
||||
const fetched = await fetch(requestUrl)
|
||||
if (!fetched.ok) throw new Error(`HTTP ${fetched.status}`)
|
||||
// store a clone in Cache Storage (non-blocking)
|
||||
console.log('Caching image:', requestUrl)
|
||||
cache.put(requestUrl, fetched.clone()).catch((e) => {
|
||||
console.warn('Cache put failed:', e)
|
||||
})
|
||||
@@ -40,6 +42,31 @@ export async function getCachedImageUrl(
|
||||
return objectUrl
|
||||
}
|
||||
|
||||
export async function getCachedImageBlob(
|
||||
imageId: string,
|
||||
cacheName = DEFAULT_IMAGE_CACHE,
|
||||
): Promise<Blob> {
|
||||
if (!imageId) throw new Error('imageId required')
|
||||
const requestUrl = `/api/image/request/${imageId}`
|
||||
|
||||
let response: Response | undefined
|
||||
if ('caches' in window) {
|
||||
const cache = await caches.open(cacheName)
|
||||
response = await cache.match(requestUrl)
|
||||
if (!response) {
|
||||
const fetched = await fetch(requestUrl)
|
||||
if (!fetched.ok) throw new Error(`HTTP ${fetched.status}`)
|
||||
cache.put(requestUrl, fetched.clone()).catch(() => {})
|
||||
response = fetched
|
||||
}
|
||||
} else {
|
||||
const fetched = await fetch(requestUrl)
|
||||
if (!fetched.ok) throw new Error(`HTTP ${fetched.status}`)
|
||||
response = fetched
|
||||
}
|
||||
return await response.blob()
|
||||
}
|
||||
|
||||
export function revokeImageUrl(imageId: string) {
|
||||
const url = objectUrlMap.get(imageId)
|
||||
if (url) {
|
||||
|
||||
Reference in New Issue
Block a user