From: Paul Hänsch Date: Wed, 8 Jan 2020 20:01:29 +0000 (+0100) Subject: therapy saving X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=90041d8be2590c270a69f1eb44b882a863491aca;p=lobster therapy saving --- diff --git a/therapies/update_therapy.sh b/therapies/update_therapy.sh index 6ba06cb..ec8ccdc 100755 --- a/therapies/update_therapy.sh +++ b/therapies/update_therapy.sh @@ -1,6 +1,6 @@ #!/bin/zsh -# Copyright 2016 Paul Hänsch +# Copyright 2016, 2020 Paul Hänsch # # This file is part of Confetti. # @@ -19,52 +19,51 @@ BR=' ' -tpy="${_POST[id]}" +tpy=$(POST id) -tpyfile="$_DATA/therapies/$tpy" -tempfile="$_DATA/temp/$tpy" +tpyfile="$_DATA/therapies/${tpy}.tpy" +tempfile="$_DATA/temp/${tpy}.tpy" # serialize POST array into file -for key in ${(k)_POST}; do - [ "$key" != imagedata ] && printf %s:%s\\n "$key" "${_POST[$key]//$BR/\\n}" +for key in $(POST_KEYS); do + [ "$key" != imagedata ] && printf %s:%s\\n "$key" "$(POST "$key" |sed ':X;N;$!bX; s;\n;\\n;g;')" done >"$tempfile" -if [ -n "$_POST[delete_session]" ]; then - n="$_POST[delete_session]" - sed -i -r '/^session'$n'[_:]/d' "$tempfile" +if [ "$(POST delete_session)" ]; then + n="$(POST delete_session)" + sed -Ei '/^session'$n'[_:]/d' "$tempfile" rm "${tpyfile%.tpy}_session${n}.png" while grep -Eq '^session'$(($n + 1))'_' "$tempfile"; do - sed -i -r 's;^session'$(($n + 1))'(_|:);session'$n'\1;' "$tempfile" + sed -Ei 's;^session'$(($n + 1))'(_|:);session'$n'\1;' "$tempfile" mv "${tpyfile%.tpy}_session$(($n+1)).png" "${tpyfile%.tpy}_session${n}.png" n=$(($n+1)) done -elif [ -n "$_POST[new_session]" ]; then - sid="$_POST[new_session]" +elif [ "$(POST new_session)" ]; then + sid="$(POST new_session)" - identify "$_EXEC/static/therapy_background.png" \ - | sed -r 's;^.* ([0-9]+x[0-9]+) .*$;\1;' \ - | read dim + read junkx junky dim junkz <<-E_READ + $(identify "$_EXEC/therapies/therapy_background.png") + E_READ convert -size "$dim" xc:transparent "${tpyfile%.tpy}_${sid}.png" printf '%s:exists\n' "$sid" >>"$tempfile" printf '%s_open:checked\n' "$sid" >>"$tempfile" -elif [ -n "$_POST[imagedata]" ]; then - sed -rn 's;^(session[0-9]+)_open:checked$;\1;p' "$tempfile" \ - | sort -n \ - | tail -n1 \ - | read sid +elif [ "$(POST imagedata)" ]; then + sid="$(sed -En 's;^(session[0-9]+)_open:checked$;\1;p' "$tempfile" \ + | sort -n \ + | tail -n1 + )" convert "${tpyfile%.tpy}_${sid}.png" \ - -strokewidth 2 -fill '#00000000' \ - -draw "${_POST[imagedata]}" -transparent white \ + -draw "$(POST imagedata)" -transparent white \ "${tpyfile%.tpy}_${sid}.png" sync fi mv "$tempfile" "$tpyfile" -redirect "?p=therapy&id=${tpy}" +REDIRECT "/therapies/${tpy%.*}/${tpy#*.}"