Added file checks.

This commit is contained in:
Fabian Schlenz 2018-11-07 15:33:35 +01:00
parent 4e2e81ec91
commit fe274fd5ce
1 changed files with 16 additions and 0 deletions

View File

@ -139,6 +139,19 @@ function log {
[ "$DEBUG" = true ] && echo "DEBUG: $1"
}
function check_file {
if [ ! -e "$1" ]; then
echo "The file $1 does not exist."
exit 1
fi
size=$(stat -c%s "$1")
if (( size > 52428800 )); then
echo "File $1 is breaking the file size limit imposed on Telegram bots (currently 50MB)."
exit 1
fi
}
function escapeMarkdown {
res="${1//\*/}"
res="${res//_/_}"
@ -317,10 +330,13 @@ if [ -n "$DOCUMENT_FILE" ] && [ -n "$IMAGE_FILE" ]; then
fi
if [ -n "$DOCUMENT_FILE" ]; then
check_file "$DOCUMENT_FILE"
CURL_OPTIONS="$CURL_OPTIONS --form document=@$DOCUMENT_FILE"
CURL_OPTIONS="$CURL_OPTIONS --form caption=<-"
METHOD="sendDocument"
elif [ -n "$IMAGE_FILE" ]; then
check_file "$IMAGE_FILE"
CURL_OPTIONS="$CURL_OPTIONS --form photo=@$IMAGE_FILE"
CURL_OPTIONS="$CURL_OPTIONS --form caption=<-"
METHOD="sendPhoto"