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