From f44be291813ac2ca493076cf6f3c83f37cbf253f Mon Sep 17 00:00:00 2001 From: Isaac Abadi Date: Fri, 25 Nov 2022 18:20:08 -0500 Subject: [PATCH] Added support for download error notifications Style improvements --- backend/downloader.js | 19 +++++++++++-------- .../notifications-list.component.html | 8 ++++---- .../notifications-list.component.ts | 2 +- .../notifications.component.html | 6 +++--- .../notifications/notifications.component.ts | 3 +-- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/backend/downloader.js b/backend/downloader.js index 4309691..0aff889 100644 --- a/backend/downloader.js +++ b/backend/downloader.js @@ -107,9 +107,10 @@ exports.clearDownload = async (download_uid) => { return await db_api.removeRecord('download_queue', {uid: download_uid}); } -async function handleDownloadError(download_uid, error_message) { - if (!download_uid) return; - await db_api.updateRecord('download_queue', {uid: download_uid}, {error: error_message, finished: true, running: false}); +async function handleDownloadError(download, error_message) { + if (!download || !download['uid']) return; + notifications_api.sendDownloadErrorNotification(download, download['user_uid']); + await db_api.updateRecord('download_queue', {uid: download['uid']}, {error: error_message, finished: true, running: false}); } async function setupDownloads() { @@ -273,14 +274,14 @@ async function downloadQueuedFile(download_uid) { clearInterval(download_checker); if (err) { logger.error(err.stderr); - await handleDownloadError(download_uid, err.stderr); + await handleDownloadError(download, err.stderr); resolve(false); return; } else if (output) { if (output.length === 0 || output[0].length === 0) { // ERROR! const error_message = `No output received for video download, check if it exists in your archive.`; - await handleDownloadError(download_uid, error_message); + await handleDownloadError(download, error_message); logger.warn(error_message); resolve(false); return; @@ -366,7 +367,7 @@ async function downloadQueuedFile(download_uid) { } else { const error_message = 'Downloaded file failed to result in metadata object.'; logger.error(error_message); - await handleDownloadError(download_uid, error_message); + await handleDownloadError(download, error_message); } const file_uids = file_objs.map(file_obj => file_obj.uid); @@ -562,7 +563,8 @@ exports.getVideoInfoByURL = async (url, args = [], download_uid = null) => { const error = `Error while retrieving info on video with URL ${url} with the following message: output JSON could not be parsed. Output JSON: ${output}`; logger.error(error); if (download_uid) { - await handleDownloadError(download_uid, error); + const download = await db_api.getRecord('download_queue', {uid: download_uid}); + await handleDownloadError(download, error); } resolve(null); } @@ -571,7 +573,8 @@ exports.getVideoInfoByURL = async (url, args = [], download_uid = null) => { if (err.stderr) error_message += `\n\n${err.stderr}`; logger.error(error_message); if (download_uid) { - await handleDownloadError(download_uid, error_message); + const download = await db_api.getRecord('download_queue', {uid: download_uid}); + await handleDownloadError(download, error_message); } resolve(null); } diff --git a/src/app/components/notifications-list/notifications-list.component.html b/src/app/components/notifications-list/notifications-list.component.html index 4a85513..d0923fc 100644 --- a/src/app/components/notifications-list/notifications-list.component.html +++ b/src/app/components/notifications-list/notifications-list.component.html @@ -1,6 +1,6 @@
-
+
{{NOTIFICATION_PREFIX[notification.type]}}  @@ -8,10 +8,10 @@ {{notification['data'][NOTIFICATION_SUFFIX_KEY[notification.type]]}}
-
- +
+ - +
\ No newline at end of file diff --git a/src/app/components/notifications-list/notifications-list.component.ts b/src/app/components/notifications-list/notifications-list.component.ts index 845773a..b8e424b 100644 --- a/src/app/components/notifications-list/notifications-list.component.ts +++ b/src/app/components/notifications-list/notifications-list.component.ts @@ -21,7 +21,7 @@ export class NotificationsListComponent { // Attaches string to the end of the notification text NOTIFICATION_SUFFIX_KEY: { [key in NotificationType]: string } = { download_complete: 'file_title', - download_error: 'file_url' + download_error: 'download_url' } NOTIFICATION_ACTION_TO_STRING: { [key in NotificationAction]: string } = { diff --git a/src/app/components/notifications/notifications.component.html b/src/app/components/notifications/notifications.component.html index 901485b..67e8a99 100644 --- a/src/app/components/notifications/notifications.component.html +++ b/src/app/components/notifications/notifications.component.html @@ -1,10 +1,10 @@ -

No notifications available

+No notifications available
-

New notifications

+ New notifications
-

Old notifications

+ Old notifications
\ No newline at end of file diff --git a/src/app/components/notifications/notifications.component.ts b/src/app/components/notifications/notifications.component.ts index 6667a1e..50ed7fc 100644 --- a/src/app/components/notifications/notifications.component.ts +++ b/src/app/components/notifications/notifications.component.ts @@ -1,5 +1,4 @@ -import { Component, ElementRef, EventEmitter, Input, OnInit, Output } from '@angular/core'; -import { MatMenuTrigger } from '@angular/material/menu'; +import { Component, ElementRef, EventEmitter, OnInit, Output } from '@angular/core'; import { Router } from '@angular/router'; import { PostsService } from 'app/posts.services'; import { Notification } from 'api-types';