mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-12 06:01:28 +03:00
Added filters for notifications
Added notifications for tasks
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const { uuid } = require('uuidv4');
|
||||
const db_api = require('./db');
|
||||
const config_api = require('./config');
|
||||
|
||||
exports.sendNotification = async (notification) => {
|
||||
// TODO: hook into third party service
|
||||
@@ -7,6 +8,15 @@ exports.sendNotification = async (notification) => {
|
||||
return notification;
|
||||
}
|
||||
|
||||
exports.sendTaskNotification = async (task_obj, confirmed) => {
|
||||
// workaround for tasks which are user_uid agnostic
|
||||
const user_uid = config_api.getConfigItem('ytdl_multi_user_mode') ? 'admin' : null;
|
||||
await db_api.removeAllRecords('notifications', {"data.task_key": task_obj.key});
|
||||
const data = {task_key: task_obj.key, task_title: task_obj.title, confirmed: confirmed};
|
||||
const notification = exports.createNotification('task_finished', ['view_tasks'], data, user_uid);
|
||||
return await exports.sendNotification(notification);
|
||||
}
|
||||
|
||||
exports.sendDownloadNotification = async (file, user_uid) => {
|
||||
const data = {file_uid: file.uid, file_title: file.title};
|
||||
const notification = exports.createNotification('download_complete', ['play'], data, user_uid);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const db_api = require('./db');
|
||||
const notifications_api = require('./notifications');
|
||||
const youtubedl_api = require('./youtube-dl');
|
||||
|
||||
const fs = require('fs-extra');
|
||||
@@ -128,6 +129,8 @@ exports.executeRun = async (task_key) => {
|
||||
const data = await TASKS[task_key].run();
|
||||
await db_api.updateRecord('tasks', {key: task_key}, {data: TASKS[task_key]['confirm'] ? data : null, last_ran: Date.now()/1000, running: false});
|
||||
logger.verbose(`Finished running task ${task_key}`);
|
||||
const task_obj = await db_api.getRecord('tasks', {key: task_key});
|
||||
await notifications_api.sendTaskNotification(task_obj, false);
|
||||
}
|
||||
|
||||
exports.executeConfirm = async (task_key) => {
|
||||
@@ -141,6 +144,7 @@ exports.executeConfirm = async (task_key) => {
|
||||
await TASKS[task_key].confirm(data);
|
||||
await db_api.updateRecord('tasks', {key: task_key}, {confirming: false, last_confirmed: Date.now()/1000, data: null});
|
||||
logger.verbose(`Finished confirming task ${task_key}`);
|
||||
await notifications_api.sendTaskNotification(task_obj, false);
|
||||
}
|
||||
|
||||
exports.updateTaskSchedule = async (task_key, schedule) => {
|
||||
|
||||
Reference in New Issue
Block a user