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,QAAO,CAAC,EAAG,IAAQ,EAAO,KACtC,EAAS,EAAO,OAAO,SACvB,MAAM,QAAqB,KAAK,wBAAwB,GAElD,QAAiB,QAAQ,IAC9B,EAAK,KAAI,MAAO,EAAK,IAAQ,qBAAqB,EAAc,EAAa,GAAK,aAGnF,UACO,QAAQ,IAAI,EAAO,KAAI,MAAO,EAAO,IAAQ,KAAK,KAAK,EAAO,EAAS,MAC9E,CAAE,MAAO,GACR,QAAQ,MAAM,EAAI,MACnB,GAGD,OAAO,WAAa,OAAS,QAAO,WACnC,MAAM,QAAmB,OAAO,eAAc,GAC9C,IAAK,IAAe,EAAW,KAC9B,OAGD,IAAI,MAAE,EAAK,KAAE,GAAS,EACtB,EAAO,EAAK,KAAI,GAAO,EAAI,QACvB,IACH,EAAQ,MAAM,mBAAmB,GACjC,EAAQ,EAAM,QAAQ,KAAM,QAG7B,MAAM,EAAS,EACb,KAAI,GAAO,EAAW,IAAI,KAC1B,OAAO,SACP,QAAO,CAAC,EAAK,EAAK,IAAW,EAAO,QAAQ,KAAS,IACjD,EAAQ,EACZ,KAAI,GAAS,EAAM,QACnB,OAAO,SACP,QAAO,CAAC,EAAK,EAAK,IAAW,EAAO,QAAQ,KAAS,IACrD,MAEF,IAAK,EAAO,OACX,OAGD,MAAM,QAAgB,qBAAqB,CAC1C,UAAW,sCAAsC,EAAK,KAAK,gBAAgB,MAC3E,SAAU,EAAK,QACf,KAAM,SAAS,EAAK,YAClB,EAAW,CACb,UAAW,UAGN,QAAQ,IAAI,EAAO,KAAI,GAAS,KAAK,KAAK,EAAM,QAAS,KAAU,EAG1E,OAAO,QAAU","file":"/npm/nodebb-plugin-ntfy@1.7.7/library.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/nodebb-plugin-ntfy@1.7.7/library.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nconst validator = require('validator');\n\nconst nconf = require.main.require('nconf');\n\nconst user = require.main.require('./src/user');\nconst meta = require.main.require('./src/meta');\nconst translator = require.main.require('./src/translator');\nconst routeHelpers = require.main.require('./src/routes/helpers');\nconst utils = require.main.require('./src/utils');\n\nconst controllers = require('./lib/controllers');\nconst ntfy = require('./lib/ntfy');\n\nconst plugin = {};\n\nplugin.init = async (params) => {\n\tconst { router, middleware /* , controllers */ } = params;\n\tconst accountMiddlewares = [\n\t\tmiddleware.exposeUid,\n\t\tmiddleware.ensureLoggedIn,\n\t\tmiddleware.canViewUsers,\n\t\tmiddleware.checkAccountPermissions,\n\t];\n\n\t// v2 compatibility\n\tif (!nconf.get('version').startsWith('2')) {\n\t\taccountMiddlewares.push(middleware.buildAccountData);\n\t} else {\n\t\tconst accountHelpers = require.main.require('./src/controllers/accounts/helpers');\n\t\taccountMiddlewares.push(async (req, res, next) => {\n\t\t\tres.locals.templateValues = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query);\n\t\t\tnext();\n\t\t});\n\t}\n\n\trouteHelpers.setupPageRoute(router, '/user/:userslug/ntfy', accountMiddlewares, controllers.renderSettings);\n\n\trouteHelpers.setupAdminPageRoute(router, '/admin/plugins/ntfy', [], controllers.renderAdminPage);\n};\n\nplugin.addRoutes = async ({ router, middleware }) => {\n\tconst middlewares = [\n\t\tmiddleware.ensureLoggedIn,\n\t];\n\n\trouteHelpers.setupApiRoute(router, 'post', '/ntfy/regenerate', middlewares, controllers.regenerateTopic);\n\trouteHelpers.setupApiRoute(router, 'post', '/ntfy/test', middlewares, controllers.sendTestNotification);\n};\n\nplugin.addAdminNavigation = (header) => {\n\theader.plugins.push({\n\t\troute: '/plugins/ntfy',\n\t\ticon: 'fa-tint',\n\t\tname: 'Push Notifications (ntfy)',\n\t});\n\n\treturn header;\n};\n\nplugin.getNotifyTags = async (returnMap) => {\n\tlet { notifyTags, notifyChannels, notifyEmails } = await meta.settings.get('ntfy');\n\tif (!notifyTags || !notifyChannels) {\n\t\treturn [];\n\t}\n\n\t[notifyChannels, notifyTags, notifyEmails] = [notifyChannels, notifyTags, notifyEmails].map(arr => (!Array.isArray(arr) ? arr.split(',') : arr));\n\n\treturn returnMap ?\n\t\tnotifyTags.reduce((map, tag, idx) => {\n\t\t\tmap.set(tag, {\n\t\t\t\tchannel: notifyChannels[idx],\n\t\t\t\temail: notifyEmails[idx],\n\t\t\t});\n\t\t\treturn map;\n\t\t}, new Map()) :\n\t\tnotifyTags.map((tag, idx) => ({\n\t\t\ttag,\n\t\t\tchannel: notifyChannels[idx],\n\t\t\temail: notifyEmails[idx],\n\t\t}));\n};\n\nplugin.addProfileItem = async (data) => {\n\tconst title = await translator.translate('[[ntfy:profile.label]]');\n\tdata.links.push({\n\t\tid: 'ntfy',\n\t\troute: 'ntfy',\n\t\ticon: 'fa-bell-o',\n\t\tname: title,\n\t\tvisibility: {\n\t\t\tself: true,\n\t\t\tother: false,\n\t\t\tmoderator: false,\n\t\t\tglobalMod: false,\n\t\t\tadmin: false,\n\t\t},\n\t});\n\n\treturn data;\n};\n\nasync function constructNtfyPayload({ bodyShort, bodyLong, path }, language, headers = {}) {\n\tlet { maxLength, dropBodyLong } = await meta.settings.get('ntfy');\n\tmaxLength = parseInt(maxLength, 10) || 256;\n\n\tif (dropBodyLong === 'on') {\n\t\tbodyLong = undefined;\n\t}\n\n\tif (!language) {\n\t\tlanguage = meta.config.defaultLang || 'en-GB';\n\t}\n\n\tlet [Title, body] = await translator.translateKeys([bodyShort, bodyLong], language);\n\t([Title, body] = [Title, body].map(str => validator.unescape(utils.stripHTMLTags(str))));\n\tconst Click = `${nconf.get('url')}${path}`;\n\n\t// Handle empty bodyLong\n\tif (!bodyLong) {\n\t\tbody = Title;\n\t\tTitle = meta.config.title || 'NodeBB';\n\t}\n\n\t// Truncate body if needed\n\tif (body.length > maxLength) {\n\t\tbody = `${body.slice(0, maxLength)}…`;\n\t}\n\n\treturn {\n\t\tbody,\n\t\theaders: {\n\t\t\tTitle,\n\t\t\tClick,\n\t\t\t...headers,\n\t\t},\n\t};\n}\n\nplugin.onNotificationPush = async ({ notification, uidsNotified: uids }) => {\n\tlet topics = (await user.getUsersFields(uids, ['ntfyTopic'])).map(obj => obj.ntfyTopic);\n\tuids = uids.filter((_, idx) => topics[idx]);\n\ttopics = topics.filter(Boolean);\n\tconst userSettings = await user.getMultipleUserSettings(uids);\n\n\tconst payloads = await Promise.all(\n\t\tuids.map(async (uid, idx) => constructNtfyPayload(notification, userSettings[idx].userLang))\n\t);\n\n\ttry {\n\t\tawait Promise.all(topics.map(async (topic, idx) => ntfy.send(topic, payloads[idx])));\n\t} catch (err) {\n\t\tconsole.error(err.stack);\n\t}\n};\n\nplugin.onTopicTag = async ({ topic, post }) => {\n\tconst notifyTags = await plugin.getNotifyTags(true);\n\tif (!notifyTags || !notifyTags.size) {\n\t\treturn;\n\t}\n\n\tlet { title, tags } = topic;\n\ttags = tags.map(tag => tag.value);\n\tif (title) {\n\t\ttitle = utils.decodeHTMLEntities(title);\n\t\ttitle = title.replace(/,/g, '\\\\,');\n\t}\n\n\tconst topics = tags\n\t\t.map(tag => notifyTags.get(tag))\n\t\t.filter(Boolean)\n\t\t.filter((tag, idx, source) => source.indexOf(tag) === idx);\n\tconst email = topics\n\t\t.map(topic => topic.email)\n\t\t.filter(Boolean)\n\t\t.filter((tag, idx, source) => source.indexOf(tag) === idx)\n\t\t.pop(); // only one email is supported per notification\n\n\tif (!topics.length) {\n\t\treturn;\n\t}\n\n\tconst payload = await constructNtfyPayload({\n\t\tbodyShort: `[[notifications:user-posted-topic, ${post.user.displayname}, ${title}]]`,\n\t\tbodyLong: post.content,\n\t\tpath: `/post/${post.pid}`,\n\t}, undefined, {\n\t\t'X-Email': email,\n\t});\n\n\tawait Promise.all(topics.map(topic => ntfy.send(topic.channel, payload)));\n};\n\nmodule.exports = plugin;\n"]}