diff --git a/app/crawler/notea.sh b/app/crawler/notea.sh index e79e691..36ea2b4 100644 --- a/app/crawler/notea.sh +++ b/app/crawler/notea.sh @@ -6,6 +6,42 @@ notea() ( } 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$' \ diff --git a/app/crawler/notea_test.sh b/app/crawler/notea_test.sh index f119886..426feb4 100644 --- a/app/crawler/notea_test.sh +++ b/app/crawler/notea_test.sh @@ -3,20 +3,33 @@ test_ids() { notea eval "$(cat <&2 + ;; + esac } ids | wc -l | grep -q 1 || return 101 ids | grep -q def || return 102