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==",
|
"integrity": "sha512-MmbQJ2MTESTjt3Gi/3yG1wGpIMhUfcIypUCGtTizFR9IiccFwxSpfp0vtIZlkFclEqERemxfnSdZEMR9VqqEFQ==",
|
||||||
"dev": true
|
"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": {
|
"node-int64": {
|
||||||
"version": "0.4.0",
|
"version": "0.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
|
||||||
@ -8931,7 +8936,7 @@
|
|||||||
},
|
},
|
||||||
"semver": {
|
"semver": {
|
||||||
"version": "4.3.2",
|
"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="
|
"integrity": "sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -12070,7 +12075,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "1.2.0",
|
"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="
|
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
"express-session": "^1.15.6",
|
"express-session": "^1.15.6",
|
||||||
"leaflet": "^1.4.0",
|
"leaflet": "^1.4.0",
|
||||||
"mapnik": "^4.2.1",
|
"mapnik": "^4.2.1",
|
||||||
|
"node-fs": "^0.1.7",
|
||||||
"pg-promise": "^8.5.6",
|
"pg-promise": "^8.5.6",
|
||||||
"react": "^16.8.3",
|
"react": "^16.8.3",
|
||||||
"react-dom": "^16.8.3",
|
"react-dom": "^16.8.3",
|
||||||
|
@ -98,7 +98,7 @@ class ColouringMap extends Component {
|
|||||||
<TileLayer
|
<TileLayer
|
||||||
key={data_tileset}
|
key={data_tileset}
|
||||||
url={`/tiles/${data_tileset}/{z}/{x}/{y}.png?rev=${rev}`}
|
url={`/tiles/${data_tileset}/{z}/{x}/{y}.png?rev=${rev}`}
|
||||||
minZoom={14} />
|
minZoom={9} />
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
// highlight
|
// highlight
|
||||||
@ -120,7 +120,7 @@ class ColouringMap extends Component {
|
|||||||
<Map
|
<Map
|
||||||
center={position}
|
center={position}
|
||||||
zoom={this.state.zoom}
|
zoom={this.state.zoom}
|
||||||
minZoom={10}
|
minZoom={9}
|
||||||
maxZoom={18}
|
maxZoom={18}
|
||||||
doubleClickZoom={false}
|
doubleClickZoom={false}
|
||||||
zoomControl={false}
|
zoomControl={false}
|
||||||
|
@ -12,8 +12,11 @@
|
|||||||
* at zoom level n
|
* 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 = process.env.CACHE_PATH
|
||||||
const CACHE_PATH = '/home/tom/projects/colouring-london/colouring-london/app/tilecache'
|
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`
|
const fname = `${dir}/${y}.png`
|
||||||
fs.writeFile(fname, im, 'binary', (err) => {
|
fs.writeFile(fname, im, 'binary', (err) => {
|
||||||
if (err && err.code === 'ENOENT') {
|
if (err && err.code === 'ENOENT') {
|
||||||
try {
|
fs.mkdir(dir, 0o755, true, (err) => {
|
||||||
console.log("trying")
|
if (err){
|
||||||
mkdir_recursive(dir);
|
cb(err);
|
||||||
fs.writeFile(fname, im, 'binary', cb);
|
} else {
|
||||||
} catch (error) {
|
fs.writeFile(fname, im, 'binary', cb);
|
||||||
console.log("mkdir error")
|
}
|
||||||
cb(err);
|
});
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
cb(err)
|
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) {
|
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)
|
// cache for higher zoom levels (unlikely to change)
|
||||||
return z <= 15
|
return z <= 15
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user