mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
whep fix
This commit is contained in:
@@ -85,13 +85,17 @@ function normalizeSource(raw) {
|
|||||||
if (!raw) return null;
|
if (!raw) return null;
|
||||||
const trimmed = raw.trim();
|
const trimmed = raw.trim();
|
||||||
if (!trimmed) return null;
|
if (!trimmed) return null;
|
||||||
if (/^wheps?:\/\//i.test(trimmed)) {
|
|
||||||
return trimmed;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const parsed = new URL(trimmed);
|
const parsed = new URL(/^[a-z]+:\/\//i.test(trimmed) ? trimmed : `http://${trimmed}`);
|
||||||
const protocol = parsed.protocol === 'https:' ? 'wheps' : 'whep';
|
const protocol = parsed.protocol === 'https:' ? 'wheps' : 'whep';
|
||||||
return `${protocol}://${parsed.host}${parsed.pathname}${parsed.search || ''}`;
|
let path = parsed.pathname || '/';
|
||||||
|
if (!path.endsWith('/whep')) {
|
||||||
|
if (!path.endsWith('/')) {
|
||||||
|
path += '/';
|
||||||
|
}
|
||||||
|
path += 'whep';
|
||||||
|
}
|
||||||
|
return `${protocol}://${parsed.host}${path}`;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.warn('invalid WHEP URL: %s (%s)', raw, err.message);
|
logger.warn('invalid WHEP URL: %s (%s)', raw, err.message);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user