forked from DMarby/picsum-photos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildcache.js
45 lines (38 loc) · 1.17 KB
/
buildcache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var sharp = require('sharp')
var path = require('path')
var async = require('async')
var config = require('./config')()
var fs = require('fs')
try {
var cache = require(config.cache_metadata_path)
} catch (error) {
var cache = {}
}
sharp.cache(0)
var imageProcessor = require('./imageProcessor')(sharp, path, config, fs)
var images = require(config.image_store_path)
fs.mkdir(config.cache_folder_path, function (error) {
var index = process.argv[2] || 0
console.log('Start: %s', index)
if (index > 0) {
images.splice(0, index)
}
async.eachLimit(images, 5, function (image, next) {
var width = 458
var height = 354
imageProcessor.getProcessedImage(width, height, null, false, false, image.filename, false, function (error, imagePath) {
if (error) {
console.log('filePath: ' + image.filename)
console.log('imagePath: ' + imagePath)
console.log('error: ' + err)
}
console.log('%s done', image.id)
cache[imagePath] = new Date()
next()
})
}, function (error) {
fs.writeFile(config.cache_metadata_path, JSON.stringify(cache), 'utf-8', function (error) {
console.log('Done')
})
})
})