From 07a0ea6d180fb68110d756065e9abfb4a3fa4ee7 Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Mon, 27 Mar 2023 19:14:15 -0400 Subject: [PATCH] Download notifications now include original URL Fixed minor notification crash --- backend/notifications.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/notifications.js b/backend/notifications.js index cee3c4f..12ec791 100644 --- a/backend/notifications.js +++ b/backend/notifications.js @@ -17,8 +17,8 @@ const NOTIFICATION_TYPE_TO_TITLE = { const NOTIFICATION_TYPE_TO_BODY = { task_finished: (notification) => notification['data']['task_title'], - download_complete: (notification) => notification['data']['file_title'], - download_error: (notification) => notification['data']['download_url'] + download_complete: (notification) => {return `${notification['data']['file_title']}\nOriginal URL: ${notification['data']['original_url']}`}, + download_error: (notification) => {return `Error: ${notification['data']['download_error_type']}\nURL: ${notification['data']['download_url']}`} } const NOTIFICATION_TYPE_TO_URL = { @@ -28,7 +28,9 @@ const NOTIFICATION_TYPE_TO_URL = { } const NOTIFICATION_TYPE_TO_THUMBNAIL = { - download_complete: (notification) => notification['data']['file_thumbnail'] + task_finished: () => null, + download_complete: (notification) => notification['data']['file_thumbnail'], + download_error: () => null } exports.sendNotification = async (notification) => { @@ -64,7 +66,7 @@ exports.sendTaskNotification = async (task_obj, confirmed) => { exports.sendDownloadNotification = async (file, user_uid) => { if (!notificationEnabled('download_complete')) return; - const data = {file_uid: file.uid, file_title: file.title, file_thumbnail: file.thumbnailURL}; + const data = {file_uid: file.uid, file_title: file.title, file_thumbnail: file.thumbnailURL, original_url: file.url}; const notification = exports.createNotification('download_complete', ['play'], data, user_uid); return await exports.sendNotification(notification); } @@ -131,5 +133,5 @@ async function sendTelegramNotification(body, title, type, url, thumbnail) { const chat_id = config_api.getConfigItem('ytdl_telegram_chat_id'); const bot = new TelegramBot(bot_token); if (thumbnail) await bot.sendPhoto(chat_id, thumbnail); - bot.sendMessage(chat_id, `${title}\n\n${body}\n${url}`, {parse_mode: 'HTML'}); + bot.sendMessage(chat_id, `${title}\n\n${body}\n${url}`, {parse_mode: 'HTML'}); } \ No newline at end of file