整体UI修改
This commit is contained in:
+21
-54
@@ -17,7 +17,7 @@ const renderCode=ts.transpileModule(await readFile(new URL('../src/lib/client/re
|
||||
const renderUrl='data:text/javascript;base64,'+Buffer.from(renderCode.replace("'../routing'",JSON.stringify(routingModuleUrl)).replace('"../api/protocol"',JSON.stringify(protocolUrl))).toString('base64');
|
||||
const searchCode=ts.transpileModule(await readFile(new URL('../src/lib/client/search.ts',import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.ESNext,target:ts.ScriptTarget.ES2022}}).outputText;
|
||||
const search=await import('data:text/javascript;base64,'+Buffer.from(searchCode.replace("'../routing'",JSON.stringify(routingModuleUrl)).replace("'../api/protocol'",JSON.stringify(protocolUrl)).replace("'./render'",JSON.stringify(renderUrl))).toString('base64'));
|
||||
const infoCode=ts.transpileModule(await readFile(new URL('../src/lib/info-pages.ts',import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.ESNext,target:ts.ScriptTarget.ES2022}}).outputText;
|
||||
const infoCode=ts.transpileModule(await readFile(new URL('../src/lib/info-pages.ts',import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.ESNext,target:ts.ScriptTarget.ES2022}}).outputText.replace('"./site"',JSON.stringify('data:text/javascript;base64,'+Buffer.from(ts.transpileModule(await readFile(new URL('../src/lib/site.ts',import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.ESNext,target:ts.ScriptTarget.ES2022}}).outputText).toString('base64')));
|
||||
const infoPages=await import('data:text/javascript;base64,'+Buffer.from(infoCode).toString('base64'));
|
||||
const siteNavigationCode=ts.transpileModule(await readFile(new URL('../src/lib/site-navigation.ts',import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022}}).outputText;
|
||||
const applicationFile=new URL('../src/lib/client/application.ts',import.meta.url);
|
||||
@@ -51,8 +51,6 @@ function fixture(load=async()=>({list:[{id:1}],totalCount:72,name:'接口通用
|
||||
if(specifier==='./config')return {configureSite:async()=>{}};
|
||||
if(specifier==='./hero-swipe')return {bindHeroSwipe(){}};
|
||||
if(specifier==='./promo-marquee')return {bindPromotionMarquee:root=>{calls.push({path:'bindPromotionMarquee',root});return ()=>calls.push({path:'disposePromotionMarquee',root});}};
|
||||
if(specifier==='./account')return {renderMember:async(...args)=>calls.push({path:'renderMember',args}),renderWallet:async(...args)=>calls.push({path:'renderWallet',args})};
|
||||
if(specifier==='./feedback')return {renderFeedbackPage:(...args)=>calls.push({path:'renderFeedbackPage',args})};
|
||||
if(specifier==='./player')return {renderPlayer:async(_app,id,chapterId,isVideo,options)=>{calls.push({path:'renderPlayer',id,chapterId,isVideo,...options});return ()=>{};}};
|
||||
if(specifier==='./render')return {escape:String,empty:message=>`<p>${message}</p>`,loading:()=>'<p>加载中</p>',activeBanners:()=>[],topicCard:()=>'<a href="/topics/1/">专题</a>',renderHome:()=>'<div data-home-loaded>接口首页</div>',card:(item,video,options)=>{cardCalls.push({item,video,options});return '<a href="/detail/1/">剧集</a>';},pagination:(_,page)=>`<span>第 ${page} 页</span>`};
|
||||
return {};
|
||||
@@ -64,7 +62,7 @@ function fixture(load=async()=>({list:[{id:1}],totalCount:72,name:'接口通用
|
||||
}
|
||||
|
||||
test('all native pages bind every square ad row and clean up old loops before rebinding',async()=>{
|
||||
for(const pathname of ['/','/shorts/','/detail/7/','/play/7/8/','/member/favorites/','/info/deposit/']){
|
||||
for(const pathname of ['/','/shorts/','/detail/7/','/play/7/8/','/info/about-us/']){
|
||||
const rows=[{name:'first row'},{name:'second row'}],f=fixture(undefined,{promotionRows:rows});
|
||||
f.location.pathname=pathname;await f.app.route();
|
||||
assert.deepEqual(f.calls.filter(call=>call.path==='bindPromotionMarquee').map(call=>call.root),rows,pathname);
|
||||
@@ -74,38 +72,13 @@ test('all native pages bind every square ad row and clean up old loops before re
|
||||
}
|
||||
});
|
||||
|
||||
test('about uses business Telegram and the feedback group while retaining configured service hours',()=>{
|
||||
const page=infoPages.getInfoPage('about-us',{config:{telegram:'https://t.me/business_team',tgGroup:'https://t.me/feedback_group',gmailAddr:'ignored@example.com',customerServiceHost:'https://ignored.example.com'}},[
|
||||
{name:'商务合作',value:'business@example.com'},{name:'用户反馈',value:'mailto:support@example.com'},
|
||||
{name:'服务时间',value:'周一至周五 09:00–18:00'},{name:'邮箱',value:'ignored@example.com'},
|
||||
]);
|
||||
assert.ok(page.html.includes('商务合作:<a href="https://t.me/business_team"'));
|
||||
assert.ok(page.html.includes('用户反馈:<a href="https://t.me/feedback_group"'));
|
||||
assert.ok(page.html.includes('<p>服务时间:周一至周五 09:00–18:00</p>'));
|
||||
assert.ok(!page.html.includes('mailto:'));assert.ok(!page.html.includes('@example.com'));assert.ok(!page.html.includes('ignored.example.com'));
|
||||
});
|
||||
|
||||
test('Telegram contacts prefer site configuration, fall back to address configuration and hide absent channels',()=>{
|
||||
const html=infoPages.infoContactSection({config:{telegram:'',tgGroup:''},newAddressInfo:{telegram:'@business_team',tgGroup:'https://t.me/feedback_group'}},null);
|
||||
assert.ok(html.includes('商务合作:<a href="https://t.me/business_team"'));assert.ok(html.includes('用户反馈:<a href="https://t.me/feedback_group"'));
|
||||
assert.ok(!html.includes('服务时间'));
|
||||
const preferred=infoPages.infoContactSection({config:{telegram:'https://t.me/primary'},newAddressInfo:{telegram:'https://t.me/fallback'}});
|
||||
assert.ok(preferred.includes('t.me/primary'));assert.ok(!preferred.includes('t.me/fallback'));assert.ok(!preferred.includes('用户反馈'));
|
||||
assert.ok(infoPages.infoContactSection({config:{gmailAddr:'help@example.com',customerServiceHost:'https://ignored.example.com'}}).includes(' hidden'));
|
||||
assert.ok(infoPages.infoContactSection({config:{telegramAdd:'https://t.me/legacy'}}).includes('t.me/legacy'));
|
||||
});
|
||||
|
||||
test('configured contacts escape text and reject executable or malformed addresses',()=>{
|
||||
const html=infoPages.infoContactSection({},[
|
||||
{name:'<img onerror=alert(1)>',value:'<script>alert(1)</script>'},
|
||||
{name:'注入',value:'javascript:alert(1)'},
|
||||
{name:'数据链接',value:'data:text/html,<script>alert(1)</script>'},
|
||||
{name:'正常链接',value:'https://example.com/?a=1&b=2'},null,
|
||||
]);
|
||||
assert.ok(html.includes('<script>'));assert.ok(html.includes('<img onerror=alert(1)>'));
|
||||
assert.ok(!html.includes('<script'));assert.ok(!html.includes('javascript:'));assert.ok(!html.includes('data:text'));
|
||||
assert.ok(html.includes('href="https://example.com/?a=1&b=2" target="_blank" rel="sponsored nofollow noopener noreferrer"'));
|
||||
assert.ok(infoPages.infoContactSection({config:{gmailAddr:'javascript:bad@example.com'}}).includes(' hidden'));
|
||||
test('about and DMCA show only the official TG contact, ignoring configured channels, footer contacts and email',()=>{
|
||||
const about=infoPages.getInfoPage('about-us').html;
|
||||
assert.ok(about.includes('官方TG:<a href="https://t.me/jbd125"'));assert.ok(about.includes('>@jbd125</a>'));
|
||||
for(const text of ['商务合作','用户反馈','服务时间','mailto:','gmail'])assert.ok(!about.includes(text),text);
|
||||
const dmca=infoPages.getInfoPage('dmca').html;
|
||||
assert.ok(dmca.includes('href="https://t.me/jbd125"'));assert.ok(!dmca.includes('mailto:'));assert.ok(!dmca.includes('gmail'));
|
||||
assert.equal(infoPages.infoContactSection(),infoPages.infoContactSection());
|
||||
});
|
||||
|
||||
test('ranking data and native page links derive from the server route and preserve global positions',()=>{
|
||||
@@ -132,19 +105,13 @@ test('initial server channel and search content is retained without page request
|
||||
}
|
||||
});
|
||||
|
||||
test('server player data binds once with its comment route and never refetches the initial content',async()=>{
|
||||
const player={detail:{id:23456,title:'剧集'},chapters:[],chapter:null,comments:{list:[],totalCount:0}};
|
||||
const path='/play/23456/90001/page/2/',f=fixture(()=>assert.fail('no page fetch'),{page:{path:path+'?commentSort=1',panel:'player',title:'剧集',player}});
|
||||
f.location.pathname=path;f.location.search='?commentSort=1';await f.app.route();
|
||||
assert.equal(f.calls.length,1);assert.equal(f.calls[0].path,'renderPlayer');assert.equal(f.calls[0].initial,player);assert.equal(f.calls[0].preserveMarkup,true);assert.equal(f.calls[0].page,2);assert.equal(f.calls[0].commentSort,1);
|
||||
assert.equal(f.calls[0].pageHref(3,1),'/play/23456/90001/page/3/?commentSort=1');await f.app.route();assert.equal(f.calls.length,1);assert.equal(f.reloads.length,1);
|
||||
});
|
||||
|
||||
test('private and feedback pages only bind interactions to their prepared snapshots',async()=>{
|
||||
for(const [path,info,handler] of [['/member/settings/',{key:'settings',member:{user:{userId:7}}},'renderMember'],['/info/deposit/',{key:'deposit',wallet:{user:{userId:7},packages:{coinList:[]},transactions:{list:[]}}},'renderWallet'],['/info/feedback/',{key:'feedback',feedback:true},'renderFeedbackPage']]){
|
||||
const f=fixture(()=>assert.fail('no page fetch'),{page:{path,panel:'info',title:'完整页面',info}});f.location.pathname=path;await f.app.route();
|
||||
assert.equal(f.calls.length,1);assert.equal(f.calls[0].path,handler);assert.equal(f.calls[0].args.at(-1),true);
|
||||
}
|
||||
test('server player data binds once and never refetches the initial content',async()=>{
|
||||
const player={detail:{id:23456,title:'剧集'},chapters:[],chapter:null};
|
||||
const path='/play/23456/90001/',f=fixture(()=>assert.fail('no page fetch'),{page:{path,panel:'player',title:'剧集',player}});
|
||||
f.location.pathname=path;await f.app.route();
|
||||
assert.equal(f.calls.length,1);assert.equal(f.calls[0].path,'renderPlayer');assert.equal(f.calls[0].initial,player);assert.equal(f.calls[0].preserveMarkup,true);
|
||||
assert.equal(f.calls[0].page,undefined);assert.equal(f.calls[0].commentSort,undefined);
|
||||
await f.app.route();assert.equal(f.calls.length,1);assert.equal(f.reloads.length,1);
|
||||
});
|
||||
|
||||
test('missing or mismatched snapshots leave server error HTML visible without a client retry',async()=>{
|
||||
@@ -153,21 +120,21 @@ test('missing or mismatched snapshots leave server error HTML visible without a
|
||||
});
|
||||
|
||||
test('client configuration preserves the server content metadata and canonical',async()=>{
|
||||
const path='/topics/7/',environment=seo.resolveSeoEnvironment({config:{foreverUrlAddr:'https://canonical.drama.test'}}),content={title:'服务端专题',description:'服务端简介',totalCount:72,pageSize:24};
|
||||
const path='/topics/7/',environment=seo.resolveSeoEnvironment({config:{foreverUrlAddr:'https://huangguocg.com'}}),content={title:'服务端专题',description:'服务端简介',totalCount:72,pageSize:24};
|
||||
const f=fixture(()=>assert.fail('no page fetch'),{page:{path,panel:'channel',title:'服务端专题'},seo:{environment,content,path}});f.location.pathname=path;await f.app.route();
|
||||
await f.app.applyConfig({config:{foreverUrlAddr:'https://other.drama.test'}});
|
||||
assert.equal(f.document.title,'服务端专题 - 91短剧');assert.equal(f.document.value('link[rel="canonical"]'),'https://canonical.drama.test/topics/7/');
|
||||
assert.equal(f.document.title,'服务端专题 - 黄果吃瓜');assert.equal(f.document.value('link[rel="canonical"]'),'https://huangguocg.com/topics/7/');
|
||||
});
|
||||
|
||||
test('shared server configuration initializes downloads and contacts without refetching page configuration or footer',async()=>{
|
||||
const shared={config:{config:{officialAppAddr:'https://app.test/download'}},footer:{footerInfo:{contactList:[{name:'服务时间',value:'每天'}]}},trackerConfigured:false};
|
||||
const shared={config:{config:{officialAppAddr:'https://app.test/download'}},footer:{footerInfo:{contactList:[{name:'服务时间',value:'每天'}]}}};
|
||||
const f=fixture(()=>assert.fail('public settings already arrived in HTML'),{shared});
|
||||
await f.app.initializeShared();assert.equal(f.app.config.config.officialAppAddr,'https://app.test/download');assert.equal(f.calls.length,0);
|
||||
});
|
||||
|
||||
test('public back/forward documents keep working without reload; interactive private pages revalidate as fresh documents',async()=>{
|
||||
test('public back/forward documents keep working without reload; interactive player pages revalidate as fresh documents',async()=>{
|
||||
const f=fixture();f.location.pathname='/shorts/';f.app.hidePage(true);assert.equal(f.app.signal.aborted,false);
|
||||
f.app.restorePage();assert.equal(f.reloads.length,0);assert.deepEqual(f.calls.map(item=>item.path),['restore-session']);
|
||||
const privatePage=fixture();privatePage.location.pathname='/info/deposit/';privatePage.app.hidePage(true);assert.equal(privatePage.app.signal.aborted,true);
|
||||
const privatePage=fixture();privatePage.location.pathname='/play/7/8/';privatePage.app.hidePage(true);assert.equal(privatePage.app.signal.aborted,true);
|
||||
privatePage.app.restorePage();assert.equal(privatePage.reloads.length,1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user