MCPcopy
hub / github.com/YMFE/yapi / token

Method token

server/controllers/project.js:999–1022  ·  view source on GitHub ↗

* 获取token数据 * @interface /project/token * @method GET * @category project * @foldnumber 10 * @param {Number} id 项目id,不能为空 * @param {String} q * @return {Object}

(ctx)

Source from the content-addressed store, hash-verified

997 * @return {Object}
998 */
999 async token(ctx) {
1000 try {
1001 let project_id = ctx.params.project_id;
1002 let data = await this.tokenModel.get(project_id);
1003 let token;
1004 if (!data) {
1005 let passsalt = yapi.commons.randStr();
1006 token = sha('sha1')
1007 .update(passsalt)
1008 .digest('hex')
1009 .substr(0, 20);
1010
1011 await this.tokenModel.save({ project_id, token });
1012 } else {
1013 token = data.token;
1014 }
1015
1016 token = getToken(token, this.getUid())
1017
1018 ctx.body = yapi.commons.resReturn(token);
1019 } catch (err) {
1020 ctx.body = yapi.commons.resReturn(null, 402, err.message);
1021 }
1022 }
1023
1024 /**
1025 * 更新token数据

Callers 5

ZtFunction · 0.80
lFunction · 0.80
cFunction · 0.80

Calls 5

getTokenFunction · 0.85
getMethod · 0.45
updateMethod · 0.45
saveMethod · 0.45
getUidMethod · 0.45

Tested by

no test coverage detected