31 lines
930 B
JavaScript
31 lines
930 B
JavaScript
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;
|
||
|
|
}
|
||
|
|
}
|