fix(player): normalize URLs without protocol to prevent relative path redirects

URLs entered without http:// or https:// were being treated as relative
paths by the browser. Added normalizeUrl() function that prepends http://
when no protocol is present.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Estrella Pan
2026-01-26 20:11:40 +01:00
parent 8d09b0cecc
commit 4488a89391
2 changed files with 24 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
<script lang="ts" setup>
const { types, type, url } = storeToRefs(usePlayerStore());
const { types, type, rawUrl } = storeToRefs(usePlayerStore());
</script>
<template>
@@ -13,10 +13,10 @@ const { types, type, url } = storeToRefs(usePlayerStore());
></ab-setting>
<ab-setting
v-model:data="url"
v-model:data="rawUrl"
type="input"
:label="$t('config.media_player_set.url')"
:prop="{ placeholder: 'media player url' }"
:prop="{ placeholder: 'http://192.168.1.100:8096' }"
></ab-setting>
</div>
</ab-fold-panel>

View File

@@ -2,14 +2,34 @@ import { useLocalStorage } from '@vueuse/core';
type MediaPlayerType = 'jump' | 'iframe';
function normalizeUrl(url: string): string {
if (!url) return '';
const trimmed = url.trim();
if (!trimmed) return '';
// If URL already has a protocol, return as-is
if (/^https?:\/\//i.test(trimmed)) {
return trimmed;
}
// Otherwise, prepend http://
return `http://${trimmed}`;
}
export const usePlayerStore = defineStore('player', () => {
const types = ref<MediaPlayerType[]>(['jump', 'iframe']);
const type = useLocalStorage<MediaPlayerType>('media-player-type', 'jump');
const url = useLocalStorage('media-player-url', '');
const rawUrl = useLocalStorage('media-player-url', '');
const url = computed(() => normalizeUrl(rawUrl.value));
function setUrl(value: string) {
rawUrl.value = value;
}
return {
types,
type,
url,
rawUrl,
setUrl,
};
});