93 lines
2.0 KiB
TypeScript
93 lines
2.0 KiB
TypeScript
import service from "../../services";
|
|
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 new Response("code not found", { status: 400 });
|
|
}
|
|
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 new Response("user_ids not found", { status: 400 });
|
|
}
|
|
if (!user_id_type) {
|
|
return new Response("user_id_type not found", { status: 400 });
|
|
}
|
|
|
|
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 new Response("hello, glade to see you!");
|
|
};
|