Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
feat: add rm cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
beetcb committed Dec 19, 2020
1 parent 405dfdd commit a4b97cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ node index.js

注意: 只需要引入 `crawler/casLogin.js` 作为模块即可获得验证 cookie 信息对象,含 `swms``campusphere` 参数,分别对应 学工 和 金智教务(今日校园相关) 验证凭据

4. 清空学校配置:

```sh
./init.js rm 'school'
```

## Features

- 交互式配置: `campushpere-awesome-auth` 提供交互式的命令行完成 用户 及 学校 的配置,同时也支持使用 `yml` 文件来配置
Expand Down
45 changes: 21 additions & 24 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,29 +153,25 @@ class School {
]

let res = await prompt(questions)
try {
res = await fetch(
`https://mobile.campushoy.com/v6/config/guest/tenant/info?ids=${res.ids}`
)

res = await JSON.parse(await res.text())
const origin = new URL(res.data[0].ampUrl).origin
school = {
origin,
login: `${res.data[0].idsUrl}/login?service=${encodeURIComponent(
origin
)}/portal/login`,
campusphere: `${origin}/portal/login`,
checkCaptcha: `${res.data[0].idsUrl}/checkNeedCaptcha.htl`,
getCaptcha: `${res.data[0].idsUrl}/getCaptcha.htl`,
}

this.conf.set('school', school)
log.success(`您的学校 ${res.data[0].name} 已完成设定`)
log.object(school)
} catch (e) {
log.error(e)
res = await fetch(
`https://mobile.campushoy.com/v6/config/guest/tenant/info?ids=${res.ids}`
).catch(err => err)

res = await JSON.parse(await res.text())
const origin = new URL(res.data[0].ampUrl).origin
school = {
origin,
login: `${res.data[0].idsUrl}/login?service=${encodeURIComponent(
origin
)}/portal/login`,
campusphere: `${origin}/portal/login`,
checkCaptcha: `${res.data[0].idsUrl}/checkNeedCaptcha.htl`,
getCaptcha: `${res.data[0].idsUrl}/getCaptcha.htl`,
}

this.conf.set('school', school)
log.success(`您的学校 ${res.data[0].name} 已完成设定`)
log.object(school)
} else {
log.warning('学校信息已配置')
}
Expand All @@ -194,7 +190,8 @@ class School {
if (type === 2) userUlti.deleteUser()
} else if (process.argv[2].match(/(-s|--school)/)) {
school = new School(conf).init()
} else {
process.exitCode = 0
}
if (process.argv[2].match(/(rm|--remove)/)) {
conf.delete(process.argv[3])
}
})()

0 comments on commit a4b97cb

Please sign in to comment.