MCPcopy
hub / github.com/ollm/OpenComic / returnThumbnailsImages

Function returnThumbnailsImages

scripts/cache.js:167–238  ·  view source on GitHub ↗
(images, callback, file = false)

Source from the content-addressed store, hash-verified

165var data = false;
166
167function returnThumbnailsImages(images, callback, file = false)
168{
169 if(!data) data = storage.get('cache') || {};
170
171 const single = images.length === undefined ? true : false;
172 images = single ? [images] : images;
173
174 const sizes = getSizes();
175
176 let thumbnail = {};
177 const thumbnails = {};
178 const toGenerateThumbnails = [];
179 const toGenerateThumbnailsData = {};
180
181 const time = app.time();
182
183 for(let i = 0, len = images.length; i < len; i++)
184 {
185 const image = images[i];
186 const forceSize = image.forceSize || 150;
187
188 const sha = imageSizeSha(image);
189 const imgCache = data[sha];
190
191 const size = image.type ? sizes[image.type][forceSize] : sizes.image[forceSize];
192 const path = addCacheVars(p.join(cacheFolder, sha+'.jpg'), size, sha);
193
194 if(typeof imgCache == 'undefined' || !fs.existsSync(p.join(cacheFolder, sha+'.jpg')))
195 {
196 toGenerateThumbnails.push(image);
197 toGenerateThumbnailsData[image.path] = {sha: sha, vars: image.vars, type: image.type || false, forceSize: forceSize};
198
199 thumbnails[sha] = thumbnail = {cache: false, path: '', sha: sha};
200 }
201 else
202 {
203 data[sha].lastAccess = time;
204
205 if(imgCache.size != size)
206 {
207 toGenerateThumbnails.push(image);
208 toGenerateThumbnailsData[image.path] = {sha: sha, vars: image.vars, type: image.type || false, forceSize: forceSize};
209
210 thumbnails[sha] = thumbnail = {cache: true, path: escapeBackSlash(path), sha: sha};
211 }
212 else
213 {
214 thumbnails[sha] = thumbnail = {cache: true, path: escapeBackSlash(path), sha: sha};
215 }
216 }
217 }
218
219 if(toGenerateThumbnails.length > 0 && file)
220 {
221 threads.job('cacheMakeAvailable', {useThreads: 0.01, delay: 50}, async function() {
222
223 await file.makeAvailable(toGenerateThumbnails, function(image) {
224

Callers

nothing calls this directly

Calls 5

imageSizeShaFunction · 0.85
addCacheVarsFunction · 0.85
escapeBackSlashFunction · 0.85
addImageToQueueFunction · 0.85
getSizesFunction · 0.70

Tested by

no test coverage detected