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
|
||||
app.get('/api/world/blocks/search', (req, res) => {
|
||||
try {
|
||||
const { fromX, fromY, fromZ, toX, toY, toZ, pattern } = req.query;
|
||||
if (!pattern) {
|
||||
return res.status(400).json({ error: 'Missing pattern parameter' });
|
||||
const { fromX, fromY, fromZ, toX, toY, toZ, pattern, name } = req.query;
|
||||
const searchPattern = pattern || name;
|
||||
if (!searchPattern) {
|
||||
return res.status(400).json({ error: 'Missing pattern or name parameter' });
|
||||
}
|
||||
const blocks = db.getBlocksWithNameLike(
|
||||
parseInt(fromX) || -1000, parseInt(fromY) || -64, parseInt(fromZ) || -1000,
|
||||
parseInt(toX) || 1000, parseInt(toY) || 320, parseInt(toZ) || 1000,
|
||||
pattern
|
||||
searchPattern
|
||||
);
|
||||
res.json({ blocks });
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user