mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-05 15:38:34 +08:00
fix: telegram bot golbalPush (#271)
This commit is contained in:
@@ -42,13 +42,13 @@ export const tgUserNewAddress = async (
|
|||||||
export const jwtListToAddressData = async (
|
export const jwtListToAddressData = async (
|
||||||
c: Context<HonoCustomType>, jwtList: string[]
|
c: Context<HonoCustomType>, jwtList: string[]
|
||||||
): Promise<{ addressList: string[], addressIdMap: Record<string, number> }> => {
|
): Promise<{ addressList: string[], addressIdMap: Record<string, number> }> => {
|
||||||
const addressList = [];
|
const addressList = [] as string[];
|
||||||
const addressIdMap = {} as Record<string, number>;
|
const addressIdMap = {} as Record<string, number>;
|
||||||
for (const jwt of jwtList) {
|
for (const jwt of jwtList) {
|
||||||
try {
|
try {
|
||||||
const { address, address_id } = await Jwt.verify(jwt, c.env.JWT_SECRET, "HS256");
|
const { address, address_id } = await Jwt.verify(jwt, c.env.JWT_SECRET, "HS256");
|
||||||
addressList.push(address);
|
addressList.push(address as string);
|
||||||
addressIdMap[address] = address_id;
|
addressIdMap[address as string] = address_id as number;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
addressList.push("无效凭证");
|
addressList.push("无效凭证");
|
||||||
console.log(`获取地址列表失败: ${(e as Error).message}`);
|
console.log(`获取地址列表失败: ${(e as Error).message}`);
|
||||||
@@ -66,8 +66,8 @@ export const bindTelegramAddress = async (
|
|||||||
}
|
}
|
||||||
const jwtList = await c.env.KV.get<string[]>(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, 'json') || [];
|
const jwtList = await c.env.KV.get<string[]>(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, 'json') || [];
|
||||||
const { addressIdMap } = await jwtListToAddressData(c, jwtList);
|
const { addressIdMap } = await jwtListToAddressData(c, jwtList);
|
||||||
if (address in addressIdMap) {
|
if (address as string in addressIdMap) {
|
||||||
return address;
|
return address as string;
|
||||||
}
|
}
|
||||||
if (jwtList.length >= getIntValue(c.env.TG_MAX_ADDRESS, 5)) {
|
if (jwtList.length >= getIntValue(c.env.TG_MAX_ADDRESS, 5)) {
|
||||||
throw Error("绑定地址数量已达上限");
|
throw Error("绑定地址数量已达上限");
|
||||||
@@ -75,7 +75,7 @@ export const bindTelegramAddress = async (
|
|||||||
await c.env.KV.put(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, JSON.stringify([...jwtList, jwt]));
|
await c.env.KV.put(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, JSON.stringify([...jwtList, jwt]));
|
||||||
// for mail push to telegram
|
// for mail push to telegram
|
||||||
await c.env.KV.put(`${CONSTANTS.TG_KV_PREFIX}:${address}`, userId.toString());
|
await c.env.KV.put(`${CONSTANTS.TG_KV_PREFIX}:${address}`, userId.toString());
|
||||||
return address;
|
return address as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const unbindTelegramAddress = async (
|
export const unbindTelegramAddress = async (
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ const checkTelegramAuth = async (
|
|||||||
if (calcHash != hash) {
|
if (calcHash != hash) {
|
||||||
throw Error("Invalid initData");
|
throw Error("Invalid initData");
|
||||||
}
|
}
|
||||||
|
if (typeof userId === "number") {
|
||||||
|
return userId.toString();
|
||||||
|
}
|
||||||
return userId;
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user