Use node-fs package to patch fs.mkdir
This commit is contained in:
parent
c5ebcd2df8
commit
77849531a6
9
app/package-lock.json
generated
9
app/package-lock.json
generated
@ -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="
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -98,7 +98,7 @@ class ColouringMap extends Component {
|
||||
<TileLayer
|
||||
key={data_tileset}
|
||||
url={`/tiles/${data_tileset}/{z}/{x}/{y}.png?rev=${rev}`}
|
||||
minZoom={14} />
|
||||
minZoom={9} />
|
||||
: null;
|
||||
|
||||
// highlight
|
||||
@ -120,7 +120,7 @@ class ColouringMap extends Component {
|
||||
<Map
|
||||
center={position}
|
||||
zoom={this.state.zoom}
|
||||
minZoom={10}
|
||||
minZoom={9}
|
||||
maxZoom={18}
|
||||
doubleClickZoom={false}
|
||||
zoomControl={false}
|
||||
|
@ -12,8 +12,11 @@
|
||||
* at zoom level n
|
||||
*
|
||||
*/
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// Using node-fs package to patch fs
|
||||
// for node >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")
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user