From 954b8e932e2eb5045fb8e7bfea1b134ed7542f5b Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Thu, 10 Feb 2022 07:04:11 -0700 Subject: [PATCH] test meta notnotea --- app/crawler/notnotea.sh | 41 +++++++++++++++++------------------- app/crawler/notnotea_test.sh | 22 +++++++++++++++++++ 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/app/crawler/notnotea.sh b/app/crawler/notnotea.sh index 2ba7a7f..facd131 100644 --- a/app/crawler/notnotea.sh +++ b/app/crawler/notnotea.sh @@ -1,13 +1,24 @@ #! /bin/bash notnotea() ( - _nncurl() { - curl -sS "$@" + ids() { + _recurse_ids "" "$(_tree)" } - ids() { - local tree="$(_nncurl $NNOTEA_ADDR/api/v0/tree)" - _recurse_ids "" "$tree" + _tree() { + local cache_key="notnotea cache _tree" + if cache get "$cache_key"; then + return 0 + fi + __tree "$@" | cache put "$cache_key" + } + + __tree() { + _nncurl $NNOTEA_ADDR/api/v0/tree + } + + _nncurl() { + curl -sS "$@" } _recurse_ids() { @@ -29,24 +40,10 @@ notnotea() ( done } - 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 + local key="$1" + key="${key//\//.Branches.}" + _tree | jq -c ".Branches.$key.Leaf" } _is_deleted() { diff --git a/app/crawler/notnotea_test.sh b/app/crawler/notnotea_test.sh index f5caa65..9241630 100644 --- a/app/crawler/notnotea_test.sh +++ b/app/crawler/notnotea_test.sh @@ -16,3 +16,25 @@ test__recurse_ids() { (notnotea _recurse_ids "" "$two_levels"; true) | tail -n 1 | grep -q '^id\/subid$' || return 102 notnotea _recurse_ids "" "$two_levels" | wc -l | grep -q 2 || return 103 } + +test_meta() { + local two_levels='{ + "Branches": { + "id": { + "Leaf": {"Title": "top level"}, + "Branches": { + "subid": { + "Leaf": {"Title": "sub level"}, + "Branches": {} + } + } + } + } + }' + notnotea eval "$(cat <