feat: 优化请求处理 & 拆分Type
This commit is contained in:
parent
fd3ada6f23
commit
7915003c1b
7
index.ts
7
index.ts
@ -5,7 +5,7 @@ import { initSchedule } from "./schedule";
|
||||
|
||||
initSchedule();
|
||||
|
||||
Bun.serve({
|
||||
const server = Bun.serve({
|
||||
async fetch(req) {
|
||||
try {
|
||||
const url = new URL(req.url);
|
||||
@ -16,7 +16,8 @@ Bun.serve({
|
||||
// 消息代理发送
|
||||
if (url.pathname === "/message") return await manageMessageReq(req);
|
||||
// 小程序
|
||||
if (url.pathname.startsWith("/micro_app")) return await manageMicroAppReq(req);
|
||||
if (url.pathname.startsWith("/micro_app"))
|
||||
return await manageMicroAppReq(req);
|
||||
// 其他
|
||||
return new Response("hello, glade to see you!");
|
||||
} catch (error: any) {
|
||||
@ -27,3 +28,5 @@ Bun.serve({
|
||||
},
|
||||
port: 3000,
|
||||
});
|
||||
|
||||
console.log(`Listening on ${server.hostname}:${server.port}`);
|
||||
|
@ -14,7 +14,11 @@ const manageLogin = async (req: Request, isSeek = false) => {
|
||||
}
|
||||
const { data: userInfo } = await service.lark.user.code2Login(code, isSeek);
|
||||
console.log("🚀 ~ manageLogin ~ userInfo:", userInfo);
|
||||
return new Response(JSON.stringify(userInfo));
|
||||
return Response.json({
|
||||
code: 0,
|
||||
message: "success",
|
||||
data: userInfo,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@ -30,10 +34,24 @@ const manageBatchUser = async (req: Request, isSeek = false) => {
|
||||
return new Response("user_ids not found", { status: 400 });
|
||||
}
|
||||
const {
|
||||
data: { user: batchUserInfo },
|
||||
// data: { user: batchUserInfo },
|
||||
code,
|
||||
data,
|
||||
msg,
|
||||
} = await service.lark.user.batchGet(user_ids, isSeek);
|
||||
console.log("🚀 ~ manageBatchUser ~ users:", batchUserInfo);
|
||||
return new Response(JSON.stringify(batchUserInfo));
|
||||
console.log("🚀 ~ manageBatchUser ~ code:", code, data, msg);
|
||||
if (code !== 0) {
|
||||
return Response.json({
|
||||
code,
|
||||
message: msg,
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
return Response.json({
|
||||
code,
|
||||
message: "success",
|
||||
data: data.user,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
10
test/batchUser.ts
Normal file
10
test/batchUser.ts
Normal file
@ -0,0 +1,10 @@
|
||||
const res = await fetch("http://localhost:3000/micro_app/egg/batch_user", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user_ids: ["libo12"],
|
||||
}),
|
||||
});
|
||||
console.log(await res.json());
|
Loading…
x
Reference in New Issue
Block a user