Add homepage to IPNS qo-op address (instead of redirect to latest IPFS)

This commit is contained in:
fred 2022-04-08 02:47:03 +02:00
parent ab1adc3b77
commit 59ca2e4e86
3 changed files with 134 additions and 4 deletions

View File

@ -157,6 +157,7 @@ echo "##########################################################################
IsThere=$(cat ~/.zen/bunkerbox/history.json | jq .Videos[].link | grep $VUID)
if [[ ! $IsThere ]]; then
echo "Add $INDEX to ~/.zen/bunkerbox/$VUID/media/history.json"
## history.json Videos.link is the HTML code displayed in index.html with pagination.js (related to)
cat ~/.zen/bunkerbox/history.json | jq '.Videos += [{"link": "<a href='"'_INDEX_'"'><img src='"'_INDEX_/_VUID_.jpg'"' height=80 ></a><br>'"'_TITLE_'"'"}]' > ~/.zen/bunkerbox/$VUID/media/history.json
echo $INDEX
sed -i "s~_INDEX_~$INDEX~g" ~/.zen/bunkerbox/$VUID/media/history.json
@ -167,11 +168,13 @@ echo "##########################################################################
# COULD BE DONE LIKE THAT
# cat ~/.zen/bunkerbox/$VUID/media/history.json | jq --arg INDEX "$INDEX" --arg TITLE "$TITLE" '.Videos += [{"link": "<a href='''$INDEX''' >'''$TITLE'''</a>"}]' > ~/.zen/bunkerbox/history.json
echo "Mise à jour ~/.zen/bunkerbox/history.json"
[[ "$(cat ~/.zen/bunkerbox/$VUID/media/history.json)" == "" ]] && echo "FATAL ERROR MAJ" && exit 1
[[ "$(cat ~/.zen/bunkerbox/$VUID/media/history.json)" == "" ]] && echo "FATAL ERROR" && exit 1
# Upgrade local history.json with latest one
[[ -f ~/.zen/bunkerbox/$VUID/media/history.json ]] && cp -f ~/.zen/bunkerbox/$VUID/media/history.json ~/.zen/bunkerbox/history.json
fi
echo "<meta http-equiv=\"refresh\" content=\"0;URL=$INDEX\">" > ~/.zen/bunkerbox/index.html
# Create local index.html redirecting to current latest IPFS video
echo "<meta http-equiv=\"refresh\" content=\"0;URL=$IPFSNGW$INDEX\">" > ~/.zen/bunkerbox/index.html
echo "===== INDEX ===== $IPFSNGW/ipfs/$IPFSROOT"
echo "HISTORY : $IPFSNGW/ipfs/$IPFSROOT/history.json"
@ -227,9 +230,16 @@ echo "##########################################################################
############################################
## FIRST PUBLISH index.html (REDIRECT) + history.json + ts
mkdir -p /tmp/$VUID
echo "<meta http-equiv=\"refresh\" content=\"0;URL=$INDEX\">" > /tmp/$VUID/index.html
## This is the welcome page of your qo-op channel.
# Could be redirect, or ... Your homepage is introduced there !!
# echo "<meta http-equiv=\"refresh\" content=\"0;URL=$INDEX\">" > /tmp/$VUID/index.html
cp ${MY_PATH}/templates/homepage.html > /tmp/$VUID/index.html
cp ${MY_PATH}/templates/crowbunkerbox.png /tmp/$VUID/
sed -i "s~_IPNSL_~$IPNSL~g" /tmp/$VUID/index.html
cp ~/.zen/bunkerbox/history.json /tmp/$VUID/history.json
echo "$TS" > /tmp/$VUID/ts # TimeStamping
VROOT=$(ipfs add -wHq /tmp/$VUID/* | tail -n 1)
ipfs name publish --key=qo-op /ipfs/$VROOT
echo "qo-op : $IPFSNGW/ipns/$IPNS/history.json REDIRECT TO /ipfs/$VROOT"
@ -246,7 +256,7 @@ echo "##########################################################################
if [[ ! $InHere ]]; then
echo "NOUVELLE VIDEO."
mkdir -p /tmp/$VUID
echo "<meta http-equiv=\"refresh\" content=\"0;URL=$INDEX\">" > /tmp/$VUID/index.html
# echo "<meta http-equiv=\"refresh\" content=\"0;URL=$INDEX\">" > /tmp/$VUID/index.html
cp ~/.zen/bunkerbox/history.json /tmp/$VUID/history.json
echo "$TS" > /tmp/$VUID/ts # TimeStamping

BIN
templates/crowbunkerbox.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

120
templates/homepage.html Normal file
View File

@ -0,0 +1,120 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>[BunkerBOX] Home </title>
<link rel="icon" type="image/png" href="styles/logo.png" />
<link rel="stylesheet" href="styles/video-js.css" type="text/css" />
<link rel="stylesheet" href="styles/forest.css" type="text/css" />
<link rel="stylesheet" href="styles/decoration.css" type="text/css" />
<link rel="stylesheet" href="styles/layout.css" type="text/css" />
</head>
<body>
<header>
<h6>
<a href="_IPNSL_" target="bunker"> "<span>BunkerBOX</span>"</a> /ipfs/
</h6>
</header>
<main>
<center>
<img src="crowbunkerbox.png" border="0" usemap="#map" />
</center>
<map name="map">
<!-- #$-:Image map file created by GIMP Image Map plug-in -->
<!-- #$-:GIMP Image Map plug-in by Maurits Rijk -->
<!-- #$-:Please do not edit lines starting with "#$" -->
<!-- #$VERSION:2.3 -->
<!-- #$AUTHOR:fred -->
<area shape="rect" coords="0,0,330,62" href="http://crowdbunker.com" />
<area shape="rect" coords="421,3,876,57" href="http://crowdbunker.com/search?q=Astroport" />
<area shape="rect" coords="1002,0,1264,61" target="code" href="https://qo-op.com" />
<area shape="rect" coords="3,64,1260,205" target="code" href="http://opencollective.com/monnaie-libre/projects/bunker-box" />
</map>
<div id="videosList"><div class="wrapper"></div></div>
<article>
<div class="row justify-center">
<h1 class="video-title">
<a href="https://git.p2p.legal/qo-op/bunkerbox" target="code">
BunkerBOX copie, conserve et partage les chaines vidéos dans IPFS.<br>
Rendez in-censurable, in-arrêtable la liberté d'expression.<br>
</a>
</h1>
<p>Activez IPFS !
<br>
<ul>
<li>Débutant, sous Windows ou Mac ? Installez <a href="https://github.com/ipfs/ipfs-desktop/releases" target="code">IPFS Desktop</a> à votre OS</li>
<li>Conscient, sous Linux? Ajoutez <a href="https://github.com/ipfs/go-ipfs/releases" target="code">go-ipfs</a> à votre système</li>
<li>Rendre son navigateur compatible avec <a href="https://github.com/ipfs/ipfs-companion/releases" target="code"><b>ipfs-companion</b></a> !!</li>
</ul>
Bunker BOX ready ? Postulez pour devenir Hébergeur officiel de BunkerBOX.<br>Contactez support@qo-op.com<br>
</p>
</div>
</article>
<center>
<h6>
<a href="_IPNSL_"> _\/_ </a> powered by <a href="https://astroport.com"><span>"</span>Astroport<span>"</span></a>
</h6>
</center>
</main>
</body>
<script src="js/video.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/pagination.min.js"></script>
<link rel="stylesheet" href="styles/pagination.css" />
<script>
$.getJSON('_IPNSL_/history.json', function (json) {
$('#videosList').pagination({
dataSource: json.Videos,
pageSize: 1,
callback: function(data, pagination) {
var wrapper = $('#videosList .wrapper').empty();
$.each(data, function (i, f) {
$('#videosList .wrapper').append('<ul><li>' + f.link + '</li></ul>');
});
}
});
});
var arrTimes = [];
var i = 0; // start
var timesToTest = 5;
var tThreshold = 150; //ms
var testImage = "https://tube.copylaradio.com/ipfs/QmUUyiuCM4yXgaeGyqC2SVUUXZksuxhDfHQYpUpZPuL2oS/astroport.jpg"; // small image in your server
var dummyImage = new Image();
var isConnectedFast = false;
testLatency(function(avg){
isConnectedFast = (avg <= tThreshold);
/** output */
document.body.appendChild(
document.createTextNode("Time: " + (avg.toFixed(2)) + "ms - Bunker BOX ready ? " + isConnectedFast)
);
});
/** test and average time took to download image from server, called recursively timesToTest times */
function testLatency(cb) {
var tStart = new Date().getTime();
if (i<timesToTest-1) {
dummyImage.src = testImage + '?t=' + tStart;
dummyImage.onload = function() {
var tEnd = new Date().getTime();
var tTimeTook = tEnd-tStart;
arrTimes[i] = tTimeTook;
testLatency(cb);
i++;
};
} else {
/** calculate average of array items then callback */
var sum = arrTimes.reduce(function(a, b) { return a + b; });
var avg = sum / arrTimes.length;
cb(avg);
}
}
</script>
</html>