Function to test if argument is a remote URL
This commit is contained in:
parent
2baa5c3b74
commit
6130c3012f
|
@ -13,6 +13,7 @@ debug=true
|
|||
flag_clipboard=false
|
||||
flag_inline=false
|
||||
flag_file=false
|
||||
flag_url=false
|
||||
|
||||
null_service_url="https://null.101010.fr"
|
||||
|
||||
|
@ -43,6 +44,30 @@ is_file_exist() {
|
|||
fi
|
||||
}
|
||||
# ]]]
|
||||
# Function to check if the argument looks like a remote URL [[[
|
||||
is_remote_url() {
|
||||
_url="${1}"
|
||||
|
||||
## The variable will be considered as an URL if it's :
|
||||
## Start with 1 to 5 alpha caracters followed by "://"
|
||||
## Start with "www"
|
||||
if printf -- '%s' "${_url}" | grep -q -E -- "^([[:alpha:]]{1,5}://|www)"
|
||||
then
|
||||
### Verify doesn't already comes from the 0x0 service
|
||||
if printf -- '%s' "${_url}" | grep -q -E -- "${null_service_url}"
|
||||
then
|
||||
flag_url=true
|
||||
debug_message "− Func is_remote_url : The url (${_url}) seems to already point to the 0x0 service (${null_service_url})."
|
||||
else
|
||||
flag_url=false
|
||||
debug_message "− Func is_remote_url : The url (${_url}) seems to be a remote url."
|
||||
fi
|
||||
else
|
||||
debug_message "− Func is_remote_url : The content is not an URL."
|
||||
fi
|
||||
|
||||
}
|
||||
# ]]]
|
||||
# Function to get content type [[[
|
||||
determine_content_type() {
|
||||
_content="${1}"
|
||||
|
@ -54,8 +79,8 @@ determine_content_type() {
|
|||
if [ "${_content_nb_line}" -eq "1" ]; then
|
||||
### Verify if it's a path to a existent file
|
||||
is_file_exist "${_content}"
|
||||
### Verify it it's a remote URL
|
||||
flag_url=""
|
||||
### Verify if it's a remote URL
|
||||
is_remote_url "${_content}"
|
||||
fi
|
||||
}
|
||||
# ]]]
|
||||
|
|
Loading…
Reference in New Issue