mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-07-09 13:37:37 +08:00
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:
@@ -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>
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user