fix: allow old sprite endpoints to work
Signed-off-by: Andrew Calcutt <acalcutt@techidiots.net>
This commit is contained in:
parent
a5f3b1488a
commit
92b528498d
1 changed files with 6 additions and 7 deletions
|
@ -56,8 +56,9 @@ export const serve_style = {
|
||||||
return res.send(styleJSON_);
|
return res.send(styleJSON_);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/:id/sprite/:name:scale(@[23]x)?.:format([\\w]+)', (req, res, next) => {
|
app.get('/:id/sprite(/:name)?:scale(@[23]x)?.:format([\\w]+)', (req, res, next) => {
|
||||||
const item = repo[req.params.id];
|
const item = repo[req.params.id];
|
||||||
|
const spriteName = req.params.name || 'sprite';
|
||||||
|
|
||||||
if (!item || !item.spritePaths) {
|
if (!item || !item.spritePaths) {
|
||||||
return res.sendStatus(404);
|
return res.sendStatus(404);
|
||||||
|
@ -65,7 +66,7 @@ export const serve_style = {
|
||||||
|
|
||||||
let spritePath
|
let spritePath
|
||||||
for (const sprite of item.spritePaths) {
|
for (const sprite of item.spritePaths) {
|
||||||
if (sprite.name === req.params.name) {
|
if (sprite.name === spriteName) {
|
||||||
spritePath = sprite.path;
|
spritePath = sprite.path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,13 +155,12 @@ export const serve_style = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let spriteName
|
|
||||||
let spritePaths = [];
|
let spritePaths = [];
|
||||||
if (styleJSON.sprite && styleJSON.sprite) {
|
if (styleJSON.sprite && styleJSON.sprite) {
|
||||||
if (Array.isArray(styleJSON.sprite)) {
|
if (Array.isArray(styleJSON.sprite)) {
|
||||||
styleJSON.sprite.forEach((spriteItem) => {
|
styleJSON.sprite.forEach((spriteItem) => {
|
||||||
if (!httpTester.test(spriteItem.url)) {
|
if (!httpTester.test(spriteItem.url)) {
|
||||||
spriteName = spriteItem.url.substring(spriteItem.url.lastIndexOf('/') + 1);
|
let spriteName = spriteItem.url.substring(spriteItem.url.lastIndexOf('/') + 1);
|
||||||
let spritePath = path.join(
|
let spritePath = path.join(
|
||||||
options.paths.sprites,
|
options.paths.sprites,
|
||||||
spriteItem.url
|
spriteItem.url
|
||||||
|
@ -176,7 +176,6 @@ export const serve_style = {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (!httpTester.test(styleJSON.sprite)) {
|
if (!httpTester.test(styleJSON.sprite)) {
|
||||||
spriteName = styleJSON.sprite.substring(styleJSON.sprite.lastIndexOf('/') + 1);
|
|
||||||
let spritePath = path.join(
|
let spritePath = path.join(
|
||||||
options.paths.sprites,
|
options.paths.sprites,
|
||||||
styleJSON.sprite
|
styleJSON.sprite
|
||||||
|
@ -186,8 +185,8 @@ export const serve_style = {
|
||||||
path.relative(options.paths.sprites, path.dirname(styleFile))
|
path.relative(options.paths.sprites, path.dirname(styleFile))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
styleJSON.sprite = `local://styles/${id}/sprite/` + spriteName;
|
styleJSON.sprite = `local://styles/${id}/sprite`;
|
||||||
spritePaths.push({id: 'default', name: spriteName, path: spritePath});
|
spritePaths.push({id: 'default', name: 'sprite', path: spritePath});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue