You can include commands, in some parts of your scope.sh
, to check for file size.
First, add new function (paste code above handle_extension()
in scope.sh
):
drop_bigsize() {
# 51200 == 50 MB * 1024
# change this number for different sizes
if [[ `du "${FILE_PATH}" | cut -f1` -gt 51200 ]]; then
echo '----- TOO BIG FILE -----'
exit 0
fi
}
Second, call that function somewhere in scope.sh
.
For example, the code below will prevent from previewing any files with size bigger than 50MB (its the last few lines from scope.sh
):
...
MIMETYPE="$( file --dereference --brief --mime-type -- "${FILE_PATH}" )"
### start of new block ###
drop_bigsize
### end of new block ###
if [[ "${PV_IMAGE_ENABLED}" == 'True' ]]; then
handle_image "${MIMETYPE}"
fi
handle_extension
handle_mime "${MIMETYPE}"
handle_fallback
exit 1
To do such stuff with some specific file types, e.g. for some archives, you would need to place the same block of code in different part of your scope.sh
:
...
handle_extension() {
case "${FILE_EXTENSION_LOWER}" in
# Archive
a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|\
rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)
### start of new block ###
drop_bigsize
### end of new block ###
atool --list -- "${FILE_PATH}" && exit 5
bsdtar --list --file "${FILE_PATH}" && exit 5
exit 1;;
rar)
# Avoid password prompt by providing empty password
unrar lt -p- -- "${FILE_PATH}" && exit 5
exit 1;;
...