|
|
@@ -3,6 +3,7 @@ import fs from 'fs/promises'
|
|
|
import path from 'path'
|
|
|
import { TgUserService } from '../services/tg-user.service'
|
|
|
import { CreateSenderBody, UpdateSenderBody, ListSenderQuery } from '../dto/tg-user.dto'
|
|
|
+import { parsePhoneNumber } from '../utils/tg.util'
|
|
|
|
|
|
export class TgUserController {
|
|
|
private tgUserService: TgUserService
|
|
|
@@ -21,12 +22,20 @@ export class TgUserController {
|
|
|
return reply.code(400).send({ message: '文件格式错误,应为数组' })
|
|
|
}
|
|
|
|
|
|
- const importList: { id: string; dcId?: number; authKey?: string }[] = []
|
|
|
+ const importList: {
|
|
|
+ id: string
|
|
|
+ dcId?: number
|
|
|
+ authKey?: string
|
|
|
+ name?: string
|
|
|
+ username?: string
|
|
|
+ areaCode?: string
|
|
|
+ phone?: string
|
|
|
+ }[] = []
|
|
|
let parseFailed = 0
|
|
|
|
|
|
for (const item of parsed) {
|
|
|
try {
|
|
|
- const { id, token } = item ?? {}
|
|
|
+ const { id, token, name, username, phone } = item ?? {}
|
|
|
if (!id || !token) {
|
|
|
parseFailed++
|
|
|
continue
|
|
|
@@ -41,10 +50,28 @@ export class TgUserController {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
+ // 解析电话号码,将区号和号码分开
|
|
|
+ let areaCode: string | undefined
|
|
|
+ let phoneNumber: string | undefined
|
|
|
+ if (phone) {
|
|
|
+ const parsedPhone = parsePhoneNumber(phone)
|
|
|
+ if (parsedPhone) {
|
|
|
+ areaCode = parsedPhone.areaCode
|
|
|
+ phoneNumber = parsedPhone.phone
|
|
|
+ } else {
|
|
|
+ // 如果无法解析,将整个电话号码保存到 phone 字段
|
|
|
+ phoneNumber = phone.replace(/\D/g, '')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
importList.push({
|
|
|
id: String(id),
|
|
|
dcId: Number(dcId),
|
|
|
- authKey: String(authKey)
|
|
|
+ authKey: String(authKey),
|
|
|
+ name: name ? String(name).trim() : undefined,
|
|
|
+ username: username ? String(username).trim() : undefined,
|
|
|
+ areaCode,
|
|
|
+ phone: phoneNumber
|
|
|
})
|
|
|
} catch {
|
|
|
parseFailed++
|