fixed preloading url issue
This commit is contained in:
parent
b2fd213fa3
commit
a454109b79
@ -257,6 +257,8 @@ export function usePreloadOrchestrator(
|
||||
|
||||
// Map of original URL → decoded blob URL (ready to display instantly)
|
||||
const readyBlobUrlsRef = useRef<Map<string, string>>(new Map());
|
||||
// Set of URLs that failed cache lookup (prevents infinite retry loops)
|
||||
const failedCacheLookupRef = useRef<Set<string>>(new Set());
|
||||
|
||||
// Use neighbor graph for determining what to preload
|
||||
const neighborGraph = useNeighborGraph({
|
||||
@ -278,11 +280,40 @@ export function usePreloadOrchestrator(
|
||||
const createReadyBlobUrl = useCallback(
|
||||
async (url: string, storageKey?: string): Promise<void> => {
|
||||
try {
|
||||
// Get blob from Cache API
|
||||
const blob = await StorageManager.getAsset(url);
|
||||
// Skip if we already know this URL is not in cache (prevents infinite loops)
|
||||
if (failedCacheLookupRef.current.has(url)) {
|
||||
return;
|
||||
}
|
||||
if (storageKey && failedCacheLookupRef.current.has(storageKey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try multiple URL formats to handle key mismatches
|
||||
// (presigned URL vs proxy URL vs storage key)
|
||||
let blob = await StorageManager.getAsset(url);
|
||||
|
||||
// If not found and we have a storage key, try that too
|
||||
if (!blob && storageKey && storageKey !== url) {
|
||||
blob = await StorageManager.getAsset(storageKey);
|
||||
}
|
||||
|
||||
// Also try with the proxy URL format as fallback
|
||||
if (!blob && storageKey) {
|
||||
const proxyUrl = `${baseURLApi}/file/download?privateUrl=${encodeURIComponent(storageKey.replace(/^\/+/, ''))}`;
|
||||
if (proxyUrl !== url) {
|
||||
blob = await StorageManager.getAsset(proxyUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if (!blob) {
|
||||
// Mark as failed to prevent repeated lookups
|
||||
failedCacheLookupRef.current.add(url);
|
||||
if (storageKey) {
|
||||
failedCacheLookupRef.current.add(storageKey);
|
||||
}
|
||||
logger.info('[PRELOAD] No blob found in cache', {
|
||||
url: url.slice(-50),
|
||||
storageKey: storageKey?.slice(-50),
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -370,6 +401,11 @@ export function usePreloadOrchestrator(
|
||||
logger.info('[PRELOAD] Download complete', {
|
||||
url: item.url.slice(-50),
|
||||
});
|
||||
// Clear failed cache lookup status since we just downloaded fresh
|
||||
failedCacheLookupRef.current.delete(item.url);
|
||||
if (item.storageKey) {
|
||||
failedCacheLookupRef.current.delete(item.storageKey);
|
||||
}
|
||||
await createReadyBlobUrl(item.url, item.storageKey);
|
||||
if (isPresignedUrl(item.url)) {
|
||||
markPresignedUrlsVerified();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user