From 873f30617d21da1b96add06d0a0afba225d49860 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 1 Jun 2020 13:59:33 +0200 Subject: [PATCH] Multiple dnslink endpoints (#2867) * Multiple dnslink endpoints * Update scripts/ipfsUpload.js --- packages/apps-config/.skip-build | 0 .../apps-config/src/settings/endpoints.ts | 22 ++++++++++---- scripts/ipfsUpload.js | 29 +++++++++++++++---- 3 files changed, 41 insertions(+), 10 deletions(-) delete mode 100644 packages/apps-config/.skip-build diff --git a/packages/apps-config/.skip-build b/packages/apps-config/.skip-build deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/apps-config/src/settings/endpoints.ts b/packages/apps-config/src/settings/endpoints.ts index b36634cb3a..b7796c18ed 100644 --- a/packages/apps-config/src/settings/endpoints.ts +++ b/packages/apps-config/src/settings/endpoints.ts @@ -4,7 +4,11 @@ import { Option } from './types'; -function createDev (t: (key: string, text: string, options: { ns: string }) => T): Option[] { +interface LinkOption extends Option { + dnslink?: string; +} + +function createDev (t: (key: string, text: string, options: { ns: string }) => T): LinkOption[] { return [ { info: 'local', @@ -14,39 +18,46 @@ function createDev (t: (key: string, text: string, options: { ns: st ]; } -function createLive (t: (key: string, text: string, options: { ns: string }) => T): Option[] { +function createLive (t: (key: string, text: string, options: { ns: string }) => T): LinkOption[] { return [ { + dnslink: 'polkadot', info: 'polkadot', text: t('rpc.polkadot.parity', 'Polkadot (Live, hosted by Parity)', { ns: 'apps-config' }), value: 'wss://rpc.polkadot.io' }, { + dnslink: 'polkadot', info: 'polkadot', text: t('rpc.polkadot.w3f', 'Polkadot (Live, hosted by Web3 Foundation)', { ns: 'apps-config' }), value: 'wss://cc1-1.polkadot.network' }, { + dnslink: 'kusama', info: 'kusama', text: t('rpc.kusama.parity', 'Kusama (Polkadot Canary, hosted by Parity)', { ns: 'apps-config' }), value: 'wss://kusama-rpc.polkadot.io/' }, { + dnslink: 'kusama', info: 'kusama', text: t('rpc.kusama.w3f', 'Kusama (Polkadot Canary, hosted by Web3 Foundation)', { ns: 'apps-config' }), value: 'wss://cc3-5.kusama.network/' }, { + dnslink: 'kusama', info: 'kusama', text: t('rpc.kusama.ava', 'Kusama (Polkadot Canary, user-run public nodes; see https://status.cloud.ava.do/)', { ns: 'apps-config' }), value: 'wss://kusama.polkadot.cloud.ava.do/' }, { + dnslink: 'edgeware', info: 'edgeware', text: t('rpc.edgeware', 'Edgeware (Edgeware Mainnet, hosted by Commonwealth Labs)', { ns: 'apps-config' }), value: 'wss://mainnet1.edgewa.re' }, { + dnslink: 'kulupu', info: 'substrate', text: t('rpc.kulupu', 'Kulupu (Kulupu Mainnet, hosted by Kulupu)', { ns: 'apps-config' }), value: 'wss://rpc.kulupu.network/ws' @@ -54,9 +65,10 @@ function createLive (t: (key: string, text: string, options: { ns: s ]; } -function createTest (t: (key: string, text: string, options: { ns: string }) => T): Option[] { +function createTest (t: (key: string, text: string, options: { ns: string }) => T): LinkOption[] { return [ { + dnslink: 'westend', info: 'westend', text: t('rpc.westend', 'Westend (Polkadot Testnet, hosted by Parity)', { ns: 'apps-config' }), value: 'wss://westend-rpc.polkadot.io' @@ -84,8 +96,8 @@ function createTest (t: (key: string, text: string, options: { ns: s // info: The chain logo name as defined in ../logos, specifically in namedLogos // text: The text to display on teh dropdown // value: The actual hosted secure websocket endpoint -export default function create (t: (key: string, text: string, options: { ns: string }) => T): Option[] { - const ENV: Option[] = []; +export default function create (t: (key: string, text: string, options: { ns: string }) => T): LinkOption[] { + const ENV: LinkOption[] = []; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access const WS_URL = process.env.WS_URL || (window as any).process_env?.WS_URL as string; diff --git a/scripts/ipfsUpload.js b/scripts/ipfsUpload.js index f1fb81f3ba..2481d1ce9e 100644 --- a/scripts/ipfsUpload.js +++ b/scripts/ipfsUpload.js @@ -7,6 +7,7 @@ const pinataSDK = require('@pinata/sdk'); const cloudflare = require('dnslink-cloudflare'); const execSync = require('@polkadot/dev/scripts/execSync'); +const createEndpoints = require('../packages/apps-config/build/settings/endpoints'); const lernaInfo = require('../lerna.json'); // https://gateway.pinata.cloud/ipfs/ @@ -84,12 +85,30 @@ async function unpin (exclude) { } async function dnslink (hash) { - await cloudflare( - { token: process.env.CF_API_TOKEN }, - { link: `/ipfs/${hash}`, record: `_dnslink.${DOMAIN}`, zone: DOMAIN } - ); + const records = createEndpoints(() => '') + .map(({ dnslink }) => dnslink) + .filter((dnslink) => !!dnslink) + .reduce((all, dnslink) => { + if (!all.includes(dnslink)) { + all.push(dnslink); + } - console.log(`Dnslink ${hash}`); + return all; + }, [null]) + .map((sub) => + ['_dnslink', sub, DOMAIN] + .filter((entry) => !!entry) + .join('.') + ); + + await Promise.all(records.map((record) => + cloudflare( + { token: process.env.CF_API_TOKEN }, + { link: `/ipfs/${hash}`, record, zone: DOMAIN } + ) + )); + + console.log(`Dnslink ${hash} for ${records.join(', ')}`); } async function main () {