当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript micro.send函数代码示例

本文整理汇总了TypeScript中micro.send函数的典型用法代码示例。如果您正苦于以下问题:TypeScript send函数的具体用法?TypeScript send怎么用?TypeScript send使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了send函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: async

 async (req: ServerRequest, res: ServerResponse) => {
   try {
     const profile = await getProfile({
       username: decodeURIComponent(req.params.username)
     });
     if (!profile) {
       throw {
         httpStatus: 404,
         message: "Profile Not Found"
       };
     }
     const { plugins, score, timestamp, game, enb, tag } = profile;
     const files = {};
     for (const f of ["plugins", "modlist", "ini", "prefsini"]) {
       files[f] = !profile[f] ? 0 : profile[f].length;
     }
     send(res, 200, {
       plugins,
       score,
       timestamp,
       game,
       enb,
       tag,
       files
     });
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 }
开发者ID:Modwatch,项目名称:API,代码行数:30,代码来源:user.ts

示例2: async

 async (req: ServerRequest, res: ServerResponse) => {
   try {
     const token = await verifyToken(await getToken(req));
     if (
       decodeURIComponent(req.params.username) !== token.sub &&
       !token.scopes.includes("admin")
     ) {
       send(res, 401);
       return;
     }
     const profile = await getProfile({
       username: decodeURIComponent(req.params.username)
     });
     if (!profile) {
       throw {
         httpStatus: 404,
         message: "Profile Not Found"
       };
     }
     if (profile.roles.includes("admin")) {
       send(res, 401);
       return;
     }
     await deleteProfile(
       decodeURIComponent(req.params.username),
       null,
       token
     );
     send(res, 200);
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 }
开发者ID:Modwatch,项目名称:API,代码行数:34,代码来源:oauth.ts

示例3: get

 get("/api/users/count", async (req: ServerRequest, res: ServerResponse) => {
   try {
     send(res, 200, await getUsersCount());
   } catch (e) {
     console.log(e);
     send(res, 500);
   }
 }),
开发者ID:Modwatch,项目名称:API,代码行数:8,代码来源:users.ts

示例4: post

 post("/auth/checkToken", async (req: ServerRequest, res: ServerResponse) => {
   try {
     const body = (await json(req)) as { token: string; username: string };
     await verifyToken(body.token);
     send(res, 200, { token: body.token });
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 }),
开发者ID:Modwatch,项目名称:API,代码行数:10,代码来源:auth.ts

示例5: post

 post("/loadorder", async (req: ServerRequest, res: ServerResponse) => {
   try {
     const body = (await json(req)) as Modwatch.Profile;
     const profile = {
       ...body,
       timestamp: new Date()
     };
     send(res, 201, await uploadProfile(profile, getToken(req)));
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 })
开发者ID:Modwatch,项目名称:API,代码行数:13,代码来源:upload.ts

示例6: get

 get("/oauth/verify", async (req: ServerRequest, res: ServerResponse) => {
   try {
     const token = await verifyToken(await getToken(req));
     if (new Date() > new Date(token.exp)) {
       send(res, 401, "Invalid Token");
       return;
     }
     send(res, 200);
   } catch (e) {
     console.log(e);
     send(res, e.httpStatus || 500, e.message || null);
   }
 }),
开发者ID:Modwatch,项目名称:API,代码行数:13,代码来源:oauth.ts

示例7: async

 async (req: ServerRequest, res: ServerResponse) => {
   const users = await searchProfiles(
     decodeURIComponent(req.params.query),
     req.params.limit ? +req.params.limit : undefined
   );
   send(res, 200, users);
 }
开发者ID:Modwatch,项目名称:API,代码行数:7,代码来源:users.ts


注:本文中的micro.send函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。