added session value support

This commit is contained in:
overflowerror 2022-01-13 22:00:25 +01:00
parent 3c41344d17
commit eceeb76eac
2 changed files with 22 additions and 4 deletions

View file

@ -29,10 +29,10 @@ session() {
value="$(queryString "val")" value="$(queryString "val")"
if test ! -z "$value"; then if test ! -z "$value"; then
setSession "$value" setSessionValue "val" "$value"
echo "saved to session" echo "saved to session"
else else
getSession getSessionValue "val"
fi fi
} }

View file

@ -67,12 +67,30 @@ startSession() {
fi fi
} }
getSession() { getSessionRaw() {
_getSession "$(_getSessionId)" | tail -n +2 _getSession "$(_getSessionId)" | tail -n +2
} }
setSession() { setSessionRaw() {
if _hasSession; then if _hasSession; then
echo "$1" | cat <(_getSessionDate) - > "$(_makeSessionPath "$(_getSessionId)")" echo "$1" | cat <(_getSessionDate) - > "$(_makeSessionPath "$(_getSessionId)")"
fi fi
} }
getSessionValue() {
key="$1"
getSessionRaw | grep -e "^$key=" | cut -d= -f2
}
setSessionValue() {
key="$1"
value="$2"
setSessionRaw "$(
getSessionRaw | while read entry; do
if test -z "$(echo "$entry" | grep -e "^$key=")"; then
echo "$entry"
fi
done
echo "$key=$value"
)"
}