feat(DeviceDetailOverlay): add URL validation and cache clearing for external URLs
This commit is contained in:
parent
8cea8a40d0
commit
4fe530352d
|
|
@ -148,6 +148,17 @@ export default function DeviceDetailOverlay({
|
||||||
updateDeviceSetting([...path, 'url'], file);
|
updateDeviceSetting([...path, 'url'], file);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isOutsideBase = (url: string, baseUrl: string): boolean => {
|
||||||
|
if (!baseUrl || !url.startsWith('/')) return false;
|
||||||
|
const normalizedBase = baseUrl.endsWith('/') ? baseUrl : baseUrl + '/';
|
||||||
|
return url !== baseUrl && !url.startsWith(normalizedBase);
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearBaseAndCache = (dev: any) => {
|
||||||
|
if ('base_url' in dev) dev.base_url = '';
|
||||||
|
if ('cache' in dev) dev.cache = '';
|
||||||
|
};
|
||||||
|
|
||||||
const handleFileSelect = async (selectedPath: string) => {
|
const handleFileSelect = async (selectedPath: string) => {
|
||||||
const devicePath = getDevicePath();
|
const devicePath = getDevicePath();
|
||||||
if (selectedPath.toLowerCase().endsWith('.lst')) {
|
if (selectedPath.toLowerCase().endsWith('.lst')) {
|
||||||
|
|
@ -168,6 +179,7 @@ export default function DeviceDetailOverlay({
|
||||||
const newConfig = JSON.parse(JSON.stringify(config));
|
const newConfig = JSON.parse(JSON.stringify(config));
|
||||||
let dev = newConfig;
|
let dev = newConfig;
|
||||||
for (const k of devicePath) dev = dev[k];
|
for (const k of devicePath) dev = dev[k];
|
||||||
|
if (isOutsideBase(files[0], dev.base_url || '')) clearBaseAndCache(dev);
|
||||||
dev.url = files[0];
|
dev.url = files[0];
|
||||||
dev.media_set = files;
|
dev.media_set = files;
|
||||||
setConfig(newConfig);
|
setConfig(newConfig);
|
||||||
|
|
@ -178,6 +190,7 @@ export default function DeviceDetailOverlay({
|
||||||
const newConfig = JSON.parse(JSON.stringify(config));
|
const newConfig = JSON.parse(JSON.stringify(config));
|
||||||
let dev = newConfig;
|
let dev = newConfig;
|
||||||
for (const k of devicePath) dev = dev[k];
|
for (const k of devicePath) dev = dev[k];
|
||||||
|
if (isOutsideBase(selectedPath, dev.base_url || '')) clearBaseAndCache(dev);
|
||||||
dev.url = selectedPath;
|
dev.url = selectedPath;
|
||||||
delete dev.media_set;
|
delete dev.media_set;
|
||||||
setConfig(newConfig);
|
setConfig(newConfig);
|
||||||
|
|
@ -342,8 +355,14 @@ export default function DeviceDetailOverlay({
|
||||||
type="text"
|
type="text"
|
||||||
value={deviceData.url}
|
value={deviceData.url}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const path = getDevicePath();
|
const newUrl = e.target.value;
|
||||||
updateDeviceSetting([...path, 'url'], e.target.value);
|
const devicePath = getDevicePath();
|
||||||
|
const newConfig = JSON.parse(JSON.stringify(config));
|
||||||
|
let dev = newConfig;
|
||||||
|
for (const k of devicePath) dev = dev[k];
|
||||||
|
if (isOutsideBase(newUrl, dev.base_url || '')) clearBaseAndCache(dev);
|
||||||
|
dev.url = newUrl;
|
||||||
|
setConfig(newConfig);
|
||||||
}}
|
}}
|
||||||
className="flex-1 px-3 py-2 border border-neutral-300 rounded-lg"
|
className="flex-1 px-3 py-2 border border-neutral-300 rounded-lg"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user