style: Update block search API to accept 'name' parameter as an alternative to 'pattern'

This commit is contained in:
MayaTheShy
2026-02-20 02:50:09 -05:00
parent fe44978f6e
commit a68ddd843f

View File

@@ -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) {