feat: 添加通知功能自定义telegram域名功能
This commit is contained in:
@@ -356,7 +356,17 @@ export class NotificationService {
|
||||
);
|
||||
console.log(`[通知测试 - Telegram] 渲染的消息文本:`, messageText);
|
||||
|
||||
const telegramApiUrl = `https://api.telegram.org/bot${config.botToken}/sendMessage`;
|
||||
let baseApiUrl = "https://api.telegram.org";
|
||||
if (config.customDomain) {
|
||||
try {
|
||||
const url = new URL(config.customDomain);
|
||||
baseApiUrl = `${url.protocol}//${url.host}`;
|
||||
console.log(`[通知测试 - Telegram] 使用自定义域名: ${baseApiUrl}`);
|
||||
} catch (e) {
|
||||
console.warn(`[通知测试 - Telegram] 无效的自定义域名 URL: ${config.customDomain}。将回退到默认 Telegram API。`);
|
||||
}
|
||||
}
|
||||
const telegramApiUrl = `${baseApiUrl}/bot${config.botToken}/sendMessage`;
|
||||
|
||||
try {
|
||||
console.log(
|
||||
@@ -802,7 +812,18 @@ export class NotificationService {
|
||||
}
|
||||
console.log(`[_sendTelegram] Final message text to send:`, messageText);
|
||||
|
||||
const telegramApiUrl = `https://api.telegram.org/bot${config.botToken}/sendMessage`;
|
||||
let baseApiUrlSend = "https://api.telegram.org";
|
||||
if (config.customDomain) {
|
||||
try {
|
||||
const url = new URL(config.customDomain);
|
||||
baseApiUrlSend = `${url.protocol}//${url.host}`;
|
||||
console.log(`[_sendTelegram] 使用自定义域名: ${baseApiUrlSend} (事件: ${payload.event})`);
|
||||
} catch (e) {
|
||||
console.warn(`[_sendTelegram] 无效的自定义域名 URL: ${config.customDomain} (事件: ${payload.event})。将回退到默认 Telegram API。`);
|
||||
}
|
||||
}
|
||||
const telegramApiUrl = `${baseApiUrlSend}/bot${config.botToken}/sendMessage`;
|
||||
|
||||
try {
|
||||
console.log(
|
||||
`[通知] 发送 Telegram 消息到聊天 ID ${config.chatId} (事件: ${payload.event})`
|
||||
|
||||
@@ -6,7 +6,7 @@ import { TelegramConfig } from "../../types/notification.types";
|
||||
class TelegramSenderService implements INotificationSender {
|
||||
async send(notification: ProcessedNotification): Promise<void> {
|
||||
const config = notification.config as TelegramConfig;
|
||||
const { botToken, chatId } = config;
|
||||
const { botToken, chatId, customDomain } = config; // Destructure customDomain
|
||||
const messageBody = notification.body;
|
||||
|
||||
if (!botToken || !chatId) {
|
||||
@@ -18,7 +18,19 @@ class TelegramSenderService implements INotificationSender {
|
||||
);
|
||||
}
|
||||
|
||||
const apiUrl = `https://api.telegram.org/bot${botToken}/sendMessage`;
|
||||
let baseApiUrl = "https://api.telegram.org";
|
||||
if (customDomain) {
|
||||
try {
|
||||
const url = new URL(customDomain); // Validate and parse the custom domain
|
||||
baseApiUrl = `${url.protocol}//${url.host}`; // Use protocol and host from customDomain
|
||||
console.log(`[TelegramSender] Using custom domain: ${baseApiUrl}`);
|
||||
} catch (e) {
|
||||
console.warn(`[TelegramSender] Invalid customDomain URL: ${customDomain}. Falling back to default Telegram API.`);
|
||||
// Optionally, you could throw an error here or decide to proceed with the default
|
||||
}
|
||||
}
|
||||
|
||||
const apiUrl = `${baseApiUrl}/bot${botToken}/sendMessage`;
|
||||
|
||||
try {
|
||||
console.log(
|
||||
|
||||
@@ -753,7 +753,7 @@ export class SftpService {
|
||||
}
|
||||
|
||||
try {
|
||||
// --- 新增:移动前检查目标是否存在 ---
|
||||
// --- 移动前检查目标是否存在 ---
|
||||
let targetExists = false;
|
||||
try {
|
||||
await this.getStats(sftp, newPath);
|
||||
@@ -1011,7 +1011,7 @@ export class SftpService {
|
||||
console.log(`[SFTP Upload ${uploadId}] Starting upload for ${remotePath} (${totalSize} bytes) in session ${sessionId}`);
|
||||
|
||||
try {
|
||||
// --- 新增:在创建流之前确保目录存在 ---
|
||||
// --- 在创建流之前确保目录存在 ---
|
||||
if (relativePath) {
|
||||
const targetDirectory = pathModule.dirname(remotePath).replace(/\\/g, '/');
|
||||
console.log(`[SFTP Upload ${uploadId}] Ensuring directory exists: ${targetDirectory}`);
|
||||
@@ -1029,7 +1029,7 @@ export class SftpService {
|
||||
}
|
||||
// --- 结束新增 ---
|
||||
|
||||
// --- 新增:预检查文件是否可写 ---
|
||||
// --- 预检查文件是否可写 ---
|
||||
console.log(`[SFTP Upload ${uploadId}] Pre-checking writability for: ${remotePath}`);
|
||||
try {
|
||||
// 确保 state.sftp 存在
|
||||
|
||||
Reference in New Issue
Block a user