Simply auto upload logic base on Pull request #214 (#217)

* Simply auto upload logic base on Pull request #214

* No bash debugging

* Minor refactor

* Update logic to handle single file or folder
This commit is contained in:
2022-06-24 22:51:50 +10:00
committed by GitHub
parent 2196929d63
commit 654f8f4b3d
2 changed files with 26 additions and 31 deletions
+2
View File
@@ -148,9 +148,11 @@ Then simply run `docker-compose up -d`, that's it!
|`/app/conf/aria2.conf` | See description above👆🏼 |
|`/app/conf/aria2.session` | See description above👆🏼 |
|`/app/conf/rclone.conf` | See description above👆🏼 |
| `/app/conf/auto-upload.sh` | The bash script to be used for uploading downloaded files to remote storage provider via Rclone, mount your own script if you want to have custom logic. |
| `/app/filebrowser.db` | File Browser settings database, make sure you make a empty file first on your host. |
| `/app/.cache` | The folder for storing rclone caches and [aria2 DHT files](https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-dht-file-path) |
## Auto HTTPS enabling
Make sure you have added proper `A` record point to the host you running to your domain `DNS` record list, then just add `e` option to bind the `https` domain when you run the image
+24 -31
View File
@@ -1,42 +1,35 @@
#!/bin/bash -eu
RCLONE_AUTO_UPLOAD_PROVIDER=google-drive
if [[ $RCLONE_AUTO_UPLOAD_PROVIDER == "" ]]; then
if [[ ${RCLONE_AUTO_UPLOAD_PROVIDER} == "" ]]; then
echo "[INFO] $(date -u +'%Y-%m-%dT%H:%M:%SZ') Auto upload isn't enabled"
exit 0
fi
if [ $2 -eq 0 ]; then
echo "[WARN] $(date -u +'%Y-%m-%dT%H:%M:%SZ') No files detected"
file_count=$2
file_path=$3
downloadsFolder='/data'
if [ ${file_count} -eq 0 ]; then
echo "[WARN] $(date -u +'%Y-%m-%dT%H:%M:%SZ') No files detected. Original parameters: Files Count: ${file_count}, Files Path: ${file_path}"
exit 0
fi
echo "[INFO] $(date -u +'%Y-%m-%dT%H:%M:%SZ') Start to upload files with: Files Count: [$2], Files Path: [$3]"
echo "[INFO] $(date -u +'%Y-%m-%dT%H:%M:%SZ') Start to upload files with: Files Count: ${file_count}, Files Path: ${file_path}"
path=$3 # File full path
downloadpath='/data' # Aria2 downloading folder
provider_name=$RCLONE_AUTO_UPLOAD_PROVIDER # RClone remote provider
folder=$RCLONE_AUTO_UPLOAD_REMOTE_PATH # Foler path in Rclone remote provider
MinSize=$RCLONE_AUTO_UPLOAD_FILE_MIN_SIZE # Set mininum file size to be uploaded, files smaller than this will be deleted without uploading
MaxSize=$RCLONE_AUTO_UPLOAD_FILE_MAX_SIZE # Set the Max file size to be uploaded
folder=${file_path%/*}
while true; do #提取下载文件根路径,如把/data/a/b/c/d.jpg变成/data/a
file_path=$path
path=${path%/*}
if [ "$path" == "" ]; then #不在下载文件夹
exit 0
elif [ "$path" == "$downloadpath" ] && [ $2 -eq 1 ]; then # To handle single file
rclone move "$file_path" ${provider_name}:${folder}/
echo "[INFO] $(date -u +'%Y-%m-%dT%H:%M:%SZ') Successfully uploaded file $file_path"
exit 0
elif [ "$path" == "$downloadpath" ]; then # To handle folder
while [[ "$(ls -A "$file_path/")" != "" ]]; do
rclone move "$file_path"/ ${provider_name}:${folder}/"${file_path##*/}"/ --delete-empty-src-dirs --min-size $MinSize --max-size $MaxSize
echo "[INFO] $(date -u +'%Y-%m-%dT%H:%M:%SZ') Successfully uploaded file $file_path"
rclone delete -v "$file_path" --max-size $MinSize # Delete files smaller than min file.
done
rm -rf "$file_path/"
exit 0
if [ "${folder}" == "" ]; then # Not the actual file, or no files downloaded.
echo "[WARN] $(date -u +'%Y-%m-%dT%H:%M:%SZ') Fail to find files ${file_path}"
exit 0
else
if [[ "$(ls -A "$folder/")" != "" ]] && [[ ${folder} != ${downloadsFolder} ]] ; then
# Copy files to remote
echo "[INFO] $(date -u +'%Y-%m-%dT%H:%M:%SZ') Start uploading entire folder ${folder}"
rclone copy "${folder}" ${RCLONE_AUTO_UPLOAD_PROVIDER}:${RCLONE_AUTO_UPLOAD_REMOTE_PATH}${folder}/ --min-size ${RCLONE_AUTO_UPLOAD_FILE_MIN_SIZE} --max-size ${RCLONE_AUTO_UPLOAD_FILE_MAX_SIZE} -P
else
#Handle single file
echo "[INFO] $(date -u +'%Y-%m-%dT%H:%M:%SZ') Start uploading file file_path"
rclone copy "${file_path}" ${RCLONE_AUTO_UPLOAD_PROVIDER}:${RCLONE_AUTO_UPLOAD_REMOTE_PATH}${folder}/ --min-size ${RCLONE_AUTO_UPLOAD_FILE_MIN_SIZE} --max-size ${RCLONE_AUTO_UPLOAD_FILE_MAX_SIZE} -P
fi
done
echo "[INFO] $(date -u +'%Y-%m-%dT%H:%M:%SZ') Successfully uploaded ${file_count} files ${file_path}"
fi