Skip to content

Commit

Permalink
fix(addr): exclude bus addr returned from baidu
Browse files Browse the repository at this point in the history
  • Loading branch information
beetcb committed Dec 5, 2021
1 parent 663c0b0 commit 3864e04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
36 changes: 19 additions & 17 deletions core/src/conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ export async function getSchoolInfos({
const isSchoolAddrNeeded = users.find((e) => e.addr.length === 1)
for (const abbreviation of schoolNamesSet) {
res = (await fetch(
`https://mobile.campushoy.com/v6/config/guest/tenant/info?ids=${abbreviation}`,
`https://mobile.campushoy.com/v6/config/guest/tenant/info?ids=${abbreviation}`
).catch(log.error)) as Response

const data = JSON.parse((await res.text().catch(log.error)) as string)
.data[0] as StringKV

const data = (await res.json().catch(log.error)).data?.[0] as StringKV
if (!data) {
log.error(`学校 ID 有误,请使用 https://cea.beetcb.com/ 检查学校 ID`)
return null
}
let origin = new URL(data.ampUrl).origin
const authOrigin = data.idsUrl

Expand All @@ -49,25 +51,23 @@ export async function getSchoolInfos({
}
if (isSchoolAddrNeeded) {
res = (await fetch(
`https://api.map.baidu.com/?qt=s&wd=${
encodeURIComponent(
data.name,
)
}&ak=E4805d16520de693a3fe707cdc962045&rn=10&ie=utf-8&oue=1&fromproduct=jsapi&res=api`,
`https://api.map.baidu.com/?qt=s&wd=${encodeURIComponent(
data.name
)}&ak=E4805d16520de693a3fe707cdc962045&rn=10&ie=utf-8&oue=1&fromproduct=jsapi&res=api`
).catch(log.error)) as Response
const addrInfo = (await res.json()) as any
defaultAddr = addrInfo.content[0].addr
const addrInfo = (await res.json()) as {
content: Array<{ addr: string; blinfo?: Array<string> }>
}
defaultAddr = addrInfo?.content?.find((c) => !c.blinfo)?.addr ?? ''
log.success({ message: `学校 ${data.name} 默认签到地址:${defaultAddr}` })
}
const isCloud = data.joinType === 'CLOUD'

// Get Edge-cases
const edgeCaseRes = await fetch(
`https://cea.beetcb.com/api/edge-case?name=${
encodeURIComponent(
data.name,
)
}&c=${isCloud ? 'true' : ''}`,
`https://cea.beetcb.com/api/edge-case?name=${encodeURIComponent(
data.name
)}&c=${isCloud ? 'true' : ''}`
).catch(log.error)
if (edgeCaseRes?.ok) {
const edgeCase = (await edgeCaseRes.json()) as SchoolEdgeCase
Expand All @@ -82,7 +82,9 @@ export async function getSchoolInfos({
edgeCase,
}
log.success(
`学校 ${data.name} 已完成设定,接入方式为 ${isCloud ? 'CLOUD' : 'NOTCLOUD'}`,
`学校 ${data.name} 已完成设定,接入方式为 ${
isCloud ? 'CLOUD' : 'NOTCLOUD'
}`
)
} else {
throw new Error('Failed to get school edge case!')
Expand Down
3 changes: 1 addition & 2 deletions core/src/crawler/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ export default async function login(
}
} else {
log.error({
message: `登录失败,请尝试本地登录此地址以确保账号密码正确 @${name}
${school.preAuthURL}`,
message: `登录失败,请尝试本地登录 ${school.preAuthURL} 以确保账号密码正确 @${name}`,
})
}
return
Expand Down

0 comments on commit 3864e04

Please sign in to comment.