Skip to content

Commit

Permalink
Updated help menu and example for info command
Browse files Browse the repository at this point in the history
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 <darkdecoy@notracking.space>
  • Loading branch information
Dark Decoy committed Mar 7, 2023
1 parent defeac8 commit 68a0d0f
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion bin/hedgedoc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ Commands:
history [--json]
View the current logged in user's list of accessed notes.
info <note_id> [--json]
View the metadata for a given note on the server.
Config:
Configuration is set via environment variables (e.g. in ~/.bashrc or shell).
Expand Down Expand Up @@ -107,6 +110,8 @@ Usage examples:
\$ $SCRIPTNAME profile
\$ $SCRIPTNAME history
\$ $SCRIPTNAME history --json
\$ $SCRIPTNAME info qhmNmwmxSmK1H2oJmkKBQQ
\$ $SCRIPTNAME info qhmNmwmxSmK1H2oJmkKBQQ --json
"


Expand Down Expand Up @@ -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 <note_id> [--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 <note_id> [--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:-}"

Expand Down Expand Up @@ -392,6 +466,9 @@ function main() {
echo "$help_str"
return 0
;;
info)
info_note "${1:-}" "${2:-}"
;;
import|import-as)
import_note "${1:-}" "${2:-}"
;;
Expand Down Expand Up @@ -436,4 +513,3 @@ fi
if [[ "${1:-}" != "--import" ]]; then
main "$@" || exit $?
fi

0 comments on commit 68a0d0f

Please sign in to comment.