fix(portal): preserve readable download filenames
This commit is contained in:
1 parent
596246f20a
commit
89cdb00765
5 files changed
+76
-45
No files matched your search
@@ -25,7 +25,7 @@ export function safePortalContent(html: string): DocumentFragment {
|
||||
if (url.origin !== location.origin && url.protocol === 'https:') element.setAttribute('target', '_blank');
|
||||
const presentation = portalLinkPresentation([...source.classList], source.style.backgroundColor, url.protocol, source.textContent ?? '');
|
||||
if (presentation) element.className = presentation;
|
||||
const resource = protectedPortalResource(url.href, location.origin);
|
||||
const resource = protectedPortalResource(url.href, location.origin, source.textContent ?? '');
|
||||
if (resource) element.dataset.portalResourceRole = resource.role;
|
||||
}
|
||||
} catch { /* Invalid destination remains visible text without navigation. */ }
|
||||
@@ -126,14 +126,16 @@ function initialize() {
|
||||
const link = document.createElement('a');
|
||||
link.href = objectUrl; link.download = filename; link.hidden = true;
|
||||
document.body.append(link); link.click(); link.remove();
|
||||
setTimeout(() => URL.revokeObjectURL(objectUrl), 0);
|
||||
// Both supported browsers have ample time to hand the Blob to their
|
||||
// download manager before its temporary URL is released.
|
||||
setTimeout(() => URL.revokeObjectURL(objectUrl), 60_000);
|
||||
};
|
||||
content.addEventListener('click', (event) => {
|
||||
const target = event.target instanceof Element ? event.target.closest<HTMLAnchorElement>('a[data-portal-resource-role]') : null;
|
||||
if (!target) return;
|
||||
event.preventDefault();
|
||||
if (downloading) return;
|
||||
const resource = protectedPortalResource(target.href, location.origin);
|
||||
const resource = protectedPortalResource(target.href, location.origin, target.textContent ?? '');
|
||||
if (!resource || !credential) {
|
||||
downloadFeedback.textContent = portalDownloadErrorMessage(undefined);
|
||||
downloadFeedback.hidden = false;
|
||||
|
||||
Reference in new issue
Block a user