style: Update block search API to accept 'name' parameter as an alternative to 'pattern'
This commit is contained in:
@@ -1036,14 +1036,15 @@ app.post('/api/chunks', (req, res) => {
|
|||||||
// Search blocks by name pattern in area
|
// Search blocks by name pattern in area
|
||||||
app.get('/api/world/blocks/search', (req, res) => {
|
app.get('/api/world/blocks/search', (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { fromX, fromY, fromZ, toX, toY, toZ, pattern } = req.query;
|
const { fromX, fromY, fromZ, toX, toY, toZ, pattern, name } = req.query;
|
||||||
if (!pattern) {
|
const searchPattern = pattern || name;
|
||||||
return res.status(400).json({ error: 'Missing pattern parameter' });
|
if (!searchPattern) {
|
||||||
|
return res.status(400).json({ error: 'Missing pattern or name parameter' });
|
||||||
}
|
}
|
||||||
const blocks = db.getBlocksWithNameLike(
|
const blocks = db.getBlocksWithNameLike(
|
||||||
parseInt(fromX) || -1000, parseInt(fromY) || -64, parseInt(fromZ) || -1000,
|
parseInt(fromX) || -1000, parseInt(fromY) || -64, parseInt(fromZ) || -1000,
|
||||||
parseInt(toX) || 1000, parseInt(toY) || 320, parseInt(toZ) || 1000,
|
parseInt(toX) || 1000, parseInt(toY) || 320, parseInt(toZ) || 1000,
|
||||||
pattern
|
searchPattern
|
||||||
);
|
);
|
||||||
res.json({ blocks });
|
res.json({ blocks });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user