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

Method init

server/controllers/base.js:21–113  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

19 }
20
21 async init(ctx) {
22 this.$user = null;
23 this.tokenModel = yapi.getInst(tokenModel);
24 this.projectModel = yapi.getInst(projectModel);
25 let ignoreRouter = [
26 '/api/user/login_by_token',
27 '/api/user/login',
28 '/api/user/reg',
29 '/api/user/status',
30 '/api/user/logout',
31 '/api/user/avatar',
32 '/api/user/login_by_ldap'
33 ];
34 if (ignoreRouter.indexOf(ctx.path) > -1) {
35 this.$auth = true;
36 } else {
37 await this.checkLogin(ctx);
38 }
39
40 let openApiRouter = [
41 '/api/open/run_auto_test',
42 '/api/open/import_data',
43 '/api/interface/add',
44 '/api/interface/save',
45 '/api/interface/up',
46 '/api/interface/get',
47 '/api/interface/list',
48 '/api/interface/list_menu',
49 '/api/interface/add_cat',
50 '/api/interface/getCatMenu',
51 '/api/interface/list_cat',
52 '/api/project/get',
53 '/api/plugin/export',
54 '/api/project/up',
55 '/api/plugin/exportSwagger'
56 ];
57
58 let params = Object.assign({}, ctx.query, ctx.request.body);
59 let token = params.token;
60
61 // 如果前缀是 /api/open,执行 parse token 逻辑
62 if (token && (openApiRouter.indexOf(ctx.path) > -1 || ctx.path.indexOf('/api/open/') === 0 )) {
63
64 let tokens = parseToken(token)
65
66 const oldTokenUid = '999999'
67
68 let tokenUid = oldTokenUid;
69
70 if(!tokens){
71 let checkId = await this.getProjectIdByToken(token);
72 if(!checkId)return;
73 }else{
74 token = tokens.projectToken;
75 tokenUid = tokens.uid;
76 }
77
78 // if (this.$auth) {

Callers 9

rFunction · 0.45
CFunction · 0.45
eFunction · 0.45
lnFunction · 0.45
VrFunction · 0.45
SFunction · 0.45
commons.jsFile · 0.45

Calls 4

checkLoginMethod · 0.95
getProjectIdByTokenMethod · 0.95
getMethod · 0.45
findByIdMethod · 0.45

Tested by

no test coverage detected