Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const makeModelsController = (
radiksCollection: Collection,
config: Config,
emitter: EventEmitter
) => {
const ModelsController = addAsync(express.Router());
ModelsController.use(bodyParser.json());
ModelsController.postAsync('/crawl', async (req, res) => {
const { gaiaURL } = req.body;
const attrs = await request({
uri: gaiaURL,
json: true,
});
const validator = new Validator(radiksCollection, attrs);
try {
await validator.validate();
await radiksCollection.save(attrs);
emitter.emit(constants.STREAM_CRAWL_EVENT, [attrs]);
res.json({
success: true,
module.exports = (radiksCollection, centralCollection) => {
const CentralController = decorateApp(express.Router());
CentralController.use(bodyParser.json());
CentralController.postAsync('/', async (req, res) => {
const {
key, value, signature, username,
} = req.body;
const { publicKey } = await radiksCollection.findOne({ username, radiksType: 'BlockstackUser' });
const _id = `${username}-${key}`;
if (verifyECDSA(_id, publicKey, signature)) {
await centralCollection.updateOne({ _id }, { $set: value }, { upsert: true });
return res.json({
success: true,
});
}
return res.status(400).json({
const makeApiController = (db) => {
const Router = decorateApp(express.Router());
const radiksData = db.collection(COLLECTION);
Router.getAsync('/messages', async (req, res) => {
let messages = await aggregateMessages(radiksData, req.query);
let username = req.query.fetcher || req.universalCookies.get('username');
if (username) username = username.replace(/"/g, '');
messages = transformMessageVotes(messages, username);
res.json({ messages });
});
Router.getAsync('/avatar/:username', async (req, res) => {
const { username } = req.params;
const user = await radiksData.findOne({ _id: username });
if (!user) {
const makeApiController = (db) => {
const Router = decorateApp(express.Router());
const radiksData = db.collection(COLLECTION);
Router.getAsync('/messages', async (req, res) => {
let messages = await aggregateMessages(radiksData, req.query);
let username = (req.query.fetcher || req.universalCookies.get('username'));
if (username) username = username.replace(/"/g, '');
messages = await transformMessageVotes(messages, username);
res.json({ messages });
});
Router.getAsync('/avatar/:username', async (req, res) => {
const { username } = req.params;
const user = await radiksData.findOne({ _id: username });