Files
IM-web-new/src/services/mediaProxy.js
T

31 lines
930 B
JavaScript
Raw Normal View History

2026-10-10 15:34:06 +07:00
function configuredProxyHosts() {
const configured = window.JC_WEB_IM_CONFIG?.mediaProxyHosts;
const values = Array.isArray(configured)
? configured
: String(configured || '').split(/[\s,]+/);
return new Set(
values
.map(value => String(value || '').trim().toLowerCase().replace(/\.$/, ''))
.filter(Boolean)
);
}
export function imageDisplayUrl(value) {
const source = String(value || '').trim();
if (!source || source.startsWith('blob:') || source.startsWith('data:')) {
return source;
}
try {
const url = new URL(source, window.location.origin);
if (url.protocol !== 'https:' || !configuredProxyHosts().has(url.hostname.toLowerCase())) {
return source;
}
const proxyUrl = new URL('/api/media_proxy.php', window.location.origin);
proxyUrl.searchParams.set('url', url.toString());
return proxyUrl.toString();
} catch (error) {
return source;
}
}