From 68a0d0f93989f9504925a1d4b1538d90b17d3192 Mon Sep 17 00:00:00 2001 From: Dark Decoy Date: Tue, 7 Mar 2023 15:10:01 +0000 Subject: [PATCH 1/5] Updated help menu and example for info command Add json format option to info command Fixed issue with returning all parts of the metadata Updated help menu and example for info command Add json format option to info command Fixed issue with returning all parts of the metadata Signed-off-by: Dark Decoy --- bin/hedgedoc | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/bin/hedgedoc b/bin/hedgedoc index b6b8173..9ae6ad7 100755 --- a/bin/hedgedoc +++ b/bin/hedgedoc @@ -70,6 +70,9 @@ Commands: history [--json] View the current logged in user's list of accessed notes. + info [--json] + View the metadata for a given note on the server. + Config: Configuration is set via environment variables (e.g. in ~/.bashrc or shell). @@ -107,6 +110,8 @@ Usage examples: \$ $SCRIPTNAME profile \$ $SCRIPTNAME history \$ $SCRIPTNAME history --json + \$ $SCRIPTNAME info qhmNmwmxSmK1H2oJmkKBQQ + \$ $SCRIPTNAME info qhmNmwmxSmK1H2oJmkKBQQ --json " @@ -177,6 +182,75 @@ function import_note() { echo "$note_id" } +function info_note() { + local note_id="$1" + local json="$2" + + if [[ ! "$note_id" ]]; then + echo "Error: You must specify an export type and note id to export." >&2 + echo "" >&2 + echo "Usage: $SCRIPTNAME info [--json]" >&2 + echo "For usage exmaples, see: $SCRIPTNAME help" >&2 + return 2 + fi + + local json="$2" + + if [[ ! "$note_id" ]]; then + echo "Error: You must specify an export type and note id to export." >&2 + echo "" >&2 + echo "Usage: $SCRIPTNAME info [--json]" >&2 + echo "For usage exmaples, see: $SCRIPTNAME help" >&2 + return 2 + fi + + if [[ "$json" == "--json" ]] + then + + curl \ + --silent \ + --cookie "$HEDGEDOC_COOKIES_FILE" \ + "${HEDGEDOC_SERVER}/$note_id/info" + + if [[ "$json" == "--json" ]] + then + + curl \ + --silent \ + --cookie "$HEDGEDOC_COOKIES_FILE" \ + "${HEDGEDOC_SERVER}/$note_id/info" + + else + + response="$( + curl \ + --silent \ + --cookie "$HEDGEDOC_COOKIES_FILE" \ + "${HEDGEDOC_SERVER}/$note_id/info" \ + | jq '.title, .description, .viewcount, .createtime, .updatetime') + )" + + SAVEIFS=$IFS + IFS=$'\n' + metadata=( $response ) + IFS=$SAVEIFS + + for ((i=0; i<${#metadata[@]}; i++)) + do + + temp=${metadata[$i]} + temp=${temp// /-} + + metadata[$i]=${temp//\"/ } + + done + + echo ${metadata[@]} + + fi + +} + function export_note() { local export_type="${1#--}" note_id="${2:-}" output_path="${3:-}" @@ -392,6 +466,9 @@ function main() { echo "$help_str" return 0 ;; + info) + info_note "${1:-}" "${2:-}" + ;; import|import-as) import_note "${1:-}" "${2:-}" ;; @@ -436,4 +513,3 @@ fi if [[ "${1:-}" != "--import" ]]; then main "$@" || exit $? fi - From a6e629157e85e4f2b585ae475cf858cb9ce044f1 Mon Sep 17 00:00:00 2001 From: Dark Decoy Date: Fri, 10 Mar 2023 15:43:34 +0000 Subject: [PATCH 2/5] Removed Duplicates Updated error messages Signed-off-by: Dark Decoy --- bin/hedgedoc | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/bin/hedgedoc b/bin/hedgedoc index 9ae6ad7..e92761e 100755 --- a/bin/hedgedoc +++ b/bin/hedgedoc @@ -187,31 +187,13 @@ function info_note() { local json="$2" if [[ ! "$note_id" ]]; then - echo "Error: You must specify an export type and note id to export." >&2 + echo "Error: You must specify a note id to retrieve metadata from the server." >&2 echo "" >&2 echo "Usage: $SCRIPTNAME info [--json]" >&2 echo "For usage exmaples, see: $SCRIPTNAME help" >&2 return 2 fi - local json="$2" - - if [[ ! "$note_id" ]]; then - echo "Error: You must specify an export type and note id to export." >&2 - echo "" >&2 - echo "Usage: $SCRIPTNAME info [--json]" >&2 - echo "For usage exmaples, see: $SCRIPTNAME help" >&2 - return 2 - fi - - if [[ "$json" == "--json" ]] - then - - curl \ - --silent \ - --cookie "$HEDGEDOC_COOKIES_FILE" \ - "${HEDGEDOC_SERVER}/$note_id/info" - if [[ "$json" == "--json" ]] then From f58d5f1bc59017f8af36e49c17b006ea1c4c61de Mon Sep 17 00:00:00 2001 From: Dark Decoy Date: Tue, 14 Mar 2023 14:52:40 +0000 Subject: [PATCH 3/5] Updated default output to be formatted Updated --raw option which returns bash array Signed-off-by: Dark Decoy --- bin/hedgedoc | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/bin/hedgedoc b/bin/hedgedoc index e92761e..1bd9429 100755 --- a/bin/hedgedoc +++ b/bin/hedgedoc @@ -184,7 +184,7 @@ function import_note() { function info_note() { local note_id="$1" - local json="$2" + local option="$2" if [[ ! "$note_id" ]]; then echo "Error: You must specify a note id to retrieve metadata from the server." >&2 @@ -194,7 +194,7 @@ function info_note() { return 2 fi - if [[ "$json" == "--json" ]] + if [[ "$option" == "--json" ]] then curl \ @@ -202,7 +202,7 @@ function info_note() { --cookie "$HEDGEDOC_COOKIES_FILE" \ "${HEDGEDOC_SERVER}/$note_id/info" - else + elif [[ "$option" == "--raw" ]] response="$( curl \ @@ -229,6 +229,26 @@ function info_note() { echo ${metadata[@]} + else + + response="$( + curl \ + --silent \ + --cookie "$HEDGEDOC_COOKIES_FILE" \ + "${HEDGEDOC_SERVER}/$note_id/info" + )" + title=$(echo "$response" | jq -r .title) + description=$(echo "$response" | jq -r .description) + viewcount=$(echo "$response" | jq -r .viewcount) + createtime=$(date -d $(echo "$response" | jq -r .createtime)) + updatetime=$(date -d $(echo "$response" | jq -r .updatetime)) + + echo "Title: ${title}" + echo "Description: ${description}" + echo "Viewcount: ${viewcount}" + echo "Created: ${createtime}" + echo "Updated: ${updatetime}" + fi } From 806e2c85a7a36d2b51bdbacf2ed02547e112fa6c Mon Sep 17 00:00:00 2001 From: Dark Decoy Date: Tue, 14 Mar 2023 14:55:52 +0000 Subject: [PATCH 4/5] Updated help documentation for new --raw option Signed-off-by: Dark Decoy --- bin/hedgedoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/hedgedoc b/bin/hedgedoc index 1bd9429..be17e37 100755 --- a/bin/hedgedoc +++ b/bin/hedgedoc @@ -70,7 +70,7 @@ Commands: history [--json] View the current logged in user's list of accessed notes. - info [--json] + info [--json] [--raw] View the metadata for a given note on the server. Config: @@ -112,6 +112,7 @@ Usage examples: \$ $SCRIPTNAME history --json \$ $SCRIPTNAME info qhmNmwmxSmK1H2oJmkKBQQ \$ $SCRIPTNAME info qhmNmwmxSmK1H2oJmkKBQQ --json + \$ $SCRIPTNAME info qhmNmwmxSmK1H2oJmkKBQQ --raw " From b537c2d580215300cbe39975cce09d6294189e3a Mon Sep 17 00:00:00 2001 From: Dark Decoy Date: Fri, 17 Mar 2023 15:23:20 +0000 Subject: [PATCH 5/5] Fixed missing then Signed-off-by: Dark Decoy --- bin/hedgedoc | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/hedgedoc b/bin/hedgedoc index be17e37..ebd23ab 100755 --- a/bin/hedgedoc +++ b/bin/hedgedoc @@ -204,6 +204,7 @@ function info_note() { "${HEDGEDOC_SERVER}/$note_id/info" elif [[ "$option" == "--raw" ]] + then response="$( curl \