Socket
Socket
Sign inDemoInstall

nodebb-plugin-freelog

Package Overview
Dependencies
8
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.14 to 1.0.15

129

api.js

@@ -7,54 +7,54 @@ const URL = require('url').URL;

(function axiosInit() {
const axios = require('axios');
axiosinstance = axios.create();
if (env === 'prod' || env === 'production') {
// axiosinstance.defaults.baseURL = 'https://api.freelog.com';
axiosinstance.defaults.baseURL = 'http://api-gateway-service.production:8895';
} else {
// axiosinstance.defaults.baseURL = 'http://api.testfreelog.com';
axiosinstance.defaults.baseURL = 'http://api-gateway-service.development:6895';
}
axiosinstance.interceptors.request.use(requestInterceptor, requestErrorInterceptor);
axiosinstance.interceptors.response.use(responseInterceptor, responseErrorInterceptor);
axiosinstance.defaults.headers.post['Content-Type'] = 'application/json';
const axios = require('axios');
axiosinstance = axios.create();
if (env === 'prod' || env === 'production') {
// axiosinstance.defaults.baseURL = 'https://api.freelog.com';
axiosinstance.defaults.baseURL = 'http://api-gateway-service.production:8895';
} else {
// axiosinstance.defaults.baseURL = 'http://api.testfreelog.com';
axiosinstance.defaults.baseURL = 'http://api-gateway-service.development:6895';
}
axiosinstance.interceptors.request.use(requestInterceptor, requestErrorInterceptor);
axiosinstance.interceptors.response.use(responseInterceptor, responseErrorInterceptor);
axiosinstance.defaults.headers.post['Content-Type'] = 'application/json';
function requestErrorInterceptor() {
return Promise.reject(error);
}
function requestErrorInterceptor() {
return Promise.reject(error);
}
function requestInterceptor(config) {
if (!config.url.startsWith('/client')) {
return config;
function requestInterceptor(config) {
if (!config.url.startsWith('/client')) {
return config;
}
const timeLine = Math.round(new Date().getTime() / 1000);
const {pathname, search} = new URL(config.url, config.baseURL);
const text = `${pathname + search}&timeline=${timeLine}`;
config.headers['clientid'] = 1006;
config.headers['timeline'] = timeLine;
config.headers['sign'] = hmacSha1(text, '4c2eab93e896a53ff3f2d3770ae97d77');
return config;
}
const timeLine = Math.round(new Date().getTime() / 1000);
const { pathname, search } = new URL(config.url, config.baseURL);
const text = `${pathname + search}&timeline=${timeLine}`;
config.headers['clientid'] = 1006;
config.headers['timeline'] = timeLine;
config.headers['sign'] = hmacSha1(text, '4c2eab93e896a53ff3f2d3770ae97d77');
return config;
}
function responseInterceptor(response) {
if (!response.data || !Reflect.has(response.data, 'ret') || !Reflect.has(response.data, 'errCode')) {
return response.data;
function responseInterceptor(response) {
if (!response.data || !Reflect.has(response.data, 'ret') || !Reflect.has(response.data, 'errCode')) {
return response.data;
}
if (response.data?.ret == null || response.data?.errCode == null) {
throw new Error('api response data is error format');
}
if (response.data.ret !== 0 || response.data.errCode !== 0) {
throw new Error(response.data.msg ?? 'null error msg', {
response: response.data
});
}
return response.data.data;
}
if (response.data?.ret == null || response.data?.errCode == null) {
throw new Error('api response data is error format');
function responseErrorInterceptor(error) {
return Promise.reject(error);
}
if (response.data.ret !== 0 || response.data.errCode !== 0) {
throw new Error(response.data.msg ?? 'null error msg', {
response: response.data
});
function hmacSha1(text, key, encoding = 'hex') {
return crypto.createHmac('sha1', key).update(text).digest(encoding);
}
return response.data.data;
}
function responseErrorInterceptor(error) {
return Promise.reject(error);
}
function hmacSha1(text, key, encoding = 'hex') {
return crypto.createHmac('sha1', key).update(text).digest(encoding);
}
})();

@@ -64,20 +64,27 @@

module.exports = {
// 根据用户名和密码获取用户信息
async getUserInfo(username, password) {
return axiosinstance.post('/v2/passport/login', {
loginName: username, password, jwtType: 'header'
});
},
// 根据用户名和密码获取用户信息
async getUserInfo(username, password) {
return axiosinstance.post('/v2/passport/login', {
loginName: username, password, jwtType: 'header'
});
},
// 根据用户名获取用户信息
async getUserInfoByUsername(username) {
return axiosinstance.get('/v2/users/detail?username=' + username);
},
// 根据用户名获取用户信息
async getUserInfoByUsername(username) {
return axiosinstance.get('/v2/users/detail?username=' + username);
},
// 发送运营任务
async sendActivityEvent(code, userId) {
return axiosinstance.post('/client/v2/activities/task/records/complete4TaskConfigCode', {
taskConfigCode: code, userId
});
}
// 发送运营任务
async sendActivityEvent(code, userId) {
return axiosinstance.post('/client/v2/activities/task/records/complete4TaskConfigCode', {
taskConfigCode: code, userId
});
},
// 吐槽区发帖之后通知给运营
async sendActivityEventOnPostCreate(code, userId, metaInfo) {
return axiosinstance.post('/client/v2/activities/task/records/complete4TaskConfigCode', {
taskConfigCode: code, userId, meta: metaInfo
});
},
};

@@ -13,3 +13,2 @@ const plugin = {};

plugin.topicReplyHandler = async function (data) {
try {

@@ -57,4 +56,22 @@ const env = process.env.NODE_ENV;

plugin.topicCreateHandler = function (data) {
throw new Error("yuliang test error");
plugin.topicCreateHandler = async function (data) {
try {
const {topic} = data;
// 正式环境和测试环境目前吐槽专区的cid都是3,如果是其他分类的帖子直接忽略
if (topic.cid !== 3) {
return data;
}
const nodebbUserInfo = await User.getUserData(data.caller.uid);
const freelogUserInfo = await freelogAPI.getUserInfoByUsername(nodebbUserInfo?.username);
if (!freelogUserInfo) {
return;
}
const env = process.env.NODE_ENV;
const forumHost = env === 'production' ? 'https://forum.freelog.com' : 'http://forum.testfreelog.com';
await freelogAPI.sendActivityEventOnPostCreate('TS000078', freelogUserInfo.userId, {
linkUrl: `${forumHost}/topic/19/${topic.tid}`
});
} catch (e) {
console.error('吐槽区运营推送事件调用失败', e, data);
}
return data;

@@ -61,0 +78,0 @@ };

@@ -5,3 +5,3 @@ {

"description": "NodeBB Forum",
"version": "1.0.14",
"version": "1.0.15",
"homepage": "https://github.com/freelogfe/nodebb-plugin-freelog",

@@ -8,0 +8,0 @@ "repository": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc