Why Nostr? What is Njump?
2024-12-29 17:34:56
in reply to

Leonard/Janis Robert König on Nostr: nprofile1q…vss2n Finally found the culprit, the following code should work :) ``` ...

Finally found the culprit, the following code should work :)

```
#! /bin/sh

# Dependencies:
# * cURL
# * htmlq: https://github.com/mgdm/htmlq

ENDPOINT='https://flask.io';

if [ "$#" -ne 2 ]; then
printf 'newtask <flask ID> <new item name>\n' >&2
exit 1
fi

flasklist="$1"
item="$2"

cookies="/tmp/flasker_cookiejar_$flasklist.txt"
csrf_token=$(curl --silent -c "$cookies" -b "$cookies" "$ENDPOINT/$flasklist" | htmlq --attribute 'content' 'meta[name=csrf-token]')

# 1. We do want to URL-Encode the checkmark emoji
# 2. We also want to encode "$item" but the [], too, so we pre-encode it
# 3. We do want to encode "Save Task" but cURL encodes space as "+" and not %20
# so we pre-encode it and prevent re-encoding through cURL.
curl --silent \
-c "$cookies" \
-b "$cookies" \
-H "X-Csrf-Token: $csrf_token" \
--data-urlencode "utf8=✓" \
--data-urlencode "task%5Bdescription%5D=$item" \
--data-urlencode "=commit=Save%20Task" \
"$ENDPOINT/$flasklist/tasks"
```

Short explanation: You also need to send the X-Csrf-Token which we need to parse from the HTML. Also some of the data needs to be differently encoded :)
Author Public Key
npub1uf6cu9nwq4tvcrgeahfxf2mx9ppq4nxdldf22a0kmhtuk7dq2mjqmm774h