From 4914555c0cf62cc7c0890466b120ac32762cbfc7 Mon Sep 17 00:00:00 2001 From: Andrew Calcutt Date: Fri, 19 Jan 2024 13:26:58 -0500 Subject: [PATCH] fix: lint Signed-off-by: Andrew Calcutt --- src/serve_rendered.js | 6 ++++-- src/utils.js | 18 +++++++++++++++--- test/tiles_rendered.js | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/src/serve_rendered.js b/src/serve_rendered.js index db0f877..36d3290 100644 --- a/src/serve_rendered.js +++ b/src/serve_rendered.js @@ -531,7 +531,9 @@ export const serve_rendered = { 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]; if (!item) { return res.sendStatus(404); @@ -565,7 +567,7 @@ export const serve_rendered = { const tileCenter = mercator.ll( [ ((x + 0.5) / (1 << z)) * (tileSize << z), - ((y + 0.5) / (1 << z)) * (tileSize << z) + ((y + 0.5) / (1 << z)) * (tileSize << z), ], z, ); diff --git a/src/utils.js b/src/utils.js index 2b3de7a..aa1509f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -26,7 +26,15 @@ export const getPublicUrl = (publicUrl, req) => { 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); if (domains) { 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}'; if (['png', 'jpg', 'jpeg', 'webp'].includes(format)) { - if(tileSize) {tileParams = '{tileSize}/{z}/{x}/{y}';} + if (tileSize) { + tileParams = '{tileSize}/{z}/{x}/{y}'; + } } const uris = []; if (!publicUrl) { for (const domain of domains) { - uris.push(`${req.protocol}://${domain}/${path}/${tileParams}.${format}${query}`); + uris.push( + `${req.protocol}://${domain}/${path}/${tileParams}.${format}${query}`, + ); } } else { uris.push(`${publicUrl}${path}/${tileParams}.${format}${query}`); diff --git a/test/tiles_rendered.js b/test/tiles_rendered.js index b0d2d68..8e00900 100644 --- a/test/tiles_rendered.js +++ b/test/tiles_rendered.js @@ -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'; - var path = '/styles/' + prefix + '/' + tileSize + '/' + z + '/' + x + '/' + y + '.' + format; - it(path + ' returns ' + status, function(done) { + var path = + '/styles/' + + prefix + + '/' + + tileSize + + '/' + + z + + '/' + + x + + '/' + + y + + '.' + + format; + it(path + ' returns ' + status, function (done) { var test = supertest(app).get(path); test.expect(status); 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'; -describe('Raster tiles', function() { - describe('valid requests', function() { - describe('various formats', function() { +describe('Raster tiles', function () { + describe('valid requests', function () { + describe('various formats', function () { testTile(prefix, 256, 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/); @@ -24,7 +46,7 @@ describe('Raster tiles', function() { 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, 512, 1, 1, 1, 'png', 200); 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(prefix, 256, -1, 0, 0, 'png', 404); testTile(prefix, 256, 25, 0, 0, 'png', 404);