rm old notea
parent
b582041af1
commit
6c2f22f756
|
|
@ -1,66 +0,0 @@
|
||||||
#! /bin/bash
|
|
||||||
|
|
||||||
test_ids() {
|
|
||||||
notea eval "$(cat <<EOF
|
|
||||||
ncurl() {
|
|
||||||
case "\$1" in
|
|
||||||
*/api/tree )
|
|
||||||
echo '{
|
|
||||||
"items": {
|
|
||||||
"root": {
|
|
||||||
"children": [
|
|
||||||
"abc",
|
|
||||||
"xyz"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"abc": {
|
|
||||||
"id": "def"
|
|
||||||
},
|
|
||||||
"def": {
|
|
||||||
"pid": "root"
|
|
||||||
},
|
|
||||||
"xyz": {
|
|
||||||
"pid": "root",
|
|
||||||
"deleted": 1,
|
|
||||||
"children": [
|
|
||||||
"wvu"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"wvu": {
|
|
||||||
"pid": "xyz",
|
|
||||||
"deleted": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}'
|
|
||||||
;;
|
|
||||||
*/api/notes/def/meta )
|
|
||||||
echo '{
|
|
||||||
"deleted": 0
|
|
||||||
}'
|
|
||||||
;;
|
|
||||||
* )
|
|
||||||
echo UNKNOWN NCURL "\$*" >&2
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
ids | wc -l | grep -q 1 || return 101
|
|
||||||
ids | grep -q def || return 102
|
|
||||||
! ids | grep -q wvu || return 103
|
|
||||||
! ids | grep -q xyz || return 104
|
|
||||||
EOF
|
|
||||||
)"
|
|
||||||
}
|
|
||||||
|
|
||||||
test_get() {
|
|
||||||
notea eval "$(cat <<EOF
|
|
||||||
ncurl() {
|
|
||||||
echo "$*" | grep -q \/api\/notes\/abc
|
|
||||||
echo 'asdf'
|
|
||||||
}
|
|
||||||
! cache get "notea cache abc" | grep -q asdf || return 101
|
|
||||||
get abc | wc -l | grep -q 1 || return 102
|
|
||||||
get abc | grep -q asdf || return 103
|
|
||||||
cache get "notea cache abc" | grep -q asdf || return 104
|
|
||||||
EOF
|
|
||||||
)"
|
|
||||||
}
|
|
||||||
|
|
@ -1,100 +0,0 @@
|
||||||
#! /bin/bash
|
|
||||||
|
|
||||||
notea() (
|
|
||||||
ncurl() {
|
|
||||||
curl -sS "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
ids() {
|
|
||||||
for id in $(_tree_ids); do
|
|
||||||
if ! _is_deleted $id; then
|
|
||||||
echo $id
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
meta() {
|
|
||||||
local cache_key="notea cache meta $1"
|
|
||||||
if cache get "$cache_key"; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
_meta "$@" | cache put "$cache_key"
|
|
||||||
}
|
|
||||||
|
|
||||||
_meta() {
|
|
||||||
ncurl $NOTEA_ADDR/api/notes/$1/meta
|
|
||||||
}
|
|
||||||
|
|
||||||
_is_deleted() {
|
|
||||||
local id="$1"
|
|
||||||
if [ "$id" == "root" ] || [ "$id" == "null" ]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
local meta="$(meta "$id")"
|
|
||||||
if echo "$meta" | jq .deleted | grep -q 1; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
local pid="$(echo "$meta" | jq -r .pid)"
|
|
||||||
if [ -z "$pid" ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
_is_deleted "$pid"
|
|
||||||
}
|
|
||||||
|
|
||||||
_tree_ids() {
|
|
||||||
ncurl $NOTEA_ADDR/api/tree \
|
|
||||||
| jq '.items | to_entries[].value.id' \
|
|
||||||
| grep -v '^null$' \
|
|
||||||
| jq -r . \
|
|
||||||
| grep -v '^root$'
|
|
||||||
}
|
|
||||||
|
|
||||||
get() {
|
|
||||||
local cache_key="notea cache $1"
|
|
||||||
if cache get "$cache_key"; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
_get "$@" | cache put "$cache_key"
|
|
||||||
}
|
|
||||||
|
|
||||||
_get() {
|
|
||||||
ncurl $NOTEA_ADDR/api/notes/$1
|
|
||||||
}
|
|
||||||
|
|
||||||
put() {
|
|
||||||
set -u
|
|
||||||
local ret=0
|
|
||||||
if ! _put "$@"; then
|
|
||||||
ret=1
|
|
||||||
fi
|
|
||||||
set +u
|
|
||||||
return $ret
|
|
||||||
}
|
|
||||||
|
|
||||||
_put() {
|
|
||||||
local xsrf_key="xsrf-token"
|
|
||||||
local contains_tokens="$(ncurl -i $NOTEA_ADDR/api)"
|
|
||||||
local xsrf_token="$(echo "$contains_tokens" | grep -o '"csrfToken":[^,]*' | tr ':' '\n' | jq -r . | tail -n 1)"
|
|
||||||
local xsrf_cookie="$(echo "$contains_tokens" | grep ^set.cookie: | sed 's/^set.cookie: //' | tr ';' '\n' | head -n 1)"
|
|
||||||
local request="$(echo '{
|
|
||||||
"content": '"$(printf "%s\n" "$CONTENT" | jq -Rs)"',
|
|
||||||
"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 @- \
|
|
||||||
$NOTEA_ADDR/api/notes \
|
|
||||||
| grep -q "$ID"
|
|
||||||
}
|
|
||||||
|
|
||||||
"$@"
|
|
||||||
)
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue