(img = false)
| 29 | if(!fs.existsSync(cacheFolder)) fs.mkdirSync(cacheFolder); |
| 30 | |
| 31 | async function processTheImageQueue(img = false) |
| 32 | { |
| 33 | let sha = img.sha; |
| 34 | |
| 35 | let realPath = fileManager.realPath(img.file); |
| 36 | let toImage = p.join(cacheFolder, sha+'.jpg'); |
| 37 | |
| 38 | let fit = { |
| 39 | poster: 'cover', |
| 40 | }; |
| 41 | |
| 42 | const ratios = getRatios(); |
| 43 | const forceSize = img.forceSize || 150; |
| 44 | |
| 45 | if(compatible.image.convert(img.file)) // Convert unsupported images |
| 46 | await workers.convertImage(img.file, {useThreads: 0.3/*0.4*/}); |
| 47 | |
| 48 | return new Promise(function(resolve, reject) { |
| 49 | |
| 50 | image.resize(realPath, toImage, {width: img.size, height: Math.round(img.size * (img.type ? ratios[img.type][forceSize] : 1.5)), quality: 95, fit: img.type ? fit[img.type] : 'inside'}).then(function(){ |
| 51 | |
| 52 | if(typeof data[sha] === 'undefined') data[sha] = {lastAccess: app.time()}; |
| 53 | data[sha].size = img.size; |
| 54 | |
| 55 | img.callback({cache: true, path: escapeBackSlash(addCacheVars(toImage, img.size, img.sha)), sha: sha}, img.vars); |
| 56 | |
| 57 | storage.setThrottle('cache', data); |
| 58 | resolve(); |
| 59 | |
| 60 | }).catch(function(){ |
| 61 | |
| 62 | img.callback({cache: true, path: escapeBackSlash(realPath), sha: sha}, img.vars); |
| 63 | |
| 64 | resolve(); |
| 65 | |
| 66 | }); |
| 67 | |
| 68 | }); |
| 69 | } |
| 70 | |
| 71 | async function addImageToQueue(file, size, sha, callback, vars, type, forceSize) |
| 72 | { |
nothing calls this directly
no test coverage detected