toymaker.git

commit 969e309827f4be006431a20d2da601ee36184599

Author: Adam <git@apiote.xyz>

format code

 toymaker.sh | 27 ++++++++-------------------


diff --git a/toymaker.sh b/toymaker.sh
index bf8db9a1a0c8f9577175e39eb0b98a99cfd7f7c0..82b8ae35d3b9a5c62cd3c2af213280d1dfa1ccc9 100755
--- a/toymaker.sh
+++ b/toymaker.sh
@@ -12,7 +12,6 @@
 exec >>~/toymaker.log
 exec 2>&1
 
-# program name
 program=${0##*/}
 
 usage() {
@@ -31,10 +30,8 @@
 # default listening port
 port=1313
 
-# Configure in accordance with your environment
 nc=$(command -v nc) || true
 
-# todo mktmp
 pid_file=/tmp/$program.pid
 
 slashes() {
@@ -87,13 +84,8 @@ 	page="$1"
 	contentType="$2"
 	[ -z "$contentType" ] && contentType='text/html'
 
-	# { cat "$fifo2" > /dev/null; printf ""; } > "$fifo1" &
-
 	printf "HTTP/1.1 200 OK\r\nContent-Length: %s\r\nContent-Type: %s\r\n\r\n%s\r\n" "${#page}" "$contentType" "$page" > "$fifo1"
 
-	# printf "%s\r\n" "$page" >> "$fifo1"
-
-	# sleep 1; echo "end" > "$fifo2"
 	printf "200 %s" "${#page}"
 }
 
@@ -192,7 +184,7 @@ 	GET)
 		if [ "$(slashes "$path")" -eq 2 ]
 		then
 			toy=$(field "$path" 3)
-			if [ "$toy"  = '' ]
+			if [ "$toy" = '' ]
 			then
 				if page=$(templateMessage "$(list_toys)" 'toys' 'text/html')
 				then
@@ -270,15 +262,13 @@ 		then
 			respond404 "$path"
 		fi
 
-		item=$(start_item "$toy")
-		if [ $! -gt 0 ]
+		if item=$(start_item "$toy")
 		then
-			respond500 "error while creating $toy"
+			respond202 "$toy" "$item"
 		else
-			respond202 "$toy" "$item"
+			respond500 "error while creating $toy"
 		fi
 
-		# todo delete old items, leave 1 stable, 1 errored
 		;;
 	DELETE)
 		check_auth "$authorization" || return
@@ -368,15 +358,15 @@ 	docroot="$1"
 fi
 docroot=$(cd "$docroot"; pwd)
 
-# FIFO to write HTTP response ## todo mktemp
+# FIFO to write HTTP response
 if ! fifo1=$(makefifo "${0##*/}.$$.1"); then
-	echo "$0: creating a named pipe failed.  Already running?" 1>&2
+	echo "$0: creating a named pipe failed. Already running?" 1>&2
 	exit 1
 fi
 
-# FIFO for internal event notification ## todo mktemp
+# FIFO for internal event notification
 if ! fifo2=$(makefifo "${0##*/}.$$.2"); then
-	echo "$0: creating a named pipe failed.  Already running?" 1>&2
+	echo "$0: creating a named pipe failed. Already running?" 1>&2
 	exit 1
 fi
 
@@ -391,7 +381,6 @@ Listening at the port number $port.
 Type ^C to quit.
 EOF
 
-# todo nc error should crash
 # shellcheck disable=SC2002
 while cat "$fifo1" | "$nc" -l -p "$port" | parse; do
 	: