mirror of
https://github.com/truewhile/MeBox.git
synced 2026-11-16 20:54:23 +08:00
优化
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { isRenderableCover } from './coverUrl.ts'
|
||||
import { isRenderableCover, needsCoverProxy } from './coverUrl.ts'
|
||||
|
||||
function check(name: string, condition: boolean) {
|
||||
if (!condition) throw new Error(`coverUrl: ${name}`)
|
||||
@@ -27,4 +27,16 @@ check('source name is not renderable', !isRenderableCover('光遇聚合'))
|
||||
check('bare relative path is not renderable', !isRenderableCover('files/a.jpg'))
|
||||
check('javascript url is not renderable', !isRenderableCover('javascript:alert(1)'))
|
||||
|
||||
// needsCoverProxy:只有明文 http 的远端封面需要绕后端代理,否则 https 部署下
|
||||
// 会被混合内容策略拦掉(书源图床酷我等没有 https,浏览器升级请求必然失败)。
|
||||
check('http cover needs proxy', needsCoverProxy('http://img4.sycdn.kuwo.cn/star/albumcover/240/a.jpg'))
|
||||
check('uppercase http cover needs proxy', needsCoverProxy('HTTP://img4.sycdn.kuwo.cn/a.jpg'))
|
||||
check('padded http cover needs proxy', needsCoverProxy(' http://img4.sycdn.kuwo.cn/a.jpg '))
|
||||
check('https cover needs no proxy', !needsCoverProxy('https://imagev2.xmcdn.com/a.jpg'))
|
||||
check('protocol relative cover needs no proxy', !needsCoverProxy('//img.example.com/a.jpg'))
|
||||
check('local asset path needs no proxy', !needsCoverProxy('/api/reader/local/asset?b=1&p=2&s=3'))
|
||||
check('data uri needs no proxy', !needsCoverProxy('data:image/png;base64,iVBORw0KGgo='))
|
||||
check('empty needs no proxy', !needsCoverProxy(''))
|
||||
check('name that merely contains http needs no proxy', !needsCoverProxy('http 书籍'))
|
||||
|
||||
console.log('coverUrl.test.ts ok')
|
||||
|
||||
Reference in New Issue
Block a user