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