mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
refactor: Add Telegram binding storage and auth
This commit is contained in:
@@ -13,7 +13,6 @@ import { readSettings, writeSettings, type Settings } from './web/cliApiToken'
|
||||
|
||||
export interface ServerSettings {
|
||||
telegramBotToken: string | null
|
||||
allowedChatIds: number[]
|
||||
webappPort: number
|
||||
webappUrl: string
|
||||
corsOrigins: string[]
|
||||
@@ -23,7 +22,6 @@ export interface ServerSettingsResult {
|
||||
settings: ServerSettings
|
||||
sources: {
|
||||
telegramBotToken: 'env' | 'file' | 'default'
|
||||
allowedChatIds: 'env' | 'file' | 'default'
|
||||
webappPort: 'env' | 'file' | 'default'
|
||||
webappUrl: 'env' | 'file' | 'default'
|
||||
corsOrigins: 'env' | 'file' | 'default'
|
||||
@@ -31,16 +29,6 @@ export interface ServerSettingsResult {
|
||||
savedToFile: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse comma-separated chat IDs from string
|
||||
*/
|
||||
function parseChatIds(str: string): number[] {
|
||||
return str
|
||||
.split(',')
|
||||
.map(id => parseInt(id.trim(), 10))
|
||||
.filter(id => !isNaN(id))
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and normalize CORS origins
|
||||
*/
|
||||
@@ -95,7 +83,6 @@ export async function loadServerSettings(dataDir: string): Promise<ServerSetting
|
||||
let needsSave = false
|
||||
const sources: ServerSettingsResult['sources'] = {
|
||||
telegramBotToken: 'default',
|
||||
allowedChatIds: 'default',
|
||||
webappPort: 'default',
|
||||
webappUrl: 'default',
|
||||
corsOrigins: 'default',
|
||||
@@ -115,20 +102,6 @@ export async function loadServerSettings(dataDir: string): Promise<ServerSetting
|
||||
sources.telegramBotToken = 'file'
|
||||
}
|
||||
|
||||
// allowedChatIds: env > file > []
|
||||
let allowedChatIds: number[] = []
|
||||
if (process.env.ALLOWED_CHAT_IDS) {
|
||||
allowedChatIds = parseChatIds(process.env.ALLOWED_CHAT_IDS)
|
||||
sources.allowedChatIds = 'env'
|
||||
if (settings.allowedChatIds === undefined) {
|
||||
settings.allowedChatIds = allowedChatIds
|
||||
needsSave = true
|
||||
}
|
||||
} else if (settings.allowedChatIds !== undefined) {
|
||||
allowedChatIds = settings.allowedChatIds
|
||||
sources.allowedChatIds = 'file'
|
||||
}
|
||||
|
||||
// webappPort: env > file > 3006
|
||||
let webappPort = 3006
|
||||
if (process.env.WEBAPP_PORT) {
|
||||
@@ -185,7 +158,6 @@ export async function loadServerSettings(dataDir: string): Promise<ServerSetting
|
||||
return {
|
||||
settings: {
|
||||
telegramBotToken,
|
||||
allowedChatIds,
|
||||
webappPort,
|
||||
webappUrl,
|
||||
corsOrigins,
|
||||
|
||||
Reference in New Issue
Block a user