repo: uritools
action: commit
revision: 
path_from: 
revision_from: 4f9509b7fe0e345f5d8fa7540adba45b1a363f81:
path_to: 
revision_to: 
git.thebackupbox.net
uritools
git clone git://git.thebackupbox.net/uritools
commit 4f9509b7fe0e345f5d8fa7540adba45b1a363f81
Author: epoch 
Date:   Sun Nov 15 19:11:16 2020 -0600

    added unshorten.sh which attempts to unshorten shortened URLs. and data_handler... no comment.

diff --git a/Makefile b/Makefile
index 7809a59af514eebefce725b66d848ef5ca2730c4..
index ..1f3ccd2c6e759cdd6f9345df1a31b53ddd3f7877 100644
--- a/Makefile
+++ b/Makefile
@@ -37,3 +37,5 @@ install: all
 	install -t $(PREFIX)/bin copy_start_nevermind.sh
 	install -t $(PREFIX)/bin choose
 	install -t $(PREFIX)/bin query_param
+	install -t $(PREFIX)/bin data_handler
+	install -t $(PREFIX)/bin unshorten.sh
diff --git a/data_handler b/data_handler
new file mode 100755
index 0000000000000000000000000000000000000000..b3936bec0ff30a70d399c44d6bb10fdf899e59d2
--- /dev/null
+++ b/data_handler
@@ -0,0 +1,17 @@
+#!/bin/sh
+hash="$(printf "$1" | sha256sum | cut '-d ' -f1)"
+mime_data="$(printf "%s\n" "$1" | cut -d, -f1)"
+data="$(printf "%s\n" "$1" | cut -d, -f2-)"
+#echo $mime_data
+is_base64="$(printf "%s\n" "$mime_data" | tr ';' '\n' | grep '^base64$')"
+media_type="$(printf "%s\n" "$mime_data" | tr ';' '\n' | head -n1)"
+### what are we going to do with this file?
+mkdir -p ~/.local/var/cache/data
+printf "%s\n" "$data" \
+ | if [ "$is_base64" ];then
+     base64 -d 
+   else
+     uriunescape
+   fi \
+ > ~/.local/var/cache/data/$hash
+uristart "file:///home/epoch/.local/var/cache/data/$hash?mime-type=$media_type"
diff --git a/unshorten.sh b/unshorten.sh
new file mode 100755
index 0000000000000000000000000000000000000000..8a3b49e8cb18ceb7d3062f37fbd2ef2e8e803d61
--- /dev/null
+++ b/unshorten.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+uri="$1"
+path="$(printf '%s\n' "$uri" | uricut -p)"
+scheme="$(printf '%s\n' "$uri" | uricut -s)"
+domain="$(printf '%s\n' "$uri" | uricut -d)"
+port="$(printf '%s\n' "$uri" | uricut -P)"
+
+case "$scheme" in
+  http*)
+    curl -Lsi "$1" | grep -i ^Location: | head -n1 | tr -s ' ' | tr -d '\r' | cut '-d ' -f2- | sed 's|^/|'"$scheme"'://'"$domain"'/|g'
+    ;;
+  gemini)
+    gemini-get "$1" | head -n1 | sed 's/^3[0-9] //g'
+    ;;
+  *)
+    printf "dunno how to handle this type of URI\n"
+    ;;
+esac

-----END OF PAGE-----