This commit is contained in:
truewhile
2026-10-02 11:05:59 +08:00
parent 42343212c5
commit 5acfa6292a
35 changed files with 4162 additions and 224 deletions
+13 -1
View File
@@ -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')