Commit 77cd8346 authored by Vitaly Lipatov's avatar Vitaly Lipatov

eget: implement download_to_ipfs and use it

parent cf455407
...@@ -878,6 +878,19 @@ fi ...@@ -878,6 +878,19 @@ fi
if [ -n "$EGET_IPFS_DB" ] && ! is_ipfsurl "$1" ; then if [ -n "$EGET_IPFS_DB" ] && ! is_ipfsurl "$1" ; then
download_to_ipfs()
{
local URL="$1"
local res
#res="$(url_scat "$URL" | ipfs_put )" || return
#res="$(echo "$res" | grep "^added Qm")" || return 1
#CID="$(echo "$res" | cut -f2 -d" ")"
# with -q to disable progress (mixed with download progress)
res="$(url_scat "$URL" | ipfs_put -q)" || return
is_ipfs_hash "$res" || return 1
echo "$res"
}
# put remote content to stdout # put remote content to stdout
scat() scat()
{ {
...@@ -894,10 +907,7 @@ scat() ...@@ -894,10 +907,7 @@ scat()
return return
fi fi
local res CID="$(download_to_ipfs "$URL")" || return
res="$(url_scat "$URL" | ipfs_put )" || return
res="$(echo "$res" | grep "^added Qm")" || return 1
CID="$(echo "$res" | cut -f2 -d" ")"
ipfs_cat "$CID" || return ipfs_cat "$CID" || return
...@@ -940,10 +950,7 @@ sget() ...@@ -940,10 +950,7 @@ sget()
TARGET="$FN" TARGET="$FN"
fi fi
local res CID="$(download_to_ipfs "$REALURL")" || return
res="$(url_scat "$URL" | ipfs_put )" || return
res="$(echo "$res" | grep "^added Qm")" || return 1
CID="$(echo "$res" | cut -f2 -d" ")"
ipfs_get "$CID" "$TARGET" || return ipfs_get "$CID" "$TARGET" || return
put_cid_and_url "$URL" "$CID" "$FN" put_cid_and_url "$URL" "$CID" "$FN"
...@@ -959,10 +966,7 @@ check_url_is_accessible() ...@@ -959,10 +966,7 @@ check_url_is_accessible()
return return
fi fi
local res CID="$(download_to_ipfs "$REALURL")" || return
res="$(url_scat "$URL" | ipfs_put )" || return
res="$(echo "$res" | grep "^added Qm")" || return 1
CID="$(echo "$res" | cut -f2 -d" ")"
ipfs_cat "$CID" >/dev/null || return ipfs_cat "$CID" >/dev/null || return
local FN="$(url_get_filename "$URL")" || return local FN="$(url_get_filename "$URL")" || return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment