94 lines
2.0 KiB
TypeScript
94 lines
2.0 KiB
TypeScript
import service from "../../services"
|
|
import netTool from "../../services/netTool"
|
|
import { trimPathPrefix } from "../../utils/pathTools"
|
|
|
|
/**
|
|
* 处理登录请求
|
|
* @param req
|
|
* @returns
|
|
*/
|
|
const manageLogin = async (req: Request) => {
|
|
const url = new URL(req.url)
|
|
const code = url.searchParams.get("code")
|
|
const appName = url.searchParams.get("app_name") || undefined
|
|
if (!code) {
|
|
return netTool.badRequest("code not found")
|
|
}
|
|
const {
|
|
code: resCode,
|
|
data,
|
|
msg,
|
|
} = await service.lark.user.code2Login(appName)(code)
|
|
|
|
console.log("🚀 ~ manageLogin:", resCode, data, msg)
|
|
|
|
if (resCode !== 0) {
|
|
return Response.json({
|
|
code: resCode,
|
|
message: msg,
|
|
data: null,
|
|
})
|
|
}
|
|
|
|
return Response.json({
|
|
code: 0,
|
|
message: "success",
|
|
data,
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 处理批量获取用户信息请求
|
|
* @param req
|
|
* @returns
|
|
*/
|
|
const manageBatchUser = async (req: Request) => {
|
|
const body = (await req.json()) as any
|
|
console.log("🚀 ~ manageBatchUser ~ body:", body)
|
|
const { user_ids, user_id_type, app_name } = body
|
|
if (!user_ids) {
|
|
return netTool.badRequest("user_ids not found")
|
|
}
|
|
if (!user_id_type) {
|
|
return netTool.badRequest("user_id_type not found")
|
|
}
|
|
|
|
const { code, data, msg } = await service.lark.user.batchGet(app_name)(
|
|
user_ids,
|
|
user_id_type
|
|
)
|
|
|
|
console.log("🚀 ~ manageBatchUser:", code, data, msg)
|
|
if (code !== 0) {
|
|
return Response.json({
|
|
code,
|
|
message: msg,
|
|
data: null,
|
|
})
|
|
}
|
|
return Response.json({
|
|
code,
|
|
message: "success",
|
|
data: data.items,
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 处理小程序请求
|
|
* @param req
|
|
* @returns
|
|
*/
|
|
export const manageMicroAppReq = async (req: Request) => {
|
|
const url = new URL(req.url)
|
|
const withoutPrefix = trimPathPrefix(url.pathname, "/micro_app")
|
|
// 处理登录请求
|
|
if (withoutPrefix === "/login") {
|
|
return manageLogin(req)
|
|
}
|
|
// 处理批量获取用户信息请求
|
|
if (withoutPrefix === "/batch_user") {
|
|
return manageBatchUser(req)
|
|
}
|
|
return netTool.ok()
|
|
}
|