handle redis chunk rejection
This commit is contained in:
parent
88a63e4387
commit
8cf2b9b523
|
@ -37,10 +37,16 @@ export default async (req: Request, res: Response, next) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let chunk;
|
||||||
// z is in preeration for 3d chunks that are also
|
// z is in preeration for 3d chunks that are also
|
||||||
// divided in height, which is not used yet
|
// divided in height, which is not used yet
|
||||||
// - this is not used and probably won't ever be used
|
// - 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({
|
res.set({
|
||||||
'Cache-Control': `public, s-maxage=${60}, max-age=${50}`, // seconds
|
'Cache-Control': `public, s-maxage=${60}, max-age=${50}`, // seconds
|
||||||
|
|
|
@ -9,59 +9,10 @@ import express from 'express';
|
||||||
import type { Request, Response } from 'express';
|
import type { Request, Response } from 'express';
|
||||||
import { TILE_FOLDER } from '../core/config';
|
import { TILE_FOLDER } from '../core/config';
|
||||||
import { HOUR } from '../core/constants';
|
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();
|
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
|
* get other tiles from directory
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user