shithub: rc-gemd

Download patch

ref: 89c9f20250438c4768fc3186d9d83b45d2997c03
parent: 0de05aed17a583e6b74ce4d02876f9bfa88c9c2a
author: Moody <j4kem00dy@gmail.com>
date: Wed Aug 19 19:39:24 EDT 2020

Parse query options properly
Add require input script for prompting client
Add example of require-input use in select-handler

--- /dev/null
+++ b/handlers/require-input
@@ -1,0 +1,5 @@
+#!/bin/rc
+if(~ $query ''){
+	echo 10^' '^$1^$cr
+	exit
+}
--- a/rc-gemd
+++ b/rc-gemd
@@ -14,6 +14,9 @@
 server_name=`{echo $url | sed 's,/.*,,'}
 location=`{echo $url | sed 's,[a-zA-Z0-9.:]+/?,/,'}
 
+query=`{echo $location | sed 's,[^?]*\??,,'}
+location=`{echo $location | sed 's,\?.*,,'}
+
 echo request from `{sed 's/!.*//' $net/remote} to $url >[1=2]
 
 . $rc_gemd_dir/select-handler
--- a/select-handler
+++ b/select-handler
@@ -1,5 +1,16 @@
 #!/bin/rc
+fs_root=/lib/gem
 if(~ $location /)
 	location=/index.gem
-fs_root=/lib/gem
+
+if(~ $location /search){
+	. $rc_gemd_dir/handlers/require-input 'Input a search query'
+	echo 20^' '^'text/gemini'^$cr
+	sq=`{echo $query | urlencode -d}
+	ls $fs_root | grep $"sq | sed '
+		s,^'$fs_root'/,,g
+		s,^,=> ,g'
+	exit
+}
+
 exec serve-static