opti: plugin

This commit is contained in:
suxiaoxin 2017-09-25 00:07:23 +08:00
parent 4d1381ceb3
commit 28040a9096
4 changed files with 77 additions and 79 deletions

View File

@ -155,7 +155,7 @@ class interfaceController extends baseController {
} }
let result = await this.Model.save(data); let result = await this.Model.save(data);
yapi.emitHook('interface_add', result._id).then();
this.catModel.get(params.catid).then((cate) => { this.catModel.get(params.catid).then((cate) => {
let username = this.getUsername(); let username = this.getUsername();
let title = `用户 "${username}" 为分类 "${cate.name}" 添加了接口 "${data.title}"` let title = `用户 "${username}" 为分类 "${cate.name}" 添加了接口 "${data.title}"`
@ -209,6 +209,7 @@ class interfaceController extends baseController {
return ctx.body = yapi.commons.resReturn(null, 406, '没有权限'); return ctx.body = yapi.commons.resReturn(null, 406, '没有权限');
} }
} }
yapi.emitHook('interface_get', params.id).then();
ctx.body = yapi.commons.resReturn(result); ctx.body = yapi.commons.resReturn(result);
} catch (e) { } catch (e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message); ctx.body = yapi.commons.resReturn(null, 402, e.message);
@ -243,6 +244,7 @@ class interfaceController extends baseController {
try { try {
let result = await this.Model.list(project_id); let result = await this.Model.list(project_id);
ctx.body = yapi.commons.resReturn(result); ctx.body = yapi.commons.resReturn(result);
yapi.emitHook('interface_list', project_id).then();
} catch (err) { } catch (err) {
ctx.body = yapi.commons.resReturn(null, 402, err.message); ctx.body = yapi.commons.resReturn(null, 402, err.message);
} }
@ -483,6 +485,7 @@ class interfaceController extends baseController {
} }
ctx.body = yapi.commons.resReturn(result); ctx.body = yapi.commons.resReturn(result);
yapi.emitHook('interface_update', id).then();
} catch (e) { } catch (e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message); ctx.body = yapi.commons.resReturn(null, 402, e.message);
} }

View File

@ -318,6 +318,8 @@ class projectController extends baseController {
let cat = await catInst.list(params.id); let cat = await catInst.list(params.id);
result.cat = cat; result.cat = cat;
result.role = await this.getProjectRole(params.id, 'project'); result.role = await this.getProjectRole(params.id, 'project');
yapi.emitHook('project_add', params.id).then();
ctx.body = yapi.commons.resReturn(result); ctx.body = yapi.commons.resReturn(result);
} catch (e) { } catch (e) {
ctx.body = yapi.commons.resReturn(null, 402, e.message); ctx.body = yapi.commons.resReturn(null, 402, e.message);

View File

@ -3,36 +3,102 @@ const plugin_path = yapi.path.join(yapi.WEBROOT, 'plugins');
const plugin_system_path = yapi.path.join(yapi.WEBROOT, 'exts'); const plugin_system_path = yapi.path.join(yapi.WEBROOT, 'exts');
const initPlugins = require('../common/lib.js').initPlugins; const initPlugins = require('../common/lib.js').initPlugins;
var extConfig = require('../common/config.js').exts; var extConfig = require('../common/config.js').exts;
/**
* 钩子配置
*/
var hooks = { var hooks = {
//第三方sso登录钩子暂只支持设置一个 /**
* 第三方sso登录钩子暂只支持设置一个
* @param ctx
*/
'third_login': { 'third_login': {
type: 'single', type: 'single',
listener: null listener: null
}, },
//增加接口成功后触发 /**
* 客户端增加接口成功后触发
* @param id 接口id
*/
'interface_add': { 'interface_add': {
type: 'multi', type: 'multi',
listener: [] listener: []
}, },
//删除接口成功后触发 /**
* 客户端删除接口成功后触发
* @param id 接口id
*/
'interface_del': { 'interface_del': {
type: 'multi', type: 'multi',
listener: [] listener: []
}, },
/**
* 客户端更新接口成功后触发
* @param id 接口id
*/
'interface_update':{
type: 'multi',
listener: []
},
/**
* 客户端获取接口数据列表
* @param id project_id
*/
'interface_list':{
type: 'multi',
listener: []
},
/**
* 客户端获取一条接口信息触发
* @param id 接口id
*/
'interface_get':{
type: 'multi',
listener: []
},
/**
* 客户端增加一个新项目
* @param id 项目id
*/
'project_add':{ 'project_add':{
type: 'multi', type: 'multi',
listener: [] listener: []
}, },
/**
* 客户端删除删除一个项目
* @param id 项目id
*/
'project_del':{ 'project_del':{
type: 'multi', type: 'multi',
listener: [] listener: []
}, },
//MockServer生成mock数据后触发 /**
* MockServer生成mock数据后触发
* @param context Object
* {
* projectData: project,
interfaceData: interfaceData,
ctx: ctx,
mockJson: res
* }
*
*/
mock_after: { mock_after: {
type: 'multi', type: 'multi',
listener: [] listener: []
}, },
//增加路由的钩子 /**
* 增加路由的钩子
* type Sync
* @param addPluginRouter Function
* addPLuginPLugin(config)
* config = {
* path, // String
* method, // String
* controller // Class 继承baseController的class
* action // String controller的Action
* }
*/
add_router: { add_router: {
type: 'multi', type: 'multi',
listener: [] listener: []

View File

@ -1,73 +0,0 @@
// file_id:2D7ABF69-3BC0-4175-98C9-5C3D5CB00158 -- nerver change this !!
/*
* file: qsso-auth.js
* URL: https://qsso.corp.qunar.com/lib/qsso-auth.js
* written by zhibin.ning
* version: 0.1
*
*/
if (!window['QSSO']) {
var QSSO = (function () {
var AUTH_SERVER = 'https://qsso.corp.qunar.com',
LOGIN_PAGE = '/login.php',
SORRY_PAGE = '/sorry.html';
if (location.hostname.match(/qunar\.ctripgroup\.com$/i)) {
AUTH_SERVER = 'https://qunar.ctripgroup.com/sec/qsso/api';
}
var qualifyURL = function (url, encode) {
var url = url || '';
var ret = location.protocol + '//' + location.host + (url.substr(0,1) === '/' ? '' : location.pathname.match(/.*\//)) + url;
if (encode) {
ret = encodeURIComponent(ret);
}
return ret;
};
var URLStringify = function (o) {
var ret = [];
for (var i in o) {
// ret.push( encodeURIComponent(i) + '=' + encodeURIComponent(o[i]) );
ret.push(i + '=' + o[i]);
}
return ret.join('&');
};
return {
'auth': function (loginURI, opt_ext) {
if (!location.hostname.match(/\.qunar(man|ops)?\.com$|\.qunarman\.com$|qunar\.it$|\.928383\.com$|^928383\.com$|qunar\.ctripgroup\.c(om|n)$|\.ctrip(corp)?\.com$|^opsdata\.me$|\.mofun\.com$/i)) {
location = AUTH_SERVER + SORRY_PAGE + '?host=' + qualifyURL('', true);
return;
}
var ret = qualifyURL(loginURI, true);
var redirectURL = AUTH_SERVER + LOGIN_PAGE + '?ret=' + ret + (opt_ext ? '&ext=' + encodeURIComponent(URLStringify(opt_ext)) : '');
// console.log(redirectURL);
location = redirectURL;
},
'attach': function (eid, loginURI, opt_ext) {
QSSO.login = function() {
QSSO.auth(loginURI, opt_ext);
};
document.getElementById(eid).onclick = QSSO.login;
if (location.hash.match('qsso-auto-login')) {
QSSO.login();
}
}
};
})();
/* todo add QSSO login UI, frame login, etc */
}