MCPcopy Create free account
hub / github.com/error311/FileRise / updateHeaderLogoFromAdmin

Function updateHeaderLogoFromAdmin

public/js/adminPanel.js:544–596  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

542}
543
544function updateHeaderLogoFromAdmin() {
545 try {
546 const input = document.getElementById('brandingCustomLogoUrl');
547 const logoImg = document.querySelector('.header-logo img');
548 if (!logoImg) return;
549
550 const sanitizeLogoUrl = (raw) => {
551 let url = (raw || '').trim();
552 if (!url) return '';
553
554 // If they used a bare "uploads/..." path, normalize to "/uploads/..."
555 if (!url.startsWith('/') && url.startsWith('uploads/')) {
556 url = '/' + url;
557 }
558
559 const legacyMatch = url.match(/\/uploads\/profile_pics\/([^?#]+)/);
560 if (legacyMatch && legacyMatch[1]) {
561 let legacyName = legacyMatch[1];
562 try { legacyName = decodeURIComponent(legacyName); } catch (e) {}
563 url = `/api/public/profilePic.php?file=${encodeURIComponent(legacyName)}`;
564 }
565
566 // Strip any CR/LF just in case
567 url = url.replace(/[\r\n]+/g, '');
568
569 if (url.startsWith('/')) {
570 if (url.includes('://')) return '';
571 return withBase(url);
572 }
573
574 try {
575 const parsed = new URL(url);
576 if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return '';
577 return parsed.toString();
578 } catch (e) {
579 return '';
580 }
581 };
582
583 const safeUrl = sanitizeLogoUrl((input && input.value) || '');
584
585 if (safeUrl) {
586 logoImg.setAttribute('src', safeUrl);
587 logoImg.setAttribute('alt', 'Site logo');
588 } else {
589 // fall back to default FileRise logo
590 logoImg.setAttribute('src', withBase('/assets/logo.svg?v={{APP_QVER}}'));
591 logoImg.setAttribute('alt', 'FileRise');
592 }
593 } catch (e) {
594 console.warn('Failed to live-update header logo from admin panel', e);
595 }
596}
597
598/* === BEGIN: Folder Access helpers (merged + improved) === */
599function qs(scope, sel) { return (scope || document).querySelector(sel); }

Callers 1

handleSaveFunction · 0.85

Calls 2

sanitizeLogoUrlFunction · 0.85
withBaseFunction · 0.85

Tested by

no test coverage detected