Skip to content

Commit

Permalink
Merge branch 'maptiler:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanlaar authored Nov 30, 2023
2 parents 5bdfc5d + f0181c5 commit 98ebbba
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 348 deletions.
94 changes: 47 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"devDependencies": {
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"chai": "4.3.10",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
Expand Down
2 changes: 1 addition & 1 deletion public/templates/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<div class="details">
<h3>{{tileJSON.name}}</h3>
<div class="identifier">identifier: {{@key}}{{#if formatted_filesize}} | size: {{formatted_filesize}}{{/if}}</div>
<div class="identifier">type: {{#is_vector}}vector{{/is_vector}}{{^is_vector}}raster{{/is_vector}} data {{#if source_type}} | ext: {{source_type}}{{/if}}</div>
<div class="identifier">type: {{#is_vector}}vector{{/is_vector}}{{^is_vector}}raster{{/is_vector}} data {{#if sourceType}} | ext: {{sourceType}}{{/if}}</div>
<p class="services">
services: <a href="{{public_url}}data/{{@key}}.json{{&../key_query}}">TileJSON</a>
{{#if xyz_link}}
Expand Down
59 changes: 30 additions & 29 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import axios from 'axios';
import { server } from './server.js';
import MBTiles from '@mapbox/mbtiles';
import { isValidHttpUrl } from './utils.js';
import { PMtilesOpen, GetPMtilesInfo } from './pmtiles_adapter.js';
import { openPMtiles, getPMtilesInfo } from './pmtiles_adapter.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand Down Expand Up @@ -62,26 +62,26 @@ const opts = program.opts();

console.log(`Starting ${packageJson.name} v${packageJson.version}`);

const StartServer = (configPath, config) => {
const startServer = (configPath, config) => {
let publicUrl = opts.public_url;
if (publicUrl && publicUrl.lastIndexOf('/') !== publicUrl.length - 1) {
publicUrl += '/';
}
return server({
configPath: configPath,
config: config,
configPath,
config,
bind: opts.bind,
port: opts.port,
cors: opts.cors,
verbose: opts.verbose,
silent: opts.silent,
logFile: opts.log_file,
logFormat: opts.log_format,
publicUrl: publicUrl,
publicUrl,
});
};

const StartWithInputFile = async (inputFile) => {
const startWithInputFile = async (inputFile) => {
console.log(`[INFO] Automatically creating config file for ${inputFile}`);
console.log(`[INFO] Only a basic preview style will be used.`);
console.log(
Expand Down Expand Up @@ -123,8 +123,8 @@ const StartWithInputFile = async (inputFile) => {

const extension = inputFile.split('.').pop().toLowerCase();
if (extension === 'pmtiles') {
let FileOpenInfo = PMtilesOpen(inputFile);
const metadata = await GetPMtilesInfo(FileOpenInfo);
const fileOpenInfo = openPMtiles(inputFile);
const metadata = await getPMtilesInfo(fileOpenInfo);

if (
metadata.format === 'pbf' &&
Expand Down Expand Up @@ -174,7 +174,7 @@ const StartWithInputFile = async (inputFile) => {
console.log('Run with --verbose to see the config file here.');
}

return StartServer(null, config);
return startServer(null, config);
} else {
if (isValidHttpUrl(inputFile)) {
console.log(
Expand Down Expand Up @@ -215,7 +215,7 @@ const StartWithInputFile = async (inputFile) => {
config['styles'][styleName] = {

Check warning on line 215 in src/main.js

View workflow job for this annotation

GitHub Actions / ESLint

src/main.js#L215

Generic Object Injection Sink (security/detect-object-injection)
style: styleFileRel,
tilejson: {
bounds: bounds,
bounds,
},
};
}
Expand All @@ -235,13 +235,13 @@ const StartWithInputFile = async (inputFile) => {
console.log('Run with --verbose to see the config file here.');
}

return StartServer(null, config);
return startServer(null, config);
});
});
}
};

fs.stat(path.resolve(opts.config), (err, stats) => {
fs.stat(path.resolve(opts.config), async (err, stats) => {

Check warning on line 244 in src/main.js

View workflow job for this annotation

GitHub Actions / ESLint

src/main.js#L244

Found stat from package "node:fs" with non literal argument at index 0 (security/detect-non-literal-fs-filename)
if (err || !stats.isFile() || stats.size === 0) {
let inputFile;
if (opts.file) {
Expand All @@ -251,7 +251,7 @@ fs.stat(path.resolve(opts.config), (err, stats) => {
}

if (inputFile) {
return StartWithInputFile(inputFile);
return startWithInputFile(inputFile);
} else {
// try to find in the cwd
const files = fs.readdirSync(process.cwd());
Expand All @@ -266,33 +266,34 @@ fs.stat(path.resolve(opts.config), (err, stats) => {
}
if (inputFile) {
console.log(`No input file specified, using ${inputFile}`);
return StartWithInputFile(inputFile);
return startWithInputFile(inputFile);
} else {
const url =
'https://github.com/maptiler/tileserver-gl/releases/download/v1.3.0/zurich_switzerland.mbtiles';
const filename = 'zurich_switzerland.mbtiles';
const writer = fs.createWriteStream(filename);
console.log(`No input file found`);
console.log(`[DEMO] Downloading sample data (${filename}) from ${url}`);
axios({
url,
method: 'GET',
responseType: 'stream',
})
.then((response) => {
response.data.pipe(writer);
writer.on('finish', () => StartWithInputFile(filename));
writer.on('error', (err) =>
console.error(`Error writing file: ${err}`),
);
})
.catch((error) => {
console.error(`Error downloading file: ${error}`);

try {
const response = await axios({
url,
method: 'GET',
responseType: 'stream',
});

response.data.pipe(writer);
writer.on('finish', () => startWithInputFile(filename));
writer.on('error', (err) =>
console.error(`Error writing file: ${err}`),
);
} catch (error) {
console.error(`Error downloading file: ${error}`);
}
}
}
} else {
console.log(`Using specified config file from ${opts.config}`);
return StartServer(opts.config, null);
return startServer(opts.config, null);
}
});
Loading

0 comments on commit 98ebbba

Please sign in to comment.