mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-04 14:15:59 +00:00
Add skip-duplicates to the request in ds.sh
This commit is contained in:
parent
6a63694a3e
commit
70b5625c48
34
tools/ds.sh
34
tools/ds.sh
@ -34,7 +34,7 @@ if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
OPTIONS=c:hsde
|
OPTIONS=c:hsde
|
||||||
LONGOPTS=config:,help,skip,delete,exists
|
LONGOPTS=config:,help,skip,delete,exists,allow-duplicates
|
||||||
|
|
||||||
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
|
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
|
||||||
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
|
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
|
||||||
@ -46,7 +46,7 @@ fi
|
|||||||
# read getopt’s output this way to handle the quoting right:
|
# read getopt’s output this way to handle the quoting right:
|
||||||
eval set -- "$PARSED"
|
eval set -- "$PARSED"
|
||||||
|
|
||||||
exists=n delete=n help=n config="${XDG_CONFIG_HOME:-$HOME/.config}/docspell/ds.conf"
|
exists=n delete=n help=n config="${XDG_CONFIG_HOME:-$HOME/.config}/docspell/ds.conf" dupes=n
|
||||||
while true; do
|
while true; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h|--help)
|
-h|--help)
|
||||||
@ -65,6 +65,10 @@ while true; do
|
|||||||
exists=y
|
exists=y
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--allow-duplicates)
|
||||||
|
dupes=y
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
break
|
break
|
||||||
@ -93,7 +97,16 @@ checkFile() {
|
|||||||
|
|
||||||
upload_file() {
|
upload_file() {
|
||||||
tf=$($MKTEMP_CMD) rc=0
|
tf=$($MKTEMP_CMD) rc=0
|
||||||
$CURL_CMD -# -o "$tf" --stderr "$tf" -w "%{http_code}" -XPOST -F file=@"$1" "$2" | (2>&1 1>/dev/null grep 200)
|
META1=""
|
||||||
|
META2=""
|
||||||
|
if [ "$dupes" = "y" ]; then
|
||||||
|
META1="-F"
|
||||||
|
META2="meta={\"multiple\": false, \"skipDuplicates\": false}"
|
||||||
|
else
|
||||||
|
META1="-F"
|
||||||
|
META2="meta={\"multiple\": false, \"skipDuplicates\": true}"
|
||||||
|
fi
|
||||||
|
$CURL_CMD -# -o "$tf" --stderr "$tf" -w "%{http_code}" -XPOST $META1 "$META2" -F file=@"$1" "$2" | (2>&1 1>/dev/null grep 200)
|
||||||
rc=$(expr $rc + $?)
|
rc=$(expr $rc + $?)
|
||||||
cat $tf | (2>&1 1>/dev/null grep '{"success":true')
|
cat $tf | (2>&1 1>/dev/null grep '{"success":true')
|
||||||
rc=$(expr $rc + $?)
|
rc=$(expr $rc + $?)
|
||||||
@ -110,12 +123,16 @@ upload_file() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
upload() {
|
upload() {
|
||||||
checkFile "$2" "$1"
|
if [ "$dupes" == "y" ]; then
|
||||||
if [ $? -eq 0 ]; then
|
|
||||||
info "File already exists at url $2"
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
upload_file "$1" "$2"
|
upload_file "$1" "$2"
|
||||||
|
else
|
||||||
|
checkFile "$2" "$1"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
info "File already exists at url $2"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
upload_file "$1" "$2"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +146,7 @@ showUsage() {
|
|||||||
info " -d | --delete Delete the files when successfully uploaded (value: $delete)"
|
info " -d | --delete Delete the files when successfully uploaded (value: $delete)"
|
||||||
info " -h | --help Prints this help text. (value: $help)"
|
info " -h | --help Prints this help text. (value: $help)"
|
||||||
info " -e | --exists Checks for the existence of a file instead of uploading (value: $exists)"
|
info " -e | --exists Checks for the existence of a file instead of uploading (value: $exists)"
|
||||||
|
info " --allow-duplicates Do not skip existing files in docspell (value: $dupes)"
|
||||||
info ""
|
info ""
|
||||||
info "Arguments:"
|
info "Arguments:"
|
||||||
info " One or more files to check for existence or upload."
|
info " One or more files to check for existence or upload."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user