mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-08-31 21:21:50 +08:00
fix(glass): load cross-origin wallpapers directly (#593)
This commit is contained in:
@@ -351,14 +351,16 @@ describe('glass optics geometry', () => {
|
||||
expect(getGlassOpticalSurfaceTransitionWeights(96, 96)).toEqual({ incoming: 1, outgoing: 0 })
|
||||
})
|
||||
|
||||
it('only uploads browser-readable login wallpapers to WebGL', () => {
|
||||
it('attempts browser-supported wallpaper protocols without allowing mixed content', () => {
|
||||
const documentUrl = 'https://moviepilot.example/login'
|
||||
|
||||
expect(canUseGlassWallpaperTexture('/api/v1/login/wallpaper/0', documentUrl)).toBe(true)
|
||||
expect(canUseGlassWallpaperTexture('https://moviepilot.example/assets/login.jpg', documentUrl)).toBe(true)
|
||||
expect(canUseGlassWallpaperTexture('blob:https://moviepilot.example/texture', documentUrl)).toBe(true)
|
||||
expect(canUseGlassWallpaperTexture('data:image/png;base64,AA==', documentUrl)).toBe(true)
|
||||
expect(canUseGlassWallpaperTexture('https://image.tmdb.org/t/p/original/poster.jpg', documentUrl)).toBe(false)
|
||||
expect(canUseGlassWallpaperTexture('https://image.tmdb.org/t/p/original/poster.jpg', documentUrl)).toBe(true)
|
||||
expect(canUseGlassWallpaperTexture('http://image.tmdb.org/t/p/original/poster.jpg', documentUrl)).toBe(false)
|
||||
expect(canUseGlassWallpaperTexture('ftp://image.tmdb.org/poster.jpg', documentUrl)).toBe(false)
|
||||
expect(canUseGlassWallpaperTexture('', documentUrl)).toBe(false)
|
||||
})
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
createLoginBackgroundLayers,
|
||||
getLoginGlassOpticalSettings,
|
||||
getLoginVisualProfile,
|
||||
getLoginWallpaperRequestMode,
|
||||
prepareLoginBackgroundLayer,
|
||||
settleLoginBackgroundLayers,
|
||||
} from '@/utils/loginPresentation'
|
||||
@@ -42,12 +41,6 @@ describe('login presentation', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('requests same-origin wallpapers only for glass', () => {
|
||||
expect(getLoginWallpaperRequestMode('glass')).toBe('same-origin')
|
||||
expect(getLoginWallpaperRequestMode('classic')).toBe('default')
|
||||
expect(getLoginWallpaperRequestMode('transparent')).toBe('default')
|
||||
})
|
||||
|
||||
it('keeps two stable wallpaper slots while their transition roles change', () => {
|
||||
const initial = createLoginBackgroundLayers('one.jpg')
|
||||
const prepared = prepareLoginBackgroundLayer(initial, 'two.jpg')
|
||||
|
||||
@@ -492,7 +492,7 @@ export function reconcileGlassOpticalSurfaceSlots<TKey>(
|
||||
return [...stable, ...reserved].slice(0, maxCount)
|
||||
}
|
||||
|
||||
/** 只将同源及本地对象交给 WebGL,避免跨域纹理失败污染登录页控制台。 */
|
||||
/** 过滤浏览器不会作为纹理读取的协议;跨域读取能力由实际纹理加载结果判定。 */
|
||||
export function canUseGlassWallpaperTexture(url: string, documentUrl: string): boolean {
|
||||
if (!url || !documentUrl) return false
|
||||
|
||||
@@ -500,7 +500,11 @@ export function canUseGlassWallpaperTexture(url: string, documentUrl: string): b
|
||||
const source = new URL(url, documentUrl)
|
||||
if (source.protocol === 'blob:' || source.protocol === 'data:') return true
|
||||
|
||||
return source.origin === new URL(documentUrl).origin
|
||||
const document = new URL(documentUrl)
|
||||
if (source.protocol !== 'http:' && source.protocol !== 'https:') return false
|
||||
if (document.protocol === 'https:' && source.protocol === 'http:') return false
|
||||
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { GlassAppearance, GlassOpticalPreset } from '@/utils/glassOptics'
|
||||
|
||||
export type LoginVisualProfile = 'classic' | 'glass' | 'transparent'
|
||||
export type LoginWallpaperRequestMode = 'default' | 'same-origin'
|
||||
|
||||
export interface LoginGlassPreference {
|
||||
/** 用户选择的玻璃材质。 */
|
||||
@@ -53,11 +52,6 @@ export function getLoginGlassOpticalSettings(preference: LoginGlassPreference) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 玻璃主题需要同源纹理,其余主题保留现有外链返回行为。 */
|
||||
export function getLoginWallpaperRequestMode(profile: LoginVisualProfile): LoginWallpaperRequestMode {
|
||||
return profile === 'glass' ? 'same-origin' : 'default'
|
||||
}
|
||||
|
||||
/** 建立两个始终存在的背景槽位,避免角色变化时复用错误的 DOM 合成层。 */
|
||||
export function createLoginBackgroundLayers(activeUrl = ''): LoginBackgroundLayer[] {
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user