Reformat ipfs redirect (#2789)

This commit is contained in:
Jaco Greeff 2020-05-21 18:44:13 +02:00 committed by GitHub
parent 98c12fcc46
commit 10fc1f32df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 30 deletions

View File

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Redirecting to latest deployed IPFS instance</title>
<meta http-equiv="refresh" content="2; url=${url}" />
</head>
<body>
<p>Redirecting you to <a href="${url}">${url}</a></p>
</body>
</html>

View File

@ -6,8 +6,6 @@ const fs = require('fs');
const pinataSDK = require('@pinata/sdk');
const execSync = require('@polkadot/dev/scripts/execSync');
const lerna = require('../lerna.json');
// https://gateway.pinata.cloud/ipfs/
const GATEWAY = 'https://ipfs.io/ipfs/';
const DST = 'packages/apps/build';
@ -18,35 +16,43 @@ const token = process.env.GH_PAT || `x-access-token:${process.env.GITHUB_TOKEN}`
const repo = `https://${token}@github.com/${process.env.GITHUB_REPOSITORY}.git`;
const pinata = pinataSDK(process.env.PINATA_API_KEY, process.env.PINATA_SECRET_KEY);
function writeFiles (name, content) {
[DST, SRC].forEach((root) =>
fs.writeFileSync(`${root}/ipfs/${name}`, content, WOPTS)
);
}
function updateGh (hash) {
execSync('git add --all .');
execSync(`git commit --no-status --quiet -m "[CI Skip] ${hash}
skip-checks: true"`);
execSync(`git push ${repo} HEAD:${process.env.GITHUB_REF}`, true);
}
async function pin () {
const result = await pinata.pinFromFS(DST);
const url = `${GATEWAY}${result.IpfsHash}/`;
const html = `<!DOCTYPE html>
<html>
<head>
<title>Redirecting to latest deployed IPFS instance</title>
<meta http-equiv="refresh" content="0; url=${url}" />
<title>Redirecting to ipfs gateway</title>
<meta http-equiv="refresh" content="100; url=${url}" />
<style>
body { font-family: sans-serif; line-height: 1.5rem; padding: 2rem; text-align: center }
p { margin: 0 }
</style>
</head>
<body>
<p>Redirecting you to <a href="${url}">${url}</a></p>
<p>Redirecting to</p>
<p><a href="${url}">${url}</a></p>
</body>
</html>`;
const pinFile = JSON.stringify({ ...result, version: lerna.version });
// write the redirect
fs.writeFileSync(`${DST}/ipfs/index.html`, html, WOPTS);
fs.writeFileSync(`${SRC}/ipfs/index.html`, html, WOPTS);
// write the pin info
fs.writeFileSync(`${DST}/ipfs/pin.json`, pinFile, WOPTS);
fs.writeFileSync(`${SRC}/ipfs/pin.json`, pinFile, WOPTS);
execSync('git add --all .');
execSync(`git commit --no-status --quiet -m "[CI Skip] ${result.IpfsHash}
skip-checks: true"`);
execSync(`git push ${repo} HEAD:${process.env.GITHUB_REF}`, true);
writeFiles('index.html', html);
writeFiles('pin.json', JSON.stringify(result));
updateGh(result.IpfsHas);
console.log(`Pinned ${result.IpfsHash}`);