fix: lint
Signed-off-by: Andrew Calcutt <acalcutt@techidiots.net>
This commit is contained in:
parent
c35035b9c1
commit
4914555c0c
3 changed files with 49 additions and 13 deletions
|
|
@ -531,7 +531,9 @@ export const serve_rendered = {
|
||||||
|
|
||||||
const app = express().disable('x-powered-by');
|
const app = express().disable('x-powered-by');
|
||||||
|
|
||||||
app.get(`/:id/:tileSize(256|512)/:z(\\d+)/:x(\\d+)/:y(\\d+):scale(${scalePattern})?.:format([\\w]+)`, (req, res, next) => {
|
app.get(
|
||||||
|
`/:id/:tileSize(256|512)/:z(\\d+)/:x(\\d+)/:y(\\d+):scale(${scalePattern})?.:format([\\w]+)`,
|
||||||
|
(req, res, next) => {
|
||||||
const item = repo[req.params.id];
|
const item = repo[req.params.id];
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return res.sendStatus(404);
|
return res.sendStatus(404);
|
||||||
|
|
@ -565,7 +567,7 @@ export const serve_rendered = {
|
||||||
const tileCenter = mercator.ll(
|
const tileCenter = mercator.ll(
|
||||||
[
|
[
|
||||||
((x + 0.5) / (1 << z)) * (tileSize << z),
|
((x + 0.5) / (1 << z)) * (tileSize << z),
|
||||||
((y + 0.5) / (1 << z)) * (tileSize << z)
|
((y + 0.5) / (1 << z)) * (tileSize << z),
|
||||||
],
|
],
|
||||||
z,
|
z,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
18
src/utils.js
18
src/utils.js
|
|
@ -26,7 +26,15 @@ export const getPublicUrl = (publicUrl, req) => {
|
||||||
return getUrlObject(req).toString();
|
return getUrlObject(req).toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTileUrls = (req, domains, path, tileSize, format, publicUrl, aliases) => {
|
export const getTileUrls = (
|
||||||
|
req,
|
||||||
|
domains,
|
||||||
|
path,
|
||||||
|
tileSize,
|
||||||
|
format,
|
||||||
|
publicUrl,
|
||||||
|
aliases,
|
||||||
|
) => {
|
||||||
const urlObject = getUrlObject(req);
|
const urlObject = getUrlObject(req);
|
||||||
if (domains) {
|
if (domains) {
|
||||||
if (domains.constructor === String && domains.length > 0) {
|
if (domains.constructor === String && domains.length > 0) {
|
||||||
|
|
@ -69,13 +77,17 @@ export const getTileUrls = (req, domains, path, tileSize, format, publicUrl, ali
|
||||||
|
|
||||||
let tileParams = '{z}/{x}/{y}';
|
let tileParams = '{z}/{x}/{y}';
|
||||||
if (['png', 'jpg', 'jpeg', 'webp'].includes(format)) {
|
if (['png', 'jpg', 'jpeg', 'webp'].includes(format)) {
|
||||||
if(tileSize) {tileParams = '{tileSize}/{z}/{x}/{y}';}
|
if (tileSize) {
|
||||||
|
tileParams = '{tileSize}/{z}/{x}/{y}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const uris = [];
|
const uris = [];
|
||||||
if (!publicUrl) {
|
if (!publicUrl) {
|
||||||
for (const domain of domains) {
|
for (const domain of domains) {
|
||||||
uris.push(`${req.protocol}://${domain}/${path}/${tileParams}.${format}${query}`);
|
uris.push(
|
||||||
|
`${req.protocol}://${domain}/${path}/${tileParams}.${format}${query}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uris.push(`${publicUrl}${path}/${tileParams}.${format}${query}`);
|
uris.push(`${publicUrl}${path}/${tileParams}.${format}${query}`);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,29 @@
|
||||||
var testTile = function(prefix, tileSize = 256, z, x, y, format, status, scale, type) {
|
var testTile = function (
|
||||||
|
prefix,
|
||||||
|
tileSize = 256,
|
||||||
|
z,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
format,
|
||||||
|
status,
|
||||||
|
scale,
|
||||||
|
type,
|
||||||
|
) {
|
||||||
if (scale) y += '@' + scale + 'x';
|
if (scale) y += '@' + scale + 'x';
|
||||||
var path = '/styles/' + prefix + '/' + tileSize + '/' + z + '/' + x + '/' + y + '.' + format;
|
var path =
|
||||||
it(path + ' returns ' + status, function(done) {
|
'/styles/' +
|
||||||
|
prefix +
|
||||||
|
'/' +
|
||||||
|
tileSize +
|
||||||
|
'/' +
|
||||||
|
z +
|
||||||
|
'/' +
|
||||||
|
x +
|
||||||
|
'/' +
|
||||||
|
y +
|
||||||
|
'.' +
|
||||||
|
format;
|
||||||
|
it(path + ' returns ' + status, function (done) {
|
||||||
var test = supertest(app).get(path);
|
var test = supertest(app).get(path);
|
||||||
test.expect(status);
|
test.expect(status);
|
||||||
if (type) test.expect('Content-Type', type);
|
if (type) test.expect('Content-Type', type);
|
||||||
|
|
@ -11,9 +33,9 @@ var testTile = function(prefix, tileSize = 256, z, x, y, format, status, scale,
|
||||||
|
|
||||||
const prefix = 'test-style';
|
const prefix = 'test-style';
|
||||||
|
|
||||||
describe('Raster tiles', function() {
|
describe('Raster tiles', function () {
|
||||||
describe('valid requests', function() {
|
describe('valid requests', function () {
|
||||||
describe('various formats', function() {
|
describe('various formats', function () {
|
||||||
testTile(prefix, 256, 0, 0, 0, 'png', 200, undefined, /image\/png/);
|
testTile(prefix, 256, 0, 0, 0, 'png', 200, undefined, /image\/png/);
|
||||||
testTile(prefix, 512, 0, 0, 0, 'png', 200, undefined, /image\/png/);
|
testTile(prefix, 512, 0, 0, 0, 'png', 200, undefined, /image\/png/);
|
||||||
testTile(prefix, 256, 0, 0, 0, 'jpg', 200, undefined, /image\/jpeg/);
|
testTile(prefix, 256, 0, 0, 0, 'jpg', 200, undefined, /image\/jpeg/);
|
||||||
|
|
@ -24,7 +46,7 @@ describe('Raster tiles', function() {
|
||||||
testTile(prefix, 512, 0, 0, 0, 'webp', 200, undefined, /image\/webp/);
|
testTile(prefix, 512, 0, 0, 0, 'webp', 200, undefined, /image\/webp/);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('different coordinates and scales', function() {
|
describe('different coordinates and scales', function () {
|
||||||
testTile(prefix, 256, 1, 1, 1, 'png', 200);
|
testTile(prefix, 256, 1, 1, 1, 'png', 200);
|
||||||
testTile(prefix, 512, 1, 1, 1, 'png', 200);
|
testTile(prefix, 512, 1, 1, 1, 'png', 200);
|
||||||
testTile(prefix, 256, 0, 0, 0, 'png', 200, 2);
|
testTile(prefix, 256, 0, 0, 0, 'png', 200, 2);
|
||||||
|
|
@ -36,7 +58,7 @@ describe('Raster tiles', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('invalid requests return 4xx', function() {
|
describe('invalid requests return 4xx', function () {
|
||||||
testTile('non_existent', 256, 0, 0, 0, 'png', 404);
|
testTile('non_existent', 256, 0, 0, 0, 'png', 404);
|
||||||
testTile(prefix, 256, -1, 0, 0, 'png', 404);
|
testTile(prefix, 256, -1, 0, 0, 'png', 404);
|
||||||
testTile(prefix, 256, 25, 0, 0, 'png', 404);
|
testTile(prefix, 256, 25, 0, 0, 'png', 404);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue