manual test notnotea put

master
Bel LaPointe 2022-02-10 07:21:42 -07:00
parent 72e17bdd43
commit b582041af1
1 changed files with 9 additions and 22 deletions

View File

@ -68,7 +68,7 @@ notnotea() (
} }
get() { get() {
local cache_key="notea cache $1" local cache_key="notnotea cache $1"
if cache get "$cache_key"; then if cache get "$cache_key"; then
return 0 return 0
fi fi
@ -76,7 +76,7 @@ notnotea() (
} }
_get() { _get() {
_ncurl $NOTEA_ADDR/api/notes/$1 _nncurl $NNOTEA_ADDR/api/v0/files/$1
} }
put() { put() {
@ -90,27 +90,14 @@ notnotea() (
} }
_put() { _put() {
local xsrf_key="xsrf-token" local id="$1"
local contains_tokens="$(_ncurl -i $NOTEA_ADDR/api)" local title="$2"
local xsrf_token="$(echo "$contains_tokens" | grep -o '"csrfToken":[^,]*' | tr ':' '\n' | jq -r . | tail -n 1)" local body="$3"
local xsrf_cookie="$(echo "$contains_tokens" | grep ^set.cookie: | sed 's/^set.cookie: //' | tr ';' '\n' | head -n 1)" echo "$body" | _nncurl \
local request="$(echo '{ -X PUT \
"content": '"$(printf "%s\n" "$CONTENT" | jq -Rs)"', -H "Title: $title" \
"deleted": 0,
"id": '"$(echo "$ID" | jq -R)"',
"pid": '"$(echo "$PID" | jq -R)"',
"pinned": 0,
"shared": 0,
"title": '"$(echo "$TITLE [generated]" | jq -R)"'
}' | jq -c .)"
echo "$request" | _ncurl \
-X POST \
-H "$xsrf_key: $xsrf_token" \
-b "$xsrf_cookie" \
-H "Content-Type: application/json" \
-d @- \ -d @- \
$NOTEA_ADDR/api/notes \ $NNOTEA_ADDR/api/v0/files/$id
| grep -q "$ID"
} }
"$@" "$@"