设备识别移除tgbot

This commit is contained in:
mtvpls
2026-07-15 15:19:47 +08:00
parent 93d6c773b8
commit 9f63e18550
4 changed files with 20 additions and 13 deletions
+4 -6
View File
@@ -6,14 +6,12 @@ on:
tag:
description: '手动指定 Docker 标签'
required: false
# dev 分支手动触发时,默认 tag 为 dev
# 手动触发时,默认 tag 为 dev
default: 'dev'
type: string
push:
# 监听 dev 分支的推送
branches: [ dev ]
# 取消了 pull_request 触发,因为它通常不应该触发构建和推送镜像的操作
# 如果确实需要,可以重新加回来
# 已移除 push 到 dev 分支时的自动构建,仅保留手动触发
# push:
# branches: [ dev ]
# pull_request:
# branches: [ dev ]
+4 -3
View File
@@ -1,4 +1,4 @@
import { NextResponse } from 'next/server';
import { NextRequest, NextResponse } from 'next/server';
import {
createTelegramLoginSession,
@@ -9,7 +9,7 @@ import {
export const runtime = 'nodejs';
export async function POST() {
export async function POST(request: NextRequest) {
const config = await getTelegramConfig();
const problems = getTelegramConfigProblems(config, 'login');
if (problems.length > 0) {
@@ -25,7 +25,8 @@ export async function POST() {
}, { status: 400 });
}
const session = await createTelegramLoginSession();
const userAgent = request.headers.get('user-agent') || '';
const session = await createTelegramLoginSession(userAgent);
const botUsername = config.botUsername.replace(/^@/, '');
return NextResponse.json({
token: session.token,
-1
View File
@@ -45,7 +45,6 @@ export function getDeviceInfoFromUserAgent(userAgent: string): string {
if (ua.includes('moontvplus')) return 'MoonTVPlus APP';
if (ua.includes('oriontv')) return 'OrionTV';
if (ua.includes('telegram')) return 'Telegram Login';
if (ua.includes('chrome')) return 'Chrome';
if (ua.includes('firefox')) return 'Firefox';
if (ua.includes('safari')) return 'Safari';
+12 -3
View File
@@ -5,7 +5,10 @@ import type { NextRequest } from 'next/server';
import nodeFetch from 'node-fetch';
import type { AdminConfig } from './admin.types';
import { generateAuthCookieValue } from './auth-cookie';
import {
generateAuthCookieValue,
getDeviceInfoFromUserAgent,
} from './auth-cookie';
import { getConfig } from './config';
import { db, getStorage } from './db';
import { lockManager } from './lock';
@@ -64,6 +67,8 @@ interface TelegramLoginSession {
username?: string;
telegramUserId?: string;
authToken?: string;
/** 发起登录的浏览器 User-Agent,用于设备管理展示 */
userAgent?: string;
}
interface TelegramBindSession {
@@ -318,12 +323,15 @@ export async function registerTelegramUser(input: {
}
}
export async function createTelegramLoginSession(): Promise<TelegramLoginSession> {
export async function createTelegramLoginSession(
userAgent?: string
): Promise<TelegramLoginSession> {
const session: TelegramLoginSession = {
token: randomToken(),
status: 'pending',
createdAt: now(),
expiresAt: now() + LOGIN_TTL_MS,
userAgent: userAgent || undefined,
};
await writeJson(loginSessionKey(session.token), session);
return session;
@@ -381,11 +389,12 @@ export async function confirmTelegramLogin(token: string, telegramUserId: string
if (!binding) throw new Error('当前 Telegram 账号尚未绑定站内账号');
const role = await getUserRole(binding.username);
const deviceInfo = getDeviceInfoFromUserAgent(session.userAgent || '');
const authToken = await generateAuthCookieValue({
username: binding.username,
role,
includePassword: false,
deviceInfo: 'Telegram Bot Login',
deviceInfo,
});
session.status = 'confirmed';