Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 });