-
Notifications
You must be signed in to change notification settings - Fork 6
Fix public handling of limited shares #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| /* Prevent user interaction on content */ | ||
| #imgframe { | ||
| pointer-events: none; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,20 +20,64 @@ | |
| * | ||
| */ | ||
| import { loadState } from '@nextcloud/initial-state' | ||
| import { translatePlural as n } from '@nextcloud/l10n' | ||
| import { translate as t, translatePlural as n } from '@nextcloud/l10n' | ||
|
|
||
| import '../css/public.css' | ||
|
|
||
| const { limit, downloads } = loadState(appName, 'download_limit', { limit: -1, downloads: 0 }) | ||
| console.debug('[DEBUG]', appName, { limit, downloads }) | ||
|
|
||
| let count = limit - downloads | ||
| let clicks = 0 | ||
|
|
||
| const updateCounter = function(span) { | ||
| if (count === 0) { | ||
| span.innerText = t(appName, 'You have reached the maximum amount of downloads allowed') | ||
| } else { | ||
| span.innerText = n(appName, '1 remaining download allowed', '{count} remaining downloads allowed', count, { count }) | ||
| } | ||
| } | ||
|
|
||
| window.addEventListener('DOMContentLoaded', function() { | ||
| if (limit > 0) { | ||
| const count = limit - downloads | ||
| const container = document.getElementById('header-primary-action') | ||
| const span = document.createElement('span') | ||
|
|
||
| span.style = 'color: var(--color-primary-text); padding: 0 10px;' | ||
| span.innerText = n('files_downloadlimit', '1 remaining download allowed', '{count} remaining downloads allowed', count, { count }) | ||
| updateCounter(span, count) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or extra count parameter here, not clear, it seems count is actually global
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's cleaner, you're right, let me fix in a pr :)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| container.prepend(span) | ||
|
|
||
| // Preventing mouse interaction | ||
| document.querySelector('#files-public-content').oncontextmenu = function(event) { | ||
| event.preventDefault() | ||
| event.stopPropagation() | ||
| return false | ||
| } | ||
|
|
||
| // Adding double-download warning | ||
| const downloadButtons = document.querySelectorAll('a[href*="/download/"]') || [] | ||
| new Set(downloadButtons).forEach(button => { | ||
| button.addEventListener('click', (event) => { | ||
| // Warn about download limits | ||
| if (clicks > 0) { | ||
| if (!confirm(t(appName, 'This share has a limited number of downloads. Are you sure you want to trigger a new download?'))) { | ||
| event.preventDefault() | ||
| event.stopPropagation() | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // Handle counts changes | ||
| count-- | ||
| clicks++ | ||
| updateCounter(span, count) | ||
|
|
||
| // Remove the buttons if share is now expired | ||
| if (count === 0) { | ||
| [...downloadButtons].forEach(button => button.remove()) | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing count parameter no?