41 lines
1.2 KiB
Django/Jinja
Executable File
41 lines
1.2 KiB
Django/Jinja
Executable File
#!/usr/bin/env bash
|
|
# $1: file to upload
|
|
|
|
BASE_URL=https://www.mediafire.com/api
|
|
TOKEN_FILE=/var/lib/motion/token
|
|
LOGIN='{{motion_cloud_login}}'
|
|
PASSWORD='{{motion_cloud_password}}'
|
|
|
|
# Plowshare App ID & API key
|
|
APP_ID={{motion_cloud_id}}
|
|
API_KEY='{{motion_cloud_key}}'
|
|
|
|
token="$(find "$TOKEN_FILE" -mmin -9 -exec cat {} \; 2>/dev/null)"
|
|
set -e
|
|
|
|
f="$1"
|
|
file_size="$(stat -L --printf=%s "$f")"
|
|
file_name="$(basename "$f")"
|
|
|
|
if [ -z "$token" ]; then
|
|
token_json="$(curl \
|
|
-d "email=$LOGIN" --data-urlencode "password=$PASSWORD" \
|
|
-d "application_id=$APP_ID" \
|
|
-d "signature=$(printf '%s' "$LOGIN$PASSWORD$APP_ID$API_KEY" | sha1sum | head -c40)" \
|
|
-d 'version=1' -d 'response_format=json' \
|
|
"$BASE_URL/user/get_session_token.php" \
|
|
| tr -d '\r\n ')"
|
|
|
|
grep -qF '"result":"Success"' <<<"$token_json"
|
|
|
|
token="$(sed -rn 's/.*"session_token":"(([^"]|\\")*)".*/\1/p' <<<"$token_json" \
|
|
| sed 's/\\\(.\)/\1/g')"
|
|
|
|
printf '%s' "$token" >"$TOKEN_FILE"
|
|
fi
|
|
|
|
curl \
|
|
-F "Filedata=@$f;filename=$file_name" \
|
|
-H "x-filename: $file_name" -H "x-filesize: $file_size" \
|
|
"$BASE_URL/upload/simple.php?session_token=${token}&path=/Camera&action_on_duplicate=keep&response_format=json"
|