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

Meta command added #530

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Declare files that will always have LF line endings on checkout.
*.sh text eol=lf
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ LABEL maintainer="[email protected]"
RUN apk add --no-cache bash curl
COPY / /opt/dropbox_uploader
RUN mkdir -p /config && mkdir -p /workdir
RUN apk --no-cache add zip
# for zip file testing
RUN apk --no-cache add p7zip

VOLUME /config /workdir

Expand Down
3 changes: 3 additions & 0 deletions Dockerfile.pi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ MAINTAINER [email protected]
RUN apk update && apk add bash curl
COPY *.sh /opt/dropbox_uploader/
RUN mkdir -p /config && mkdir -p /workdir
RUN apk --no-cache add zip
# for zip file testing
RUN apk --no-cache add p7zip

VOLUME /config /workdir

Expand Down
15 changes: 15 additions & 0 deletions Dockerfile.pi64
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM arm64v8/alpine:3.13
MAINTAINER [email protected]

RUN apk add --no-cache bash curl
COPY / /opt/dropbox_uploader
RUN mkdir -p /config && mkdir -p /workdir
RUN apk --no-cache add zip
# for zip file testing
RUN apk --no-cache add p7zip

VOLUME /config /workdir

WORKDIR /workdir

ENTRYPOINT ["/opt/dropbox_uploader/dropbox_uploader.sh", "-f", "/config/dropbox_uploader.conf"]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ Download a file from an URL to a Dropbox folder directly (the file is NOT downlo
* **search** <QUERY>
Search for a specific pattern on Dropbox and returns the list of matching files or directories

* **meta** <REMOTE_FILE>
Get metadata of provided file. Prints Lastmodfied date/time and size in bytes. Not valid for folders

* **info**
Print some info about your Dropbox account

Expand Down Expand Up @@ -146,6 +149,7 @@ Ignores/excludes directories or files from syncing.
./dropbox_uploader.sh download /backup.zip
./dropbox_uploader.sh delete /backup.zip
./dropbox_uploader.sh mkdir /myDir/
./dropbox_uploader.sh meta /path/to/remotefile.zip
./dropbox_uploader.sh upload "My File.txt" "My File 2.txt"
./dropbox_uploader.sh share "My File.txt"
./dropbox_uploader.sh list
Expand All @@ -158,6 +162,7 @@ Ignores/excludes directories or files from syncing.
* MacOSX
* Windows/Cygwin
* Raspberry Pi
* Raspberry Pi 4 (64-bit Debian OS)
* QNAP
* iOS
* OpenWRT
Expand Down Expand Up @@ -260,6 +265,9 @@ Using the script with docker makes it also possible to run the script even on wi

To use a proxy, just set the mentioned environment variables via the docker `-e` parameter.

### Prebuilt containers
* Rpi4 (ARM/v8) [ARM/V8 Dropbox Uploader on Dockerhub](https://hub.docker.com/layers/ummarbhutta/dropboxuploader/1.1-armv8/images/sha256-16312dea974c08ada6c47156c13b5f09ffb8f2293f787a543269398daa11a396?context=explore)

## Related projects
[thunar-dropbox](https://github.com/mDfRg/Thunar-Dropbox-Uploader-plugin/tree/thunar-dropbox/plugins/thunar): A simple extension to Dropbox Uploader that provides a convenient method to share your Dropbox files with one click!

Expand Down
53 changes: 52 additions & 1 deletion dropbox_uploader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ CHUNK_FILE="$TMP_DIR/du_chunk_$RANDOM"
TEMP_FILE="$TMP_DIR/du_tmp_$RANDOM"
AUTH_ACCESS_TOKEN_EXPIRE="0"
BIN_DEPS="sed basename date grep stat dd mkdir"
VERSION="1.0"
VERSION="1.1"

umask 077

Expand Down Expand Up @@ -275,6 +275,7 @@ function usage
echo -e "\t share <REMOTE_FILE>"
echo -e "\t saveurl <URL> <REMOTE_DIR>"
echo -e "\t search <QUERY>"
echo -e "\t meta <REMOTE_FILE>"
echo -e "\t info"
echo -e "\t space"
echo -e "\t unlink"
Expand Down Expand Up @@ -1013,6 +1014,44 @@ function db_account_space
fi
}

#Get metadata of file
#$1 Source path (File)
#Returns Lastmodified(DateTime) and Size
function db_getmeta
{
local SRC=$(normalize_path "$1")

print "Dropbox Uploader v$VERSION\n\n"
print " > Getting meta data for $SRC\n\n"

$CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST -L -s --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Content-Type: application/json" --data "{\"path\": \"$SRC\",\"include_media_info\": false,\"include_deleted\": false,\"include_has_explicit_shared_members\": false}" "$API_METADATA_URL" 2> /dev/null
check_http_response

#Check
if grep -q "^HTTP/[12].* 200" "$RESPONSE_FILE"; then

type=$(sed -n 's/{".tag": *"*\([^"]*\)"*.*/\1/p' "$RESPONSE_FILE")


if [[ $type = "file" ]]; then

client_modified=$(sed -n 's/.* "server_modified": *"\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z\)".*/\1/p' "$RESPONSE_FILE")
echo -e "LastModified:\t$client_modified"

size=$(sed -n 's/.*"size": *\([0-9]*\).*/\1/p' "$RESPONSE_FILE")
echo -e "Size:\t$size"
else
print "FAILED: Only files are supported.\n"
ERROR_STATUS=1
fi

else
print "FAILED\n"
ERROR_STATUS=1
fi

}

#Account unlink
function db_unlink
{
Expand Down Expand Up @@ -1813,6 +1852,18 @@ case $COMMAND in

;;

meta)

if [[ $argnum -lt 1 ]]; then
usage
fi

FILE_SRC="$ARG1"

db_getmeta "/$FILE_SRC"

;;

*)

if [[ $COMMAND != "" ]]; then
Expand Down