]> Sergey Matveev's repositories - sfloader.git/commitdiff
Initial commit master
authorSergey Matveev <stargrave@stargrave.org>
Sat, 18 Mar 2023 08:26:58 +0000 (11:26 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 18 Mar 2023 08:40:11 +0000 (11:40 +0300)
README [new file with mode: 0644]
sf-dl [new file with mode: 0755]
sf-ul [new file with mode: 0755]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..cf98ea8
--- /dev/null
+++ b/README
@@ -0,0 +1,2 @@
+Seafile (https://www.seafile.com/en/home/) download/upload utilities.
+API was taken from https://github.com/seafile-data/seafile-web-api-manual.
diff --git a/sf-dl b/sf-dl
new file mode 100755 (executable)
index 0000000..ec486aa
--- /dev/null
+++ b/sf-dl
@@ -0,0 +1,3 @@
+#!/bin/sh -e
+
+${CURL:-curl} -s "$1" | sed -n 's#\\u002D#-#g ; s/^.*rawPath: .\(.*\).,$/\1/p'
diff --git a/sf-ul b/sf-ul
new file mode 100755 (executable)
index 0000000..e317053
--- /dev/null
+++ b/sf-ul
@@ -0,0 +1,39 @@
+#!/bin/sh -ex
+
+SRV=${SRV:-cloud.seafile.com}
+CURL=${CURL:-curl}
+JQ=${JQ:-gojq}
+JO=${JO:-gjo}
+
+fn="$1"
+[ -n "$fn" ]
+
+auth=`grep "machine $SRV" ${NETRC:-$HOME/.netrc}`
+[ -n "$auth" ]
+auth_name=`echo $auth | sed 's/^.*login \([^ ]*\).*$/\1/'`
+auth_pass=`echo $auth | sed 's/^.*password \([^ ]*\).*$/\1/'`
+
+SRV="https://$SRV"
+CURL="$CURL --fail"
+JQ="$JQ --raw-output"
+
+token=$($CURL --silent --data "username=${auth_name}&password=${auth_pass}" \
+    $SRV/api2/auth-token/ | $JQ .token)
+[ -n "$token" ]
+repoId=$($CURL --silent --header "Authorization: Token $token" \
+    $SRV/api2/default-repo/ | $JQ .repo_id)
+[ -n "$repoId" ]
+uploadLink=$($CURL --silent --header "Authorization: Token $token" \
+    $SRV/api2/repos/${repoId}/upload-link/ | $JQ .)
+[ -n "$uploadLink" ]
+fileId=$($CURL --progress-bar --header "Authorization: Token $token" \
+    --form file=@${fn} --form parent_dir=/ $uploadLink)
+[ -n "$fileId" ]
+fn="$(basename "$fn")"
+req=$($JO repo_id=$repoId "path=/$fn" permissions="$($JO can_edit=false can_download=true)")
+$CURL --silent --header "Authorization: Token $token" \
+    --header "Content-type: application/json" --data "$req" \
+    $SRV/api/v2.1/share-links/ | $JQ .link
+
+# $CURL -H "Authorization: Token $token" -X DELETE "$SRV/api/v2.1/share-links/LINK/"
+# $CURL -H "Authorization: Token $token" -X DELETE "$SRV/api2/repos/$repoId/file/?p=/$fn