Upload your file to Astroport

This commit is contained in:
fred 2022-11-19 03:18:09 +01:00
parent 1e74e8ad87
commit a48fd636ee
4 changed files with 283 additions and 19 deletions

View File

@ -297,8 +297,8 @@ echo "" > ~/.zen/tmp/.ipfsgw.bad.twt # TODO move in 20h12.sh
[[ $(cat ~/.zen/tmp/.ipfsgw.bad.twt | grep -w $nicegw) ]] && echo "<<< BAD GATEWAY >>> $nicegw" && continue
gum=$(echo "$nicegw" | sed "s~:hash~$DATAID~g")
echo "LOADING $gum"
curl -m 3 -so ~/.zen/tmp/${IPFSNODEID}/${ASTRONAUTENS}/${APPNAME}/${MOATS}.data.${WHAT} "$gum"
[[ $? != 0 ]] && echo "(✜‿‿✜) $nicegw BYPASSING"; echo
curl -m 5 -so ~/.zen/tmp/${IPFSNODEID}/${ASTRONAUTENS}/${APPNAME}/${MOATS}.data.${WHAT} "$gum"
[[ $? != 0 ]] && echo "(✜‿‿✜) BYPASSING"; echo
if [[ -s ~/.zen/tmp/${IPFSNODEID}/${ASTRONAUTENS}/${APPNAME}/${MOATS}.data.${WHAT} ]]; then
@ -306,8 +306,9 @@ echo "" > ~/.zen/tmp/.ipfsgw.bad.twt # TODO move in 20h12.sh
GOAL=$(ipfs add -q ~/.zen/tmp/${IPFSNODEID}/${ASTRONAUTENS}/${APPNAME}/${MOATS}.data.${WHAT})
if [[ ${GOAL} != ${DATAID} ]]; then
echo " (╥☁╥ ) - $nicegw ${WHAT} FORMAT ERROR - (╥☁╥ )"
echo " (╥☁╥ ) - BAD ${WHAT} FORMAT ERROR ${MIME} - (╥☁╥ )"
ipfs pin rm /ipfs/${GOAL}
rm ~/.zen/tmp/${IPFSNODEID}/${ASTRONAUTENS}/${APPNAME}/${MOATS}.data.${WHAT}
# NOT A JSON AVOID BANISHMENT
echo $nicegw >> ~/.zen/tmp/.ipfsgw.bad.twt
continue
@ -317,12 +318,12 @@ echo "" > ~/.zen/tmp/.ipfsgw.bad.twt # TODO move in 20h12.sh
ipfs pin add /ipfs/${GOAL}
## + TW ADD (new_file_in_astroport.sh)
echo "(♥‿‿♥) $nicegw OK"; echo
echo "(♥‿‿♥) FILE UPLOAD OK"; echo
break
fi
echo " (⇀‿‿↼) - $nicegw TIMEOUT - (⇀‿‿↼)"
echo " (⇀‿‿↼) - TIMEOUT - (⇀‿‿↼)"
continue
fi

View File

@ -484,15 +484,13 @@ fi
mkdir -p ~/astroport/${CAT}/${MEDIAID}/
mv /tmp/screen.png ~/astroport/${CAT}/${MEDIAID}/screen.png
mv -f "${FILE_PATH}/${FILE_NAME}" "$HOME/astroport/${CAT}/${MEDIAID}/${TITLE}.${FILE_EXT}"
mv -f "${FILE_PATH}/${FILE_NAME}" "$HOME/astroport/${CAT}/${MEDIAID}/${TITLE}${SAISON}.${FILE_EXT}"
if [ $? == 0 ]; then
zenity --warning --width ${large} --text "Votre fichier ~/astroport/${CAT}/${MEDIAID}/${TITLE}.${FILE_EXT} est prêt à embarquer. Cliquez sur OK, nous allons préparer son script d'ajout à Astroport..."
else
if [ $? != 0 ]; then
zenity --warning --width ${large} --text "Impossible de déplacer votre fichier ${FILE_PATH}/${FILE_NAME} vers ~/astroport - EXIT -"
exit 1
fi
FILE_NAME="${TITLE}.${FILE_EXT}"
FILE_NAME="${TITLE}${SAISON}.${FILE_EXT}"
## CREATE "~/astroport/${CAT}/${MEDIAID}/ajouter_video.txt"
@ -538,7 +536,7 @@ echo "${CAT};${MEDIAID};${YEAR};${TITLE};${SAISON};${GENRES};_IPNSKEY_;${RES};/i
## CREATE SIMPLE JSON (REMOVE== it ?
jq -n --arg ts "$MEDIAID" --arg title "$TITLE" --arg desc "$DESCRIPTION" --arg htag "$HASHTAG" '{"timestamp":$ts,"ipfs":"_IPFSREPFILEID_","ipns":"_IPNSKEY_","title":$title,"desc":$desc,"tag":$htag}' > ~/astroport/${CAT}/${MEDIAID}/video.json
## MOVE FILE TO IMPORT ZONE
mv -f "${FILE_PATH}/${FILE_NAME}" "$HOME/astroport/${CAT}/${MEDIAID}/${TITLE}.${FILE_EXT}"
mv -f "${FILE_PATH}/${FILE_NAME}" "$HOME/astroport/${CAT}/${MEDIAID}/${TITLE}${SAISON}.${FILE_EXT}"
FILE_NAME="${TITLE}.${FILE_EXT}"
;;
@ -556,9 +554,9 @@ echo "${CAT};${MEDIAID};${YEAR};${TITLE};${SAISON};${GENRES};_IPNSKEY_;${RES};/i
esac
## Extract thumbnail
MIME=$(file --mime-type -b $HOME/astroport/${CAT}/${MEDIAID}/${TITLE}.${FILE_EXT})
MIME=$(file --mime-type -b $HOME/astroport/${CAT}/${MEDIAID}/${TITLE}${SAISON}.${FILE_EXT})
[[ $(echo $MIME | grep video) ]] && ffmpeg -i $HOME/astroport/${CAT}/${MEDIAID}/${TITLE}.${FILE_EXT} -r 1/300 -vf scale=-1:120 -vcodec png $HOME/astroport/${CAT}/${MEDIAID}/thumbnail.png
[[ $(echo $MIME | grep video) ]] && ffmpeg -i $HOME/astroport/${CAT}/${MEDIAID}/${TITLE}${SAISON}.${FILE_EXT} -r 1/300 -vf scale=-1:120 -vcodec png $HOME/astroport/${CAT}/${MEDIAID}/thumbnail.png
[[ ! -f ~/astroport/${CAT}/${MEDIAID}/thumbnail.png ]] && echo "DEFAULT THUMBNAIL NEEDED"
########################################################################

View File

@ -456,6 +456,9 @@ then
[[ $CAT == "Film" ]] && tdb="movie"
[[ $CAT == "Serie" ]] && tdb="tv"
# CapitalGluedTitle
CapitalGluedTitle=$(echo "${TITLE}" | sed -r 's/\<./\U&/g' | sed 's/ //g')
GENRE=$(cat ~/astroport/${TyPE}/${REFERENCE}/ajouter_video.txt | cut -d ';' -f 6 | sed 's/|/ /g' | jq -r '@csv' | sed 's/ /_/g' | sed 's/,/ /g' | sed 's/\"//g' )
echo $GENRE
@ -474,9 +477,9 @@ then
if [[ $(echo "$MIME" | grep 'video') ]]; then
TEXT="<video controls width=100% poster='/ipfs/"${ANIMH}"'><source src='/ipfs/"${IPFSID}"' type='"${MIME}"'>
</video><h1><a href='https://www.themoviedb.org/"${tdb}"/"${REFERENCE}"'>"${TITLE}"</a></h1>
</video><h1><a target='tmdb' href='https://www.themoviedb.org/"${tdb}"/"${REFERENCE}"'>"${CapitalGluedTitle}"</a></h1>
<h2>"$DESCRIPTION"</h2>
<img src='/ipfs/"${POSTER}"' width=72%></img><br>
<img src='/ipfs/"${POSTER}"' width=33%><br>
<\$button class='tc-tiddlylink'>
<\$list filter='[tag[G1${CAT}]]'>
<\$action-navigate \$to=<<currentTiddler>> \$scroll=no/>
@ -484,14 +487,14 @@ then
Afficher tous les G1${CAT}
</\$button>"
TidType="text/vnd.tiddlywiki" ## MAYBE REAL ONCE TW CAN SHOW ATTACHED IPFS VIDEO (TODO: TESTINGS)
TAGS="G1${CAT} ${PLAYER} $GENRE ipfs ${HASHTAG}"
TAGS="G1${CAT} ${PLAYER} ${CapitalGluedTitle} $GENRE ipfs ${HASHTAG}"
# TyPE="$MIME"
# CANON="/ipfs/"${IPFSID}
CANON=''
else
TidType="${MIME}"
TEXT='${MEDIAKEY}'
TAGS="'$:/isAttachment $:/isIpfs G1${CAT} $GENRE"
TAGS="'$:/isAttachment $:/isIpfs G1${CAT} ${PLAYER} ${CapitalGluedTitle} $GENRE ${HASHTAG}"
CANON="/ipfs/"${IPFSID}
fi
@ -499,7 +502,7 @@ then
echo '[
{
"text": "'${TEXT}'",
"title": "'${TITLE}'",
"title": "'${CapitalGluedTitle}'",
"created": "'${MOATS}'",
"resolution": "'${RES}'",
"gifanime": "'/ipfs/${ANIMH}'",

View File

@ -1 +1,263 @@
<head><meta http-equiv='Refresh' content='0; URL=_REDIRLINK_'></head>
<html class=" rrghhqet idc0_344 cadefrffwk ftnryedt"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Upload files to Astroport</title>
<style>
a, a:hover, a:visited, a:active {
color: #fff;
text-decoration: none;
}
body {
border: 0;
margin: 0;
font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;
background-color: #041d2f;
color: #fff;
display: flex;
flex-direction: column;
min-height: 100vh;
}
input[type=text] {
width: 500px;
height: 50px;
text-align: center;
margin: 5px;
}
input[type=file] {
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}
input[type=file] + label {
display: inline-block;
font-size: 1.25em;
font-weight: 700;
color: #333;
background-color: #fff;
border-radius: 5px;
padding: 20px;
}
input[type=file]:focus + label,
input[type=file] + label:hover {
background-color: #fff;
}
label {
cursor: pointer;
}
button {
width: 500px;
height: 50px;
text-align: center;
margin: 5px;
cursor: pointer;
}
.content {
flex: 1;
margin: 10px;
text-align: center;
}
.informations {
font-size: 24px;
}
.image {
display: block;
margin: 0 auto;
height: 300px;
margin-bottom: 40px;
}
.wrapWithDirectoryContainer {
font-size: 16px;
}
.footer {
text-align: center;
margin: 10px;
}
</style>
<script src="ipfs.js"></script>
</head>
<body>
<div class="content">
<img src="./logo-astroport.png" class="image">
<div id="informations" class="informations">
Téléverser un fichier vers Astroport
</div>
<br>
<br>
<form>
<input id="file" type="file">
<label for="file">Choose a file</label>
<br>
<br>
<div class="wrapWithDirectoryContainer">
<input id="wrapWithDirectory" type="checkbox">
<label for="wrapWithDirectory">Wrap with a directory (recommended)</label>
</div>
</form>
</div>
<script>
function cacheIt (appName, hash, nodeId = '') {
var gatewayProtocol = 'https';
var gatewayDomain = 'tube.copylaradio.com';
var gatewayPort = '1234';
var salt = 'totodu56';
var pepper = 'totodu56';
var query = 'salt='+ salt
query += '&pepper='+ pepper
query += '&' + appName
query += '&nodeid=' + nodeId
query += '&dataid=' + hash;
var URL1234 = 'http://'+ gatewayDomain +':'+ gatewayPort + '/?' + query;
console.log(URL1234)
var fullURL = 'https://'+ gatewayDomain +'/'+ gatewayPort + '/?' + query;
console.log(fullURL)
const controller = new AbortController()
const timeoutId = setTimeout( () => {
controller.abort()
}, 15000)
var fetchOpts = {
method: 'GET',
headers: {
'Accept': 'text/html'
// ,'Content-Type': 'text/html'
// // ,'Access-Control-Allow-Origin': '*',
// ,'Origin': 'la-bureautique'
// ,'Referrer-Policy': 'unsafe-url'
// ,'Redirect': 'manual'
},
signal: controller.signal
}
fetch(fullURL, fetchOpts)
.then(reponse => {
return reponse.text()
})
.then(html => {
// console.log(html)
var regex = /url='([^']+)/i;
var redirectURL = html.match(regex)[1]
return redirectURL
})
.then(url => {
console.log(url)
})
// JSON.stringify(json)
}
async function ipfs_init() {
const node = await window.IpfsCore.create(
{
config: {
Addresses: {
Swarm: [
'/dns4/wrtc-star1.par.dwebops.pub/tcp/443/wss/p2p-webrtc-star',
'/dns4/wrtc-star2.sjc.dwebops.pub/tcp/443/wss/p2p-webrtc-star'
]
}
}
}
);
let nodeId = await node.id();
console.log('node id :', nodeId)
nodeId = nodeId.id
console.log(nodeId)
const version = await node.version();
console.log('Version:', version.version);
async function ipfs_upload(file, wrapWithDirectory) {
const fileAdded = await node.add(
{
path: file.name,
content: file
},
{
wrapWithDirectory,
progress: bytesAdded => document.getElementById('informations').innerHTML = `Sending... ${Math.round((bytesAdded / file.size) * 100)}%`
}
);
const cid = fileAdded.cid.toString();
document.getElementById('informations').innerHTML = [
'The file has been added to IPFS!',
'',
'Its hash (CID) is:',
`<a href="https://download-a-file-from-ipfs.com/?cid=${cid}" target="_blank">${cid}</a>`,
'(click to download it)'
].join('<br />');
cacheIt('testcraft=on', cid, nodeId)
}
document.getElementById('file').disabled = false;
document.getElementById('file').addEventListener('change', async event => {
event.preventDefault();
document.getElementById('file').disabled = true;
const fileInput = document.getElementById('file');
if (!fileInput.files.length) {
alert('You have to select a file first');
} else {
const wrapWithDirectory = document.getElementById('wrapWithDirectory').checked;
await ipfs_upload(fileInput.files[0], wrapWithDirectory)
.catch(error => alert(error.toString()));
}
document.getElementById('file').disabled = false;
});
}
ipfs_init();
</script>
</body></html>