only list if recursively not deleted and test
parent
0a3943561f
commit
1c6cdec2c0
|
|
@ -6,6 +6,42 @@ notea() (
|
||||||
}
|
}
|
||||||
|
|
||||||
ids() {
|
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 \
|
ncurl $NOTEA_ADDR/api/tree \
|
||||||
| jq '.items | to_entries[].value.id' \
|
| jq '.items | to_entries[].value.id' \
|
||||||
| grep -v '^null$' \
|
| grep -v '^null$' \
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@
|
||||||
test_ids() {
|
test_ids() {
|
||||||
notea eval "$(cat <<EOF
|
notea eval "$(cat <<EOF
|
||||||
ncurl() {
|
ncurl() {
|
||||||
echo "$*" | grep -q \/api\/tree
|
case "\$1" in
|
||||||
|
*/api/tree )
|
||||||
echo '{
|
echo '{
|
||||||
"items": {
|
"items": {
|
||||||
"root": {
|
"root": {
|
||||||
|
|
@ -14,9 +15,21 @@ test_ids() {
|
||||||
"abc": {
|
"abc": {
|
||||||
"id": "def"
|
"id": "def"
|
||||||
},
|
},
|
||||||
"def": {}
|
"def": {
|
||||||
|
"pid": "root"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}'
|
}'
|
||||||
|
;;
|
||||||
|
*/api/notes/def/meta )
|
||||||
|
echo '{
|
||||||
|
"deleted": 0
|
||||||
|
}'
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
echo UNKNOWN NCURL "\$*" >&2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
ids | wc -l | grep -q 1 || return 101
|
ids | wc -l | grep -q 1 || return 101
|
||||||
ids | grep -q def || return 102
|
ids | grep -q def || return 102
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue