aboutsummaryrefslogtreecommitdiffstats
path: root/docker-compose.override.yml
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2021-04-23 00:44:23 -0400
committerAdam Soltys <[email protected]>2021-04-27 18:07:15 -0400
commit20273701d1cf75ef7540ba2e7b90554c0b17c41c (patch)
tree3543e736c52a6d39253c5f3e1266abe565477e0e /docker-compose.override.yml
parent2621fec1c189b6de5e3bd2b86b391443ccd7a8a7 (diff)
downloadcoinos-server-20273701d1cf75ef7540ba2e7b90554c0b17c41c.tar.gz
coinos-server-20273701d1cf75ef7540ba2e7b90554c0b17c41c.zip
change cors setting
Diffstat (limited to 'docker-compose.override.yml')
0 files changed, 0 insertions, 0 deletions
t .ch { color: #888 } /* Comment.Hashbang */ .highlight .cm { color: #888 } /* Comment.Multiline */ .highlight .cp { color: #C00; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888 } /* Comment.Single */ .highlight .cs { color: #C00; font-weight: bold; background-color: #FFF0F0 } /* Comment.Special */ .highlight .gd { color: #000; background-color: #FDD } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #A00 } /* Generic.Error */ .highlight .gh { color: #333 } /* Generic.Heading */ .highlight .gi { color: #000; background-color: #DFD } /* Generic.Inserted */ .highlight .go { color: #888 } /* Generic.Output */ .highlight .gp { color: #555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666 } /* Generic.Subheading */ .highlight .gt { color: #A00 } /* Generic.Traceback */ .highlight .kc { color: #080; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #080; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #080; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #080 } /* Keyword.Pseudo */ .highlight .kr { color: #080; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #00D; font-weight: bold } /* Literal.Number */ .highlight .s { color: #D20; background-color: #FFF0F0 } /* Literal.String */ .highlight .na { color: #369 } /* Name.Attribute */ .highlight .nb { color: #038 } /* Name.Builtin */ .highlight .nc { color: #B06; font-weight: bold } /* Name.Class */ .highlight .no { color: #036; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555 } /* Name.Decorator */ .highlight .ne { color: #B06; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #06B; font-weight: bold } /* Name.Function */ .highlight .nl { color: #369; font-style: italic } /* Name.Label */ .highlight .nn { color: #B06; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #369; font-weight: bold } /* Name.Property */ .highlight .nt { color: #B06; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #369 } /* Name.Variable */ .highlight .ow { color: #080 } /* Operator.Word */ .highlight .w { color: #BBB } /* Text.Whitespace */ .highlight .mb { color: #00D; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #00D; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #00D; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #00D; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #00D; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #D20; background-color: #FFF0F0 } /* Literal.String.Affix */ .highlight .sb { color: #D20; background-color: #FFF0F0 } /* Literal.String.Backtick */ .highlight .sc { color: #D20; background-color: #FFF0F0 } /* Literal.String.Char */ .highlight .dl { color: #D20; background-color: #FFF0F0 } /* Literal.String.Delimiter */ .highlight .sd { color: #D20; background-color: #FFF0F0 } /* Literal.String.Doc */ .highlight .s2 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Double */ .highlight .se { color: #04D; background-color: #FFF0F0 } /* Literal.String.Escape */ .highlight .sh { color: #D20; background-color: #FFF0F0 } /* Literal.String.Heredoc */ .highlight .si { color: #33B; background-color: #FFF0F0 } /* Literal.String.Interpol */ .highlight .sx { color: #2B2; background-color: #F0FFF0 } /* Literal.String.Other */ .highlight .sr { color: #080; background-color: #FFF0FF } /* Literal.String.Regex */ .highlight .s1 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Single */ .highlight .ss { color: #A60; background-color: #FFF0F0 } /* Literal.String.Symbol */ .highlight .bp { color: #038 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #369 } /* Name.Variable.Class */ .highlight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
// A post is written as plain text but doesn't arrive as plain text: a .jpg
// URL becomes a picture, a youtu.be link becomes a player, a nostr: ref
// becomes the note it points at. Until now the only way to find out how
// yours would land was to post it.
//
// The preview runs the draft through noteBody — the renderer the feed uses —
// so it isn't a lookalike, it's the same thing. This checks that what the
// preview shows is what a real post shows, for the same text.
//
// Run: bun tools/compose-preview-test.js
import puppeteer from 'puppeteer-core';
import { generateMnemonic } from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
import { cacheKeyFor } from '../src/wallet.js';
import { buildHtml } from '../build.js';
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
let ok = true;
const check = (n, c, d = '') => { console.log(` ${c ? '✓' : '✗'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; };

const html = await buildHtml({ minify: true, pwa: false });
const server = Bun.serve({ port: 5294, fetch: () => new Response(html, { headers: { 'content-type': 'text/html' } }) });
const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] });
const page = await browser.newPage();
const errs = [];
page.on('pageerror', (e) => errs.push(String(e)));
const click = (t) => page.evaluate((x) => { const e = [...document.querySelectorAll('button')].find((n) => n.textContent.trim().toLowerCase().includes(x)); if (e) { e.click(); return true; } return false; }, t);
const waitText = async (x, ms = 25000) => { for (let i = 0; i < ms / 250; i++) { if ((await page.evaluate(() => document.body.innerText)).toLowerCase().includes(x)) return true; await sleep(250); } return false; };
const type = (sel, v) => page.evaluate((s, val) => {
  const e = document.querySelector(s);
  if (!e) return false;
  e.focus(); e.value = val;
  e.dispatchEvent(new Event('input', { bubbles: true }));
  return true;
}, sel, v);

const DRAFT = 'look at this https://coinos.io/punks/7.webp and this https://youtu.be/dQw4w9WgXcQ';

try {
  await page.setViewport({ width: 390, height: 844 });
  await page.goto('http://localhost:5294/', { waitUntil: 'domcontentloaded' });
  await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'regtest'));
  await page.reload({ waitUntil: 'domcontentloaded' });
  await sleep(400);
  await click('create a new wallet'); await sleep(500);
  await click('to import'); await sleep(400);
  await page.waitForSelector('textarea');
  const mn = generateMnemonic(wordlist);
  await page.type('textarea', mn);
  await click('open wallet');
  await waitText('receive', 20000);
  // a post in the feed, so there is something to reply to
  const base = cacheKeyFor(mn + '\n');
  await page.evaluate(([k, n]) => {
    localStorage.setItem(k + ':follows', JSON.stringify({ tags: [['p', n.pubkey]], c: '', at: Math.floor(Date.now() / 1000) }));
    localStorage.setItem(k + ':feedNotes', JSON.stringify([n]));
  }, [base, {
    id: 'f'.repeat(63) + '1', pubkey: '3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d',
    kind: 1, created_at: Math.floor(Date.now() / 1000) - 60, content: 'a post to answer', tags: [],
  }]);
  await page.reload({ waitUntil: 'domcontentloaded' });
  await waitText('receive', 20000);

  // into the feed, where posts are written
  await page.evaluate(() => { const b = [...document.querySelectorAll('button')].find((e) => /message/i.test(e.getAttribute('aria-label') || '')); if (b) b.click(); });
  await sleep(1000);
  await page.evaluate(() => { const e = [...document.querySelectorAll('.item')].find((n) => /feed/i.test(n.textContent)); if (e) e.click(); });
  await sleep(2500);
  const opened = await click('new post');
  check('the composer opens', opened && !!(await page.$('textarea')));

  await type('textarea', DRAFT);
  await sleep(400);
  check('no preview until it is asked for', !(await page.$('.draft-preview')));

  await page.evaluate(() => [...document.querySelectorAll('button')]
    .find((b) => /preview/i.test(b.getAttribute('aria-label') || ''))?.click());
  await sleep(2500);
  const shown = await page.evaluate(() => {
    const p = document.querySelector('.draft-preview');
    if (!p) return null;
    return {
      imgs: [...p.querySelectorAll('img')].map((i) => i.getAttribute('src') || i.src).filter(Boolean),
      yt: !!p.querySelector('.yt-embed'),
      text: p.innerText,
    };
  });
  check('the preview appears', !!shown);
  check('...with the picture rendered, not its URL', !!shown && shown.imgs.some((u) => /punks\/7\.webp/.test(u)),
    shown ? shown.imgs.length + ' image(s)' : '');
  check('...and the YouTube link as a player', !!shown && shown.yt);
  check('...and the raw URLs are not left lying in the text', !!shown && !shown.text.includes('https://youtu.be/'),
    shown ? JSON.stringify(shown.text.slice(0, 60)) : '');

  // live: keep typing and the preview follows
  await type('textarea', DRAFT + ' plus a word');
  await sleep(900);
  check('it follows the draft as you type',
    /plus a word/.test(await page.evaluate(() => (document.querySelector('.draft-preview') || {}).innerText || '')));

  // and it puts itself away
  await page.evaluate(() => [...document.querySelectorAll('button')]
    .find((b) => /hide preview/i.test(b.getAttribute('aria-label') || ''))?.click());
  await sleep(500);
  check('and it closes again', !(await page.$('.draft-preview')));

  // ---- and the same thing on a reply -------------------------------------
  await click('cancel');
  await sleep(400);
  // open a thread: any post in the feed does
  const intoThread = await page.evaluate(() => {
    const r = document.querySelector('.notes-feed > .row');
    if (!r) return false;
    r.click();
    return true;
  });
  if (!intoThread) {
    console.log(' — no post in the feed to reply to, skipping the reply half');
  } else {
    await sleep(2500);
    const box = await page.$('.thread-reply-input');
    check('a thread has a reply box', !!box);
    if (box) {
      await type('.thread-reply-input', 'my answer https://coinos.io/punks/3.webp');
      await sleep(300);
      check('a reply has no preview until asked either', !(await page.$('.draft-preview')));
      await page.evaluate(() => [...document.querySelectorAll('button')]
        .find((b) => /^preview$/i.test(b.getAttribute('aria-label') || ''))?.click());
      await sleep(1500);
      const rp = await page.evaluate(() => {
        const p = document.querySelector('.draft-preview');
        return p ? { imgs: p.querySelectorAll('img').length, text: p.innerText } : null;
      });
      check('the reply previews the same way', !!rp && rp.imgs > 0,
        rp ? rp.imgs + ' image(s)' : 'no preview');
      check('...showing the picture instead of its URL', !!rp && !rp.text.includes('punks/3.webp'),
        rp ? JSON.stringify(rp.text.slice(0, 50)) : '');
    }
  }

  check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | '));
} finally { await browser.close(); server.stop(true); }
console.log(ok ? '\n✅ what you see is what they get' : '\n❌ failed');
process.exit(ok ? 0 : 1);