This commit is contained in:
谢宇宁
2026-11-06 00:13:27 +07:00
parent f65d10e998
commit 37411fcada
98 changed files with 958 additions and 4598 deletions
+21 -14
View File
@@ -1,3 +1,4 @@
import {linkShared} from './helpers/shared-modules.mjs';
import {routingModuleUrl} from './helpers/routing.mjs';
import {test} from 'node:test';
import assert from 'node:assert/strict';
@@ -7,37 +8,43 @@ import ts from 'typescript';
async function moduleUrl(file,replace=code=>code){
const filename=new URL(file,import.meta.url);
const {outputText}=ts.transpileModule(await readFile(filename,'utf8'),{compilerOptions:{target:ts.ScriptTarget.ES2022,module:ts.ModuleKind.ESNext}});
return 'data:text/javascript;base64,'+Buffer.from(replace(outputText).replace(/(['"])\.\.\/routing\1/g,JSON.stringify(routingModuleUrl))+'\n//# sourceURL='+filename.pathname).toString('base64');
return 'data:text/javascript;base64,'+Buffer.from(linkShared(replace(outputText)).replace(/(['"])\.\.\/routing\1/g,JSON.stringify(routingModuleUrl))+'\n//# sourceURL='+filename.pathname).toString('base64');
}
const protocolUrl=await moduleUrl('../src/lib/api/protocol.ts');
const renderUrl=await moduleUrl('../src/lib/client/render.ts',code=>code.replace('"../api/protocol"',JSON.stringify(protocolUrl)));
const detailUrl=await moduleUrl('../src/lib/client/detail.ts',code=>code.replace('"../api/protocol"',JSON.stringify(protocolUrl)).replace('"./render"',JSON.stringify(renderUrl)));
const {overviewMarkup,officialLinks,bindSeriesDescription,detailActionIcon}=await import(detailUrl);
test('overview retains API data, encrypted image loading and real chapter links in the original layout',()=>{
const html=overviewMarkup({id:23456,title:'剧名 <script>',coverImg:'https://cdn.example/encrypted.webp',description:'真实简介 <img onerror=alert(1)>',themeNames:['古装','爱情'],isNew:true,countCollect:23000,countLike:100,heatValue:999},{id:90042,currentEpisode:1},'<div class="play-detail-actions">actions</div>');
test('cinematic overview keeps API data, encrypted image loading and real chapter links',()=>{
const html=overviewMarkup({id:23456,title:'剧名 <script>',coverImg:'https://cdn.example/encrypted.webp',description:'真实简介 <img onerror=alert(1)>',themeNames:['古装','爱情'],totalEpisode:12,updateStatus:1,isNew:true,countCollect:23000,countLike:100,heatValue:999},{id:90042,currentEpisode:1});
assert.ok(html.includes('剧名 &lt;script&gt;'));assert.ok(!html.includes('<script>'));
assert.ok(html.includes('真实简介 &lt;img onerror=alert(1)&gt;'));assert.ok(html.includes('古装 · 爱情'));
assert.ok(html.includes('真实简介 &lt;img onerror=alert(1)&gt;'));assert.ok(html.includes('#古装'));assert.ok(html.includes('#爱情'));
assert.ok(html.includes('class="cine-hero"'));assert.ok(html.includes('class="cine-hero-image"'));assert.ok(!html.includes('series-poster'));
assert.ok(html.includes('data-src="https://cdn.example/encrypted.webp"'));assert.ok(!/\ssrc="https:\/\/cdn\.example/.test(html));
assert.ok(html.includes('href="/play/23456/90042/"'));assert.ok(html.includes('series-badge--new'));
assert.ok(html.includes('<div class="series-action-bar"><div class="series-actions">'));
assert.ok(html.includes('<span class="cine-kicker">短剧 · 连载中</span>'));assert.ok(html.includes('<h1 id="play-detail-title">'));
assert.ok(html.includes('href="/play/23456/90042/"'));assert.ok(html.includes('<span>立即观看</span>'));
for(const text of ['999热度','2.3万收藏','100点赞','data-engage="like"','data-engage="collect"','data-share'])assert.ok(html.includes(text),text);
assert.ok(html.includes('aria-controls="series-description-text"'));assert.ok(html.includes('data-app-download-entry'));
assert.ok(!overviewMarkup({id:7,title:'无章节'},undefined,'').includes('href="/play/'));
const rich=overviewMarkup({id:8,title:'完结剧',totalEpisode:10,updateStatus:2,countBrowse:167,anchor:'演员 <b>',showOriginal:true,operateType:2,tagNames:['家庭'],tagSlugs:['jiating'],themeNames:['家庭']},{id:1},'');
for(const text of ['全10集','已完结','167次观看','演员 演员 &lt;b&gt;','series-badge--original','series-badge--comic','href="/tag/jiating/"'])assert.ok(rich.includes(text),text);
assert.equal(rich.split('家庭').length-1,1);
assert.ok(!overviewMarkup({id:7,title:'无章节'},undefined).includes('href="/play/'));
const later=overviewMarkup({id:9,title:'从中间开始',totalEpisode:30},{id:5,currentEpisode:3});
assert.ok(later.includes('从第 3 集开始'));
const single=overviewMarkup({id:8,title:'单集',totalEpisode:1,tagNames:['家庭'],tagSlugs:['jiating'],themeNames:['家庭']},{id:1});
assert.ok(single.includes('<span class="cine-kicker">视频</span>'));assert.ok(!single.includes('全1集'));
assert.ok(single.includes('href="/tag/jiating/"'));assert.equal(single.split('#家庭').length-1,1);
});
test('official links use configured safe URLs and retain the original feedback entrance',()=>{
test('official links use configured safe URLs without a customer-service entrance',()=>{
const html=officialLinks({config:{newUrlAddr:'https://entry.example',foreverUrlAddr:'https://permanent.example',tgGroup:'https://t.me/example',telegram:'https://contact.example'}});
for(const url of ['https://entry.example/','https://permanent.example/','https://t.me/example','https://contact.example/'])assert.ok(html.includes(`href="${url}"`));
for(const url of ['https://entry.example/','https://permanent.example/','https://t.me/example'])assert.ok(html.includes(`href="${url}"`));
assert.ok(html.includes('点击加入黄果短剧官方 Telegram 群'));
for(const text of ['官方客服','https://contact.example','/info/feedback/'])assert.ok(!html.includes(text),text);
const fallback=officialLinks({config:{newUrlAddr:'javascript:alert(1)',tgGroup:'javascript:alert(1)'},navPageList:[{line:1,url:'https://backup.example'}]});
assert.ok(fallback.includes('href="https://backup.example/"'));assert.ok(fallback.includes('href="/info/feedback/"'));assert.ok(!fallback.includes('javascript:'));
assert.ok(fallback.includes('href="https://backup.example/"'));assert.ok(!fallback.includes('javascript:'));
assert.ok(!fallback.includes('huangguo.me'));assert.ok(!fallback.includes('huangguo.tv'));
});
test('original action SVGs remain accessible and inherit the active colors',()=>{
for(const kind of ['like','save','share','feedback']){
for(const kind of ['like','save','share']){
const html=detailActionIcon(kind);assert.match(html,/<svg class="play-action-icon"/);assert.match(html,/aria-hidden="true"/);assert.ok(html.includes('<path d="'));
}
});