marketing-touch-fault-bundle.ts 1.1 KB

12345678910111213141516171819202122232425262728
  1. import yazl from "yazl";
  2. /** 独立真实 ZIP 用于握手故障,不给产品增加测试专用入口。 */
  3. export async function createMarketingTouchZip(html: Buffer) {
  4. const archive = new yazl.ZipFile();
  5. archive.addBuffer(html, "index.html");
  6. archive.end();
  7. const chunks: Buffer[] = [];
  8. for await (const chunk of archive.outputStream) chunks.push(Buffer.from(chunk));
  9. return Buffer.concat(chunks);
  10. }
  11. export async function createMarketingTouchFaultBundle() {
  12. return createMarketingTouchZip(
  13. Buffer.from(`<!doctype html><script>
  14. addEventListener('message', ({data}) => {
  15. if (data?.channel !== 'zcode-cloud-hero-v1' || data.type !== 'init') return;
  16. if (data.data?.mode === 'wrong-instance') {
  17. parent.postMessage({channel: data.channel, instanceId: data.instanceId + '-other', type: 'ready'}, '*');
  18. document.documentElement.dataset.sent = 'wrong-instance';
  19. }
  20. if (data.data?.mode === 'error') parent.postMessage({
  21. channel: data.channel, instanceId: data.instanceId, type: 'error', code: 'e2e_error'
  22. }, '*');
  23. });
  24. </script>`),
  25. );
  26. }