#19, added tags, and tags filtering
This commit is contained in:
@@ -31,6 +31,7 @@ class Db {
|
||||
await dbo.createCollection(c);
|
||||
}catch(err){}
|
||||
}
|
||||
await dbo.collection('assets').createIndex({ name: 'text', 'description': 'text', tags: 'text' }, {name:'fts', default_language: "none" });
|
||||
}finally{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ const execFile = util.promisify(npExecFile);
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import Utils from "../Utils.js";
|
||||
|
||||
const collection = 'assets';
|
||||
|
||||
/**
|
||||
@@ -144,6 +146,11 @@ class GameObjectsManager{
|
||||
project: { name:1, id:1, type:1, asset:1}
|
||||
});
|
||||
}
|
||||
|
||||
this.getTags = async function(q){
|
||||
let objects = await db.distinct(collection, 'tags', q ? {tags: {$regex: Utils.escapeRegExp(q), $options: 'i'}} : {});
|
||||
return objects;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,7 @@ class GameObjectsController{
|
||||
* @param {App} app The application instance, апликация
|
||||
*/
|
||||
init(app){
|
||||
const { gameObject, am } = app;
|
||||
const { gameObject, am, db } = app;
|
||||
const router = express.Router();
|
||||
|
||||
/**
|
||||
@@ -26,7 +26,7 @@ class GameObjectsController{
|
||||
*/
|
||||
router.put('/', multipartMiddleware, async (req, res)=>{
|
||||
try{
|
||||
let data = req.body;
|
||||
let data = JSON.parse(req.body.object);
|
||||
let action = data.id ? 'update' : 'create';
|
||||
let object = await gameObject[action](req, data)
|
||||
res.json({status: 'OK', object});
|
||||
@@ -45,11 +45,16 @@ class GameObjectsController{
|
||||
* @memberof GameObjectsController
|
||||
*/
|
||||
router.post('/', async (req, res)=>{
|
||||
let result = await gameObject.list(req.body);
|
||||
let result = await gameObject.list(db.sanitizeQuery(req.body));
|
||||
res.json(result);
|
||||
am.audit(req, `game-object-list`, null, {q: req.body});
|
||||
})
|
||||
|
||||
router.post('/tags', async (req, res)=>{
|
||||
let tags = await gameObject.getTags(req.body.q);
|
||||
res.json(tags);
|
||||
})
|
||||
|
||||
/**
|
||||
* API: GET /api/game-object/:id Retrieve game object by ID, извличане на обект по идентификатор
|
||||
* @function read
|
||||
|
||||
Reference in New Issue
Block a user