Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added getting metadata from a note id #54

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 81 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] [--raw]
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,9 @@ Usage examples:
\$ $SCRIPTNAME profile
\$ $SCRIPTNAME history
\$ $SCRIPTNAME history --json
\$ $SCRIPTNAME info qhmNmwmxSmK1H2oJmkKBQQ
\$ $SCRIPTNAME info qhmNmwmxSmK1H2oJmkKBQQ --json
\$ $SCRIPTNAME info qhmNmwmxSmK1H2oJmkKBQQ --raw
"


Expand Down Expand Up @@ -177,6 +183,78 @@ function import_note() {
echo "$note_id"
}

function info_note() {
local note_id="$1"
local option="$2"

if [[ ! "$note_id" ]]; then
echo "Error: You must specify a note id to retrieve metadata from the server." >&2
echo "" >&2
echo "Usage: $SCRIPTNAME info <note_id> [--json]" >&2
echo "For usage exmaples, see: $SCRIPTNAME help" >&2
return 2
fi

if [[ "$option" == "--json" ]]
then

curl \
--silent \
--cookie "$HEDGEDOC_COOKIES_FILE" \
"${HEDGEDOC_SERVER}/$note_id/info"

elif [[ "$option" == "--raw" ]]
darkdecoy marked this conversation as resolved.
Show resolved Hide resolved
then

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[@]}
ErikMichelson marked this conversation as resolved.
Show resolved Hide resolved

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

}

function export_note() {
local export_type="${1#--}" note_id="${2:-}" output_path="${3:-}"

Expand Down Expand Up @@ -392,6 +470,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 +517,3 @@ fi
if [[ "${1:-}" != "--import" ]]; then
main "$@" || exit $?
fi