diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-20 19:14:15 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-20 19:14:15 +0200 |
| commit | b548bf2f89e5d6f23b6ff2c4838e2f31e6010848 (patch) | |
| tree | 573d0ca483e2bae53de5a50ab6a55fdef21ba1b2 /test_status.sh | |
| download | pput-b548bf2f89e5d6f23b6ff2c4838e2f31e6010848.tar.gz pput-b548bf2f89e5d6f23b6ff2c4838e2f31e6010848.zip | |
feat: upload documents to paperless-ngx from the CLI
Single bash script over the paperless REST API. Posts each file to
/api/documents/post_document/, then polls /api/tasks/ until the document
is consumed, so each file gets a real outcome instead of a task id.
The task response needed care: it is a paginated object rather than a
bare list, statuses are lowercase, and the outcome lives in result_data
as a dict, carrying duplicate_of when paperless rejects re-uploaded
content. test_status.sh covers those shapes.
Token is read from pass, never passed as an argument. Host, pass entry
and timeout are environment-overridable.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'test_status.sh')
| -rwxr-xr-x | test_status.sh | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test_status.sh b/test_status.sh new file mode 100755 index 0000000..ae28199 --- /dev/null +++ b/test_status.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Check the task-response parser against the four shapes the API returns. +# Run: ./test_status.sh +set -euo pipefail +cd "$(dirname "$0")" + +# shellcheck disable=SC1091 +status() { sed -n '/^status()/,/^}/p' pput | sed '1d;$d' | bash -s; } + +check() { + got=$(printf '%s' "$2" | bash -c "$(sed -n '/^status()/,/^}/p' pput); status") + [ "$got" = "$(printf '%b' "$3")" ] \ + && echo "ok $1" \ + || { echo "FAIL $1: got [$got] want [$(printf '%b' "$3")]" >&2; exit 1; } +} + +check "empty results" '{"results":[]}' 'pending\t' +check "pending" '{"results":[{"status":"pending","result_data":null}]}' 'pending\t' +check "success" '{"results":[{"status":"success","result_data":{"document_id":46}}]}' 'success\tdoc 46' +check "duplicate" '{"results":[{"status":"failure","result_data":{"duplicate_of":45,"duplicate_in_trash":false}}]}' 'failure\tduplicate of doc 45' +check "dup in trash" '{"results":[{"status":"failure","result_data":{"duplicate_of":9,"duplicate_in_trash":true}}]}' 'failure\tduplicate of doc 9 (in trash)' +check "other error" '{"results":[{"status":"failure","result_data":{"error":"bad mime"}}]}' 'failure\tbad mime' +echo "all passed" |
