-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfiles_downloadlimit-public.mjs.map
More file actions
1 lines (1 loc) · 4.6 KB
/
files_downloadlimit-public.mjs.map
File metadata and controls
1 lines (1 loc) · 4.6 KB
1
{"version":3,"file":"files_downloadlimit-public.mjs","sources":["../src/public.ts"],"sourcesContent":["/**\n * @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>\n *\n * @author Christopher Ng <chrng8@gmail.com>\n * @author John Molakvoæ <skjnldsv@protonmail.com>\n *\n * @license GNU AGPL version 3 or any later version\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n *\n */\n\nimport { loadState } from '@nextcloud/initial-state'\nimport { translate as t, translatePlural as n } from '@nextcloud/l10n'\n\nimport '../css/public.css'\n\nimport { logger } from './logger.ts'\n\nconst { limit, downloads } = loadState('files_downloadlimit', 'download_limit', { limit: -1, downloads: 0 })\nlogger.debug('Download limit', { limit, downloads })\n\n// Global variables init on page load\nlet count = limit - downloads\nlet clicks = 0\n\n/**\n * Update the span counter message\n *\n * @param span html span element to update\n * @param count number of remaining downloads allowed\n */\nconst updateCounter = (span: HTMLSpanElement, count: number) => {\n\tif (count === 0) {\n\t\tspan.innerText = t('files_downloadlimit', 'You have reached the maximum amount of downloads allowed')\n\t} else {\n\t\tspan.innerText = n('files_downloadlimit', '1 remaining download allowed', '{count} remaining downloads allowed', count, { count })\n\t}\n}\n\nwindow.addEventListener('DOMContentLoaded', () => {\n\tif (limit < 1) {\n\t\treturn\n\t}\n\n\tconst container = document.getElementById('header-primary-action')\n\tif (!container) {\n\t\treturn\n\t}\n\n\tconst span = document.createElement('span')\n\tspan.setAttribute('style', 'color: var(--color-primary-text); padding: 0 10px;')\n\tupdateCounter(span, count)\n\tcontainer.prepend(span)\n\n\tconst publicContent = document.querySelector<HTMLElement>('#files-public-content')\n\tif (!publicContent) {\n\t\treturn\n\t}\n\n\t// Preventing mouse interaction\n\tpublicContent.oncontextmenu = (event) => {\n\t\tevent.preventDefault()\n\t\tevent.stopPropagation()\n\t\treturn false\n\t}\n\n\t// Adding double-download warning\n\tconst downloadButtons = document.querySelectorAll<HTMLAnchorElement>('a[href*=\"/download/\"]') || []\n\tnew Set(downloadButtons).forEach(button => {\n\t\tbutton.addEventListener('click', (event) => {\n\t\t\t// Warn about download limits\n\t\t\tif (clicks > 0) {\n\t\t\t\tif (!confirm(t('files_downloadlimit', 'This share has a limited number of downloads. Are you sure you want to trigger a new download?'))) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tevent.stopPropagation()\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Handle counts changes\n\t\t\tcount--\n\t\t\tclicks++\n\t\t\tupdateCounter(span, count)\n\n\t\t\t// Remove the buttons if share is now expired\n\t\t\tif (count === 0) {\n\t\t\t\t[...downloadButtons].forEach(button => button.remove())\n\t\t\t}\n\t\t})\n\t})\n})\n"],"names":["limit","downloads","loadState","logger","count","clicks","updateCounter","span","t","n","container","publicContent","event","downloadButtons","button"],"mappings":";uIA8BA,KAAM,CAAE,MAAAA,EAAO,UAAAC,GAAcC,EAAU,sBAAuB,iBAAkB,CAAE,MAAO,GAAI,UAAW,CAAG,CAAA,EAC3GC,EAAO,MAAM,iBAAkB,CAAE,MAAAH,EAAO,UAAAC,CAAW,CAAA,EAGnD,IAAIG,EAAQJ,EAAQC,EAChBI,EAAS,EAQb,MAAMC,EAAgB,CAACC,EAAuBH,IAAkB,CAC3DA,IAAU,EACRG,EAAA,UAAYC,EAAE,sBAAuB,0DAA0D,E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