UNPKG

yt-dlx

Version:

Effortless Audio-Video Downloader And Streamer!

52 lines 2.37 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = unseen_notifications; const colors_1 = __importDefault(require("colors")); const zod_1 = require("zod"); const TubeLogin_1 = __importDefault(require("../../utils/TubeLogin")); const ZodSchema = zod_1.z.object({ cookies: zod_1.z.string(), verbose: zod_1.z.boolean().optional() }); async function unseen_notifications(options) { try { ZodSchema.parse(options); const { verbose, cookies } = options; if (verbose) console.log(colors_1.default.green("@info:"), "Fetching unseen notifications..."); if (!cookies) { throw new Error(`${colors_1.default.red("@error:")} Cookies not provided!`); } const client = await (0, TubeLogin_1.default)(cookies); if (!client) { throw new Error(`${colors_1.default.red("@error:")} Could not initialize Tube client.`); } const count = await client.getUnseenNotificationsCount(); if (count === undefined) { throw new Error(`${colors_1.default.red("@error:")} Failed to fetch unseen notifications count.`); } const result = { status: "success", data: { count: Number(count) || 0 } }; if (verbose) console.log(colors_1.default.green("@info:"), "❣️ Thank you for using yt-dlx. Consider 🌟starring the GitHub repo https://github.com/yt-dlx."); return result; } catch (error) { if (error instanceof zod_1.ZodError) { const errorMessage = `${colors_1.default.red("@error:")} Argument validation failed: ${error.errors.map(e => `${e.path.join(".")}: ${e.message}`).join(", ")}`; console.error(errorMessage); throw new Error(errorMessage); } else if (error instanceof Error) { console.error(error.message); throw error; } else { const unexpectedError = `${colors_1.default.red("@error:")} An unexpected error occurred: ${String(error)}`; console.error(unexpectedError); throw new Error(unexpectedError); } } finally { } } //# sourceMappingURL=UnseenNotifications.js.map