MCPcopy Create free account
hub / github.com/ColmapView/Colmapview.github.io / fetchUrlImage

Function fetchUrlImage

src/utils/urlImageFiles.ts:92–135  ·  view source on GitHub ↗
(
  imageUrlBase: string | null,
  imageName: string,
  explicitUrl?: string
)

Source from the content-addressed store, hash-verified

90 * @returns The fetched File or null if fetch failed
91 */
92export async function fetchUrlImage(
93 imageUrlBase: string | null,
94 imageName: string,
95 explicitUrl?: string
96): Promise<File | null> {
97 const cached = urlImageState.getCached(imageName);
98 if (cached) {
99 return cached;
100 }
101
102 const resolved = resolveImageRequestUrl(imageUrlBase, imageName, explicitUrl);
103 if (!resolved) {
104 return null;
105 }
106 const { url: imageUrl, filename } = resolved;
107
108 if (urlImageState.isRequestPending(imageUrl)) {
109 return urlImageState.waitForRequest(imageUrl);
110 }
111
112 urlImageState.startRequest(imageUrl);
113 let result: File | null = null;
114
115 try {
116 const response = await fetch(imageUrl);
117 if (!response.ok) {
118 appLogger.warn(`[URL Image] Failed to fetch ${imageName}: ${response.status}`);
119 return null;
120 }
121
122 const blob = await response.blob();
123 const file = await compressAndResizeToJpeg(blob, filename);
124
125 urlImageState.setCached(imageName, file);
126 result = file;
127
128 return file;
129 } catch (err) {
130 appLogger.warn(`[URL Image] Error fetching ${imageName}:`, err);
131 return null;
132 } finally {
133 urlImageState.completeRequest(imageUrl, result);
134 }
135}
136
137/**
138 * Fetch an image from URL without display-cache resizing or JPEG recompression.

Callers 4

getImageFunction · 0.90
prefetchUrlImagesFunction · 0.85

Calls 9

compressAndResizeToJpegFunction · 0.90
resolveImageRequestUrlFunction · 0.85
getCachedMethod · 0.80
isRequestPendingMethod · 0.80
waitForRequestMethod · 0.80
startRequestMethod · 0.80
blobMethod · 0.80
setCachedMethod · 0.80
completeRequestMethod · 0.80

Tested by

no test coverage detected