From 6d55acdd42600103ac48720376751054a91f5f2c Mon Sep 17 00:00:00 2001 From: Dream Hunter Date: Sat, 25 May 2024 14:34:16 +0800 Subject: [PATCH] fix: telegram bot golbalPush (#271) --- worker/src/telegram_api/common.ts | 12 ++++++------ worker/src/telegram_api/miniapp.ts | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/worker/src/telegram_api/common.ts b/worker/src/telegram_api/common.ts index e18bd822..e541684a 100644 --- a/worker/src/telegram_api/common.ts +++ b/worker/src/telegram_api/common.ts @@ -42,13 +42,13 @@ export const tgUserNewAddress = async ( export const jwtListToAddressData = async ( c: Context, jwtList: string[] ): Promise<{ addressList: string[], addressIdMap: Record }> => { - const addressList = []; + const addressList = [] as string[]; const addressIdMap = {} as Record; for (const jwt of jwtList) { try { const { address, address_id } = await Jwt.verify(jwt, c.env.JWT_SECRET, "HS256"); - addressList.push(address); - addressIdMap[address] = address_id; + addressList.push(address as string); + addressIdMap[address as string] = address_id as number; } catch (e) { addressList.push("无效凭证"); console.log(`获取地址列表失败: ${(e as Error).message}`); @@ -66,8 +66,8 @@ export const bindTelegramAddress = async ( } const jwtList = await c.env.KV.get(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, 'json') || []; const { addressIdMap } = await jwtListToAddressData(c, jwtList); - if (address in addressIdMap) { - return address; + if (address as string in addressIdMap) { + return address as string; } if (jwtList.length >= getIntValue(c.env.TG_MAX_ADDRESS, 5)) { throw Error("绑定地址数量已达上限"); @@ -75,7 +75,7 @@ export const bindTelegramAddress = async ( await c.env.KV.put(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, JSON.stringify([...jwtList, jwt])); // for mail push to telegram await c.env.KV.put(`${CONSTANTS.TG_KV_PREFIX}:${address}`, userId.toString()); - return address; + return address as string; } export const unbindTelegramAddress = async ( diff --git a/worker/src/telegram_api/miniapp.ts b/worker/src/telegram_api/miniapp.ts index dc062df1..34e3d1b2 100644 --- a/worker/src/telegram_api/miniapp.ts +++ b/worker/src/telegram_api/miniapp.ts @@ -53,6 +53,9 @@ const checkTelegramAuth = async ( if (calcHash != hash) { throw Error("Invalid initData"); } + if (typeof userId === "number") { + return userId.toString(); + } return userId; }