diff --git a/app/package-lock.json b/app/package-lock.json index 863102e4..d48c1474 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -8193,6 +8193,11 @@ "integrity": "sha512-MmbQJ2MTESTjt3Gi/3yG1wGpIMhUfcIypUCGtTizFR9IiccFwxSpfp0vtIZlkFclEqERemxfnSdZEMR9VqqEFQ==", "dev": true }, + "node-fs": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/node-fs/-/node-fs-0.1.7.tgz", + "integrity": "sha1-MjI8zLRsn78PwRgS1FAhzDHTJbs=" + }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -8931,7 +8936,7 @@ }, "semver": { "version": "4.3.2", - "resolved": "https://registry.npmjs.org/semver/-/semver-4.3.2.tgz", + "resolved": "http://registry.npmjs.org/semver/-/semver-4.3.2.tgz", "integrity": "sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c=" } } @@ -12070,7 +12075,7 @@ "dependencies": { "minimist": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" } } diff --git a/app/package.json b/app/package.json index 85ac3b81..1b7906c1 100644 --- a/app/package.json +++ b/app/package.json @@ -22,6 +22,7 @@ "express-session": "^1.15.6", "leaflet": "^1.4.0", "mapnik": "^4.2.1", + "node-fs": "^0.1.7", "pg-promise": "^8.5.6", "react": "^16.8.3", "react-dom": "^16.8.3", diff --git a/app/src/frontend/map.js b/app/src/frontend/map.js index 959e8355..a49da6fe 100644 --- a/app/src/frontend/map.js +++ b/app/src/frontend/map.js @@ -98,7 +98,7 @@ class ColouringMap extends Component { + minZoom={9} /> : null; // highlight @@ -120,7 +120,7 @@ class ColouringMap extends Component { 10 we could drop this in favour of fs.mkdir (which has recursive option) +// and then use stdlib `import fs from 'fs';` +import fs from 'node-fs'; // const CACHE_PATH = process.env.CACHE_PATH const CACHE_PATH = '/home/tom/projects/colouring-london/colouring-london/app/tilecache' @@ -37,31 +40,21 @@ function put(im, tileset, z, x, y, cb){ const fname = `${dir}/${y}.png` fs.writeFile(fname, im, 'binary', (err) => { if (err && err.code === 'ENOENT') { - try { - console.log("trying") - mkdir_recursive(dir); - fs.writeFile(fname, im, 'binary', cb); - } catch (error) { - console.log("mkdir error") - cb(err); - } + fs.mkdir(dir, 0o755, true, (err) => { + if (err){ + cb(err); + } else { + fs.writeFile(fname, im, 'binary', cb); + } + }); } else { cb(err) } }); } -// for node >10 we could drop this in favour of fs.mkdir(dir, { recursive: true }, (err) => {}) -function mkdir_recursive(dir) { - const parent = path.dirname(dir); - if (!fs.existsSync(parent)) { - mkdir_recursive(parent) - } - fs.mkdirSync(dir); -} - function should_try_cache(tileset, z) { - if (tileset === 'base_light' || tileset === 'base_light') { + if (tileset === 'base_light' || tileset === 'base_night') { // cache for higher zoom levels (unlikely to change) return z <= 15 }