try to fix errors
This commit is contained in:
parent
8e07336ec2
commit
10cd6433f6
6 changed files with 101 additions and 76 deletions
|
@ -25,8 +25,12 @@ export default [
|
||||||
globals: {
|
globals: {
|
||||||
...globals.node, // Add Node.js globals
|
...globals.node, // Add Node.js globals
|
||||||
...globals.browser, // Add browser globals
|
...globals.browser, // Add browser globals
|
||||||
...globals.es6, // Add ES6 globals (if not already included)
|
...globals.es6, // Add ES6 globals
|
||||||
// ...js.configs.recommended.languageOptions?.globals, // Remove if you want to completely rely on globals package
|
...globals.mocha, // Add Mocha globals (describe, it, before, after, etc.)
|
||||||
|
supertest: 'readonly', // Mark supertest as a global read-only variable
|
||||||
|
expect: 'readonly', // Mark expect as a global read-only variable if your assertion library isn't automatically detected
|
||||||
|
app: 'readonly', // Mark app as a global read-only variable
|
||||||
|
server: 'readonly', // Mark server as a global read-only variable
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -29,8 +29,8 @@ const packageJson = JSON.parse(
|
||||||
);
|
);
|
||||||
|
|
||||||
const isLight = packageJson.name.slice(-6) === '-light';
|
const isLight = packageJson.name.slice(-6) === '-light';
|
||||||
const serve_rendered = (
|
const serve_rendered = import(
|
||||||
await import(`${!isLight ? `./serve_rendered.js` : `./serve_light.js`}`)
|
`${!isLight ? `./serve_rendered.js` : `./serve_light.js`}`
|
||||||
).serve_rendered;
|
).serve_rendered;
|
||||||
|
|
||||||
export const serve_data = {
|
export const serve_data = {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
||||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ const staticTypeRegex = new RegExp(
|
||||||
);
|
);
|
||||||
|
|
||||||
const PATH_PATTERN =
|
const PATH_PATTERN =
|
||||||
/^((fill|stroke|width)\:[^\|]+\|)*(enc:.+|-?\d+(\.\d*)?,-?\d+(\.\d*)?(\|-?\d+(\.\d*)?,-?\d+(\.\d*)?)+)/;
|
/^((fill|stroke|width):[^|]+\|)*(enc:.+|-?\d+(\.\d*)?,-?\d+(\.\d*)?(\|-?\d+(\.\d*)?,-?\d+(\.\d*)?)+)/;
|
||||||
const httpTester = /^https?:\/\//i;
|
const httpTester = /^https?:\/\//i;
|
||||||
|
|
||||||
const mercator = new SphericalMercator();
|
const mercator = new SphericalMercator();
|
||||||
|
@ -273,7 +273,7 @@ function parseMarkerOptions(optionsList, marker) {
|
||||||
break;
|
break;
|
||||||
// Icon offset as positive or negative pixel value in the following
|
// Icon offset as positive or negative pixel value in the following
|
||||||
// format [offsetX],[offsetY] where [offsetY] is optional
|
// format [offsetX],[offsetY] where [offsetY] is optional
|
||||||
case 'offset':
|
case 'offset': {
|
||||||
const providedOffset = optionParts[1].split(',');
|
const providedOffset = optionParts[1].split(',');
|
||||||
// Set X-axis offset
|
// Set X-axis offset
|
||||||
marker.offsetX = parseFloat(providedOffset[0]);
|
marker.offsetX = parseFloat(providedOffset[0]);
|
||||||
|
@ -285,6 +285,7 @@ function parseMarkerOptions(optionsList, marker) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses markers provided via query into a list of marker objects.
|
* Parses markers provided via query into a list of marker objects.
|
||||||
|
@ -452,6 +453,7 @@ async function respondImage(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format === 'png' || format === 'webp') {
|
if (format === 'png' || format === 'webp') {
|
||||||
|
/* empty */
|
||||||
} else if (format === 'jpg' || format === 'jpeg') {
|
} else if (format === 'jpg' || format === 'jpeg') {
|
||||||
format = 'jpeg';
|
format = 'jpeg';
|
||||||
} else {
|
} else {
|
||||||
|
@ -1486,9 +1488,10 @@ export const serve_rendered = {
|
||||||
* @returns {object}
|
* @returns {object}
|
||||||
*/
|
*/
|
||||||
getTerrainElevation: async function (data, param) {
|
getTerrainElevation: async function (data, param) {
|
||||||
return await new Promise(async (resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const image = new Image();
|
const image = new Image(); // Create a new Image object
|
||||||
image.onload = async () => {
|
image.onload = () => {
|
||||||
|
try {
|
||||||
const canvas = createCanvas(param['tile_size'], param['tile_size']);
|
const canvas = createCanvas(param['tile_size'], param['tile_size']);
|
||||||
const context = canvas.getContext('2d');
|
const context = canvas.getContext('2d');
|
||||||
context.drawImage(image, 0, 0);
|
context.drawImage(image, 0, 0);
|
||||||
|
@ -1509,8 +1512,10 @@ export const serve_rendered = {
|
||||||
const xTile = Math.floor((xWorld * scale) / param['tile_size']);
|
const xTile = Math.floor((xWorld * scale) / param['tile_size']);
|
||||||
const yTile = Math.floor((yWorld * scale) / param['tile_size']);
|
const yTile = Math.floor((yWorld * scale) / param['tile_size']);
|
||||||
|
|
||||||
const xPixel = Math.floor(xWorld * scale) - xTile * param['tile_size'];
|
const xPixel =
|
||||||
const yPixel = Math.floor(yWorld * scale) - yTile * param['tile_size'];
|
Math.floor(xWorld * scale) - xTile * param['tile_size'];
|
||||||
|
const yPixel =
|
||||||
|
Math.floor(yWorld * scale) - yTile * param['tile_size'];
|
||||||
if (
|
if (
|
||||||
xPixel < 0 ||
|
xPixel < 0 ||
|
||||||
yPixel < 0 ||
|
yPixel < 0 ||
|
||||||
|
@ -1536,18 +1541,25 @@ export const serve_rendered = {
|
||||||
param['green'] = green;
|
param['green'] = green;
|
||||||
param['blue'] = blue;
|
param['blue'] = blue;
|
||||||
resolve(param);
|
resolve(param);
|
||||||
|
} catch (error) {
|
||||||
|
reject(error); // Catch any errors during canvas operations
|
||||||
|
}
|
||||||
};
|
};
|
||||||
image.onerror = (err) => reject(err);
|
image.onerror = (err) => reject(err);
|
||||||
if (param['format'] === 'webp') {
|
|
||||||
|
// Load the image data - handle the sharp conversion outside the Promise
|
||||||
|
(async () => {
|
||||||
try {
|
try {
|
||||||
|
if (param['format'] === 'webp') {
|
||||||
const img = await sharp(data).toFormat('png').toBuffer();
|
const img = await sharp(data).toFormat('png').toBuffer();
|
||||||
image.src = img;
|
image.src = `data:image/png;base64,${img.toString('base64')}`; // Set data URL
|
||||||
} catch (err) {
|
|
||||||
reject(err);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
image.src = data;
|
image.src = data;
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
reject(err); // Reject promise on sharp error
|
||||||
|
}
|
||||||
|
})();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,8 +30,8 @@ const packageJson = JSON.parse(
|
||||||
);
|
);
|
||||||
const isLight = packageJson.name.slice(-6) === '-light';
|
const isLight = packageJson.name.slice(-6) === '-light';
|
||||||
|
|
||||||
const serve_rendered = (
|
const serve_rendered = import(
|
||||||
await import(`${!isLight ? `./serve_rendered.js` : `./serve_light.js`}`)
|
`${!isLight ? `./serve_rendered.js` : `./serve_light.js`}`
|
||||||
).serve_rendered;
|
).serve_rendered;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,13 +148,19 @@ async function start(opts) {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let dataDecoratorFunc = null; // Initialize to null
|
||||||
if (options.dataDecorator) {
|
if (options.dataDecorator) {
|
||||||
try {
|
try {
|
||||||
options.dataDecoratorFunc = require(
|
const dataDecoratorPath = path.resolve(paths.root, options.dataDecorator);
|
||||||
path.resolve(paths.root, options.dataDecorator),
|
const module = await import(dataDecoratorPath);
|
||||||
);
|
dataDecoratorFunc = module.default;
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
console.error(`Error loading data decorator: ${e}`);
|
||||||
|
// Handle the error (e.g., set a default decorator)
|
||||||
|
dataDecoratorFunc = null; // Or a default function
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
options.dataDecoratorFunc = dataDecoratorFunc;
|
||||||
|
|
||||||
const data = clone(config.data || {});
|
const data = clone(config.data || {});
|
||||||
|
|
||||||
|
@ -671,7 +677,7 @@ async function start(opts) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wmts.hasOwnProperty('serve_rendered') && !wmts.serve_rendered) {
|
if (Object.hasOwn(wmts, 'serve_rendered') && !wmts.serve_rendered) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
src/utils.js
24
src/utils.js
|
@ -35,7 +35,6 @@ export function allowedScales(scale, maxScale = 9) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
||||||
const regex = new RegExp(`^[2-${maxScale}]x$`);
|
const regex = new RegExp(`^[2-${maxScale}]x$`);
|
||||||
if (!regex.test(scale)) {
|
if (!regex.test(scale)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -152,7 +151,7 @@ export function getTileUrls(
|
||||||
const hostParts = urlObject.host.split('.');
|
const hostParts = urlObject.host.split('.');
|
||||||
const relativeSubdomainsUsable =
|
const relativeSubdomainsUsable =
|
||||||
hostParts.length > 1 &&
|
hostParts.length > 1 &&
|
||||||
!/^([0-9]{1,3}\.){3}[0-9]{1,3}(\:[0-9]+)?$/.test(urlObject.host);
|
!/^([0-9]{1,3}\.){3}[0-9]{1,3}(:[0-9]+)?$/.test(urlObject.host);
|
||||||
const newDomains = [];
|
const newDomains = [];
|
||||||
for (const domain of domains) {
|
for (const domain of domains) {
|
||||||
if (domain.indexOf('*') !== -1) {
|
if (domain.indexOf('*') !== -1) {
|
||||||
|
@ -238,7 +237,7 @@ export function fixTileJSONCenter(tileJSON) {
|
||||||
export function readFile(filename) {
|
export function readFile(filename) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const sanitizedFilename = path.normalize(filename); // Normalize path, remove ..
|
const sanitizedFilename = path.normalize(filename); // Normalize path, remove ..
|
||||||
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
||||||
fs.readFile(String(sanitizedFilename), (err, data) => {
|
fs.readFile(String(sanitizedFilename), (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
|
@ -260,7 +259,7 @@ export function readFile(filename) {
|
||||||
*/
|
*/
|
||||||
async function getFontPbf(allowedFonts, fontPath, name, range, fallbacks) {
|
async function getFontPbf(allowedFonts, fontPath, name, range, fallbacks) {
|
||||||
if (!allowedFonts || (allowedFonts[name] && fallbacks)) {
|
if (!allowedFonts || (allowedFonts[name] && fallbacks)) {
|
||||||
const fontMatch = name?.match(/^[\p{L}\p{N} \-\.~!*'()@&=+,#$\[\]]+$/u);
|
const fontMatch = name?.match(/^[\p{L}\p{N} \-.~!*'()@&=+,#$[\]]+$/u);
|
||||||
const sanitizedName = fontMatch?.[0] || 'invalid';
|
const sanitizedName = fontMatch?.[0] || 'invalid';
|
||||||
if (!name || typeof name !== 'string' || name.trim() === '' || !fontMatch) {
|
if (!name || typeof name !== 'string' || name.trim() === '' || !fontMatch) {
|
||||||
console.error(
|
console.error(
|
||||||
|
@ -394,7 +393,8 @@ export function isValidHttpUrl(string) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
url = new URL(string);
|
url = new URL(string);
|
||||||
} catch (_) {
|
} catch (e) {
|
||||||
|
void e;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,15 +412,19 @@ export function isValidHttpUrl(string) {
|
||||||
*/
|
*/
|
||||||
export async function fetchTileData(source, sourceType, z, x, y) {
|
export async function fetchTileData(source, sourceType, z, x, y) {
|
||||||
if (sourceType === 'pmtiles') {
|
if (sourceType === 'pmtiles') {
|
||||||
return await new Promise(async (resolve) => {
|
try {
|
||||||
const tileinfo = await getPMtilesTile(source, z, x, y);
|
const tileinfo = await getPMtilesTile(source, z, x, y);
|
||||||
if (!tileinfo?.data) return resolve(null);
|
if (!tileinfo?.data) return null;
|
||||||
resolve({ data: tileinfo.data, headers: tileinfo.header });
|
return { data: tileinfo.data, headers: tileinfo.header };
|
||||||
});
|
} catch (error) {
|
||||||
|
console.error('Error fetching PMTiles tile:', error);
|
||||||
|
return null; // Or throw the error if you want to propagate it
|
||||||
|
}
|
||||||
} else if (sourceType === 'mbtiles') {
|
} else if (sourceType === 'mbtiles') {
|
||||||
return await new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
source.getTile(z, x, y, (err, tileData, tileHeader) => {
|
source.getTile(z, x, y, (err, tileData, tileHeader) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
console.error('Error fetching MBTiles tile:', err);
|
||||||
return resolve(null);
|
return resolve(null);
|
||||||
}
|
}
|
||||||
resolve({ data: tileData, headers: tileHeader });
|
resolve({ data: tileData, headers: tileHeader });
|
||||||
|
|
Loading…
Reference in a new issue