tencent-sms
Version:
sms plugin for tencent cloud
28 lines (27 loc) • 688 B
JavaScript
;
const { createSingleon } = require('./utils/sms');
const { isObject } = require('./utils');
function tencentSMS() {
this.clients = new Map();
}
tencentSMS.prototype.get = function(key) {
try {
return this.clients.get(key);
} catch (error) {
throw new Error('no such client');
}
};
module.exports = function(config) {
if (!isObject(config)) {
throw new Error('config must be a object');
}
const keys = Object.keys(config);
const sms = new tencentSMS();
keys.forEach(key => {
sms.clients.set(key, createSingleon(config[key]));
});
return function(req, res, next) {
req.tencentSMS = sms;
next();
};
};