about summary refs log tree commit diff
path: root/bundles/immich/files/immich-api-tool
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/immich/files/immich-api-tool')
-rwxr-xr-xbundles/immich/files/immich-api-tool49
1 files changed, 49 insertions, 0 deletions
diff --git a/bundles/immich/files/immich-api-tool b/bundles/immich/files/immich-api-tool
new file mode 100755
index 0000000..d0a1a41
--- /dev/null
+++ b/bundles/immich/files/immich-api-tool
@@ -0,0 +1,49 @@
+#!/bin/sh
+set -eu
+
+API_URL=https://photos.gzr.im/api
+API_KEY=zaJUJGHpFqY9OA6kAhuauTj9tC1YVfA8umtZc6ls8U
+
+request() {
+  ENDPOINT=${1:?}
+  shift 1
+
+  curl -sSfL "${API_URL}${ENDPOINT}" \
+    -H "x-api-key: $API_KEY" \
+    -H 'Content-Type: application/json' \
+    "$@"
+}
+
+validateAccessToken() {
+  request '/auth/validateToken' -X POST >/dev/null
+}
+
+# returns full json response
+searchFavorites() {
+  request '/search/metadata' \
+    -H 'Accept: application/json' \
+    -d '{"isFavorite": true}'
+}
+
+# requires '{"assetIds":["list","of","ids",...]}' on stdin
+# downloads to PWD
+downloadArchive() {
+  request '/download/archive' \
+    -H 'Accept: application/octet-stream' \
+    -d @- \
+    -o "archive.zip" \
+    --no-silent
+}
+
+main() {
+  validateAccessToken || exit 1
+
+  # download favorites as archive
+  searchFavorites |
+    jq '[.assets.items[].id] | {assetIds:.}' -rc |
+    downloadArchive
+}
+
+test -n "${DEBUG:-}" && set -x
+main
+exit 0