Skip to content

Commit

Permalink
Fix attachment clipboard copy on insecure origin (go-gitea#26224)
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Jul 29, 2023
1 parent 2122743 commit b24fb6c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions web_src/js/features/common-global.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import $ from 'jquery';
import 'jquery.are-you-sure';
import {clippie} from 'clippie';
import {createDropzone} from './dropzone.js';
import {initCompColorPicker} from './comp/ColorPicker.js';
import {showGlobalErrorMessage} from '../bootstrap.js';
import {handleGlobalEnterQuickSubmit} from './comp/QuickSubmit.js';
import {svg} from '../svg.js';
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
import {htmlEscape} from 'escape-goat';
import {showTemporaryTooltip} from '../modules/tippy.js';

const {appUrl, csrfToken} = window.config;
const {appUrl, csrfToken, i18n} = window.config;

export function initGlobalFormDirtyLeaveConfirm() {
// Warn users that try to leave a page after entering data into a form.
Expand Down Expand Up @@ -146,15 +148,16 @@ export function initGlobalDropzone() {
copyLinkElement.className = 'gt-text-center';
// The a element has a hardcoded cursor: pointer because the default is overridden by .dropzone
copyLinkElement.innerHTML = `<a href="#" style="cursor: pointer;">${svg('octicon-copy', 14, 'copy link')} Copy link</a>`;
copyLinkElement.addEventListener('click', (e) => {
copyLinkElement.addEventListener('click', async (e) => {
e.preventDefault();
let fileMarkdown = `[${file.name}](/attachments/${file.uuid})`;
if (file.type.startsWith('image/')) {
fileMarkdown = `!${fileMarkdown}`;
} else if (file.type.startsWith('video/')) {
fileMarkdown = `<video src="/attachments/${file.uuid}" title="${htmlEscape(file.name)}" controls></video>`;
}
navigator.clipboard.writeText(fileMarkdown);
const success = await clippie(fileMarkdown);
showTemporaryTooltip(e.target, success ? i18n.copy_success : i18n.copy_error);
});
file.previewTemplate.append(copyLinkElement);
});
Expand Down

0 comments on commit b24fb6c

Please sign in to comment.