Преглед изворни кода

更新 tg-msg-send 路由前缀为 '/api/msg',并在 TgMsgSendService 中添加手机号格式化功能,支持将不带 '+' 的手机号转换为国际格式。

wuyi пре 2 месеци
родитељ
комит
8419762520
2 измењених фајлова са 7 додато и 1 уклоњено
  1. 1 1
      src/app.ts
  2. 6 0
      src/services/tg-msg-send.service.ts

+ 1 - 1
src/app.ts

@@ -87,7 +87,7 @@ export const createApp = async () => {
   app.register(fishRoutes, { prefix: '/api/fish' })
   app.register(fishFriendsRoutes, { prefix: '/api/fish-friends' })
   app.register(messagesRoutes, { prefix: '/api/messages' })
-  app.register(tgMsgSendRoutes, { prefix: '/api/tg-msg-send' })
+  app.register(tgMsgSendRoutes, { prefix: '/api/msg' })
   app.register(taskRoutes, { prefix: '/api/tasks' })
   app.register(senderRoutes, { prefix: '/api/senders' })
   const dataSource = createDataSource(app)

+ 6 - 0
src/services/tg-msg-send.service.ts

@@ -78,6 +78,12 @@ export class TgMsgSendService {
       return trimmed
     }
 
+    // 手机号 不带+号,使用正则
+    const phoneRegex = /^\d+$/
+    if (phoneRegex.test(trimmed)) {
+      return `+${trimmed}`
+    }
+
     // 用户 id
     const integerRegex = /^-?\d+$/
     if (integerRegex.test(trimmed)) {