From 8cf2b9b5235a4c0213356adfadc9729e3808b843 Mon Sep 17 00:00:00 2001 From: HF Date: Mon, 2 Aug 2021 00:02:41 +0200 Subject: [PATCH] handle redis chunk rejection --- src/routes/chunks.js | 8 +++++++- src/routes/tiles.js | 49 -------------------------------------------- 2 files changed, 7 insertions(+), 50 deletions(-) diff --git a/src/routes/chunks.js b/src/routes/chunks.js index aec3d78..5bd6a14 100644 --- a/src/routes/chunks.js +++ b/src/routes/chunks.js @@ -37,10 +37,16 @@ export default async (req: Request, res: Response, next) => { return; } + let chunk; // z is in preeration for 3d chunks that are also // divided in height, which is not used yet // - this is not used and probably won't ever be used - const chunk = await RedisCanvas.getChunk(c, x, y, z); + try { + chunk = await RedisCanvas.getChunk(c, x, y, z); + } catch { + res.status(503).end(); + return; + } res.set({ 'Cache-Control': `public, s-maxage=${60}, max-age=${50}`, // seconds diff --git a/src/routes/tiles.js b/src/routes/tiles.js index a457406..4594cd4 100644 --- a/src/routes/tiles.js +++ b/src/routes/tiles.js @@ -9,59 +9,10 @@ import express from 'express'; import type { Request, Response } from 'express'; import { TILE_FOLDER } from '../core/config'; import { HOUR } from '../core/constants'; -// import sharp from 'sharp'; -// import { TILE_SIZE, HOUR } from '../core/constants'; -// import RedisCanvas from '../data/models/RedisCanvas'; const router = express.Router(); - -/* - * send chunk, but as png - * This might be handy in the future if we decide to - * provide more zoomlevels to support GoogleMaps / OSM APIs -async function basetile(req: Request, res: Response, next) { - const { c: paramC, x: paramX, y: paramY } = req.params; - const x = parseInt(paramX, 10); - const y = parseInt(paramY, 10); - try { - let tile = await RedisCanvas.getChunk(c, x, y); - - res.set({ - 'Cache-Control': `public, s-maxage=${5 * 60}, max-age=${3 * 60}`, // seconds - }); - - if (!tile) { - res.status(200).end(); - return; - } - - //note that we have to initialize the palette somewhere, if we decide to use it - const tileRGB = palette.buffer2RGB(tile); - tile = null; - const tilePng = await sharp(Buffer.from(tileRGB.buffer), { raw: { width: TILE_SIZE, height: TILE_SIZE, channels: 3 } }) - .png({ options: { compressionLevel: 0, palette: true, quality: 16, colors: 16, dither: 0.0 } }) - .toBuffer(); - res.set({ - 'Content-Type': 'image/png', - }); - - res.status(200).send(tilePng); - } catch (error) { - next(error); - } -} - - -// get basetiles from redis -// note that MAX_TILED_ZOOM is not an available constant anymore, sinze different -// canvases can have different sizes. If this should be reenabled, you have to find another -// solution for that here. -router.get(`/:c([a-z]+)/${MAX_TILED_ZOOM}/:x([0-9]+)/:y(-?[0-9]+).png`, basetile); -*/ - - /* * get other tiles from directory */