mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-24 07:53:20 +03:00
Added ability to set a webhook proxy for telegram requests
Fixed issue where config changes were broadcast before they were written
This commit is contained in:
@@ -49,6 +49,7 @@
|
|||||||
"use_telegram_API": false,
|
"use_telegram_API": false,
|
||||||
"telegram_bot_token": "",
|
"telegram_bot_token": "",
|
||||||
"telegram_chat_id": "",
|
"telegram_chat_id": "",
|
||||||
|
"telegram_webhook_proxy": "",
|
||||||
"webhook_URL": "",
|
"webhook_URL": "",
|
||||||
"discord_webhook_URL": "",
|
"discord_webhook_URL": "",
|
||||||
"slack_webhook_URL": ""
|
"slack_webhook_URL": ""
|
||||||
|
|||||||
@@ -85,11 +85,11 @@ exports.getConfigFile = () => {
|
|||||||
exports.setConfigFile = (config) => {
|
exports.setConfigFile = (config) => {
|
||||||
try {
|
try {
|
||||||
const old_config = exports.getConfigFile();
|
const old_config = exports.getConfigFile();
|
||||||
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
const changes = exports.findChangedConfigItems(old_config, config);
|
const changes = exports.findChangedConfigItems(old_config, config);
|
||||||
if (changes.length > 0) {
|
if (changes.length > 0) {
|
||||||
for (const change of changes) exports.config_updated.next(change);
|
for (const change of changes) exports.config_updated.next(change);
|
||||||
}
|
}
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
||||||
return true;
|
return true;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return false;
|
return false;
|
||||||
@@ -239,6 +239,7 @@ const DEFAULT_CONFIG = {
|
|||||||
"use_telegram_API": false,
|
"use_telegram_API": false,
|
||||||
"telegram_bot_token": "",
|
"telegram_bot_token": "",
|
||||||
"telegram_chat_id": "",
|
"telegram_chat_id": "",
|
||||||
|
"telegram_webhook_proxy": "",
|
||||||
"webhook_URL": "",
|
"webhook_URL": "",
|
||||||
"discord_webhook_URL": "",
|
"discord_webhook_URL": "",
|
||||||
"slack_webhook_URL": "",
|
"slack_webhook_URL": "",
|
||||||
|
|||||||
@@ -154,6 +154,10 @@ exports.CONFIG_ITEMS = {
|
|||||||
'key': 'ytdl_telegram_chat_id',
|
'key': 'ytdl_telegram_chat_id',
|
||||||
'path': 'YoutubeDLMaterial.API.telegram_chat_id'
|
'path': 'YoutubeDLMaterial.API.telegram_chat_id'
|
||||||
},
|
},
|
||||||
|
'ytdl_telegram_webhook_proxy': {
|
||||||
|
'key': 'ytdl_telegram_webhook_proxy',
|
||||||
|
'path': 'YoutubeDLMaterial.API.telegram_webhook_proxy'
|
||||||
|
},
|
||||||
'ytdl_webhook_url': {
|
'ytdl_webhook_url': {
|
||||||
'key': 'ytdl_webhook_url',
|
'key': 'ytdl_webhook_url',
|
||||||
'path': 'YoutubeDLMaterial.API.webhook_URL'
|
'path': 'YoutubeDLMaterial.API.webhook_URL'
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ const REST = require('@discordjs/rest').REST;
|
|||||||
const API = require('@discordjs/core').API;
|
const API = require('@discordjs/core').API;
|
||||||
const EmbedBuilder = require('@discordjs/builders').EmbedBuilder;
|
const EmbedBuilder = require('@discordjs/builders').EmbedBuilder;
|
||||||
|
|
||||||
const debugMode = process.env.YTDL_MODE === 'debug';
|
|
||||||
|
|
||||||
const NOTIFICATION_TYPE_TO_TITLE = {
|
const NOTIFICATION_TYPE_TO_TITLE = {
|
||||||
task_finished: 'Task finished',
|
task_finished: 'Task finished',
|
||||||
download_complete: 'Download complete',
|
download_complete: 'Download complete',
|
||||||
@@ -160,7 +158,7 @@ config_api.config_updated.subscribe(change => {
|
|||||||
const bot_token = config_api.getConfigItem('ytdl_telegram_bot_token');
|
const bot_token = config_api.getConfigItem('ytdl_telegram_bot_token');
|
||||||
if (!use_telegram_api || !bot_token) return;
|
if (!use_telegram_api || !bot_token) return;
|
||||||
if (!change) return;
|
if (!change) return;
|
||||||
if (change['key'] === 'ytdl_use_telegram_API' || change['key'] === 'ytdl_telegram_bot_token') {
|
if (change['key'] === 'ytdl_use_telegram_API' || change['key'] === 'ytdl_telegram_bot_token' || change['key'] === 'ytdl_telegram_webhook_proxy') {
|
||||||
logger.debug('Telegram bot setting up');
|
logger.debug('Telegram bot setting up');
|
||||||
setupTelegramBot();
|
setupTelegramBot();
|
||||||
}
|
}
|
||||||
@@ -172,7 +170,8 @@ async function setupTelegramBot() {
|
|||||||
if (!use_telegram_api || !bot_token) return;
|
if (!use_telegram_api || !bot_token) return;
|
||||||
|
|
||||||
telegram_bot = new TelegramBotAPI(bot_token);
|
telegram_bot = new TelegramBotAPI(bot_token);
|
||||||
const webhook_url = `${utils.getBaseURL()}/api/telegramRequest`;
|
const webhook_proxy = config_api.getConfigItem('ytdl_telegram_webhook_proxy');
|
||||||
|
const webhook_url = webhook_proxy ? webhook_proxy : `${utils.getBaseURL()}/api/telegramRequest`;
|
||||||
telegram_bot.setWebHook(webhook_url);
|
telegram_bot.setWebHook(webhook_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -426,6 +426,13 @@
|
|||||||
<mat-hint><a target="_blank" href="https://stackoverflow.com/a/37396871/8088021"><ng-container i18n="Telegram chat ID help">How do I get the chat ID?</ng-container></a></mat-hint>
|
<mat-hint><a target="_blank" href="https://stackoverflow.com/a/37396871/8088021"><ng-container i18n="Telegram chat ID help">How do I get the chat ID?</ng-container></a></mat-hint>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-12 mb-2">
|
||||||
|
<mat-form-field class="text-field" color="accent">
|
||||||
|
<mat-label i18n="Telegram webhook proxy">Telegram webhook proxy</mat-label>
|
||||||
|
<input placeholder="https://smee.io/XXXXX" [disabled]="!new_config['Extra']['enable_notifications'] || !new_config['API']['use_telegram_API']" [(ngModel)]="new_config['API']['telegram_webhook_proxy']" matInput>
|
||||||
|
<mat-hint><a target="_blank" href="https://smee.io/"><ng-container i18n="Telegram webhook proxy help">Example service</ng-container></a></mat-hint>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
|||||||
Reference in New Issue
Block a user