Finish rewrite of plumber.
This commit is contained in:
parent
26469b1abd
commit
effb7907a1
48
plumber
48
plumber
@ -27,15 +27,31 @@ web_handler()
|
||||
esac
|
||||
}
|
||||
|
||||
edgecase()
|
||||
{
|
||||
err()
|
||||
{
|
||||
printf "Plumber wasn't able to find a way to handle the following URI.\n%s\nError code: %s\nProbable reason: %s\n" "${1}" "${2}" "${3}"|xmessage -file - &
|
||||
}
|
||||
|
||||
case "${2}" in
|
||||
0) set -- "${1}" "${2}" "Some other error." ;;
|
||||
1) set -- "${1}" "${2}" "It doesn't exist on the local filesystem." ;;
|
||||
esac
|
||||
|
||||
err "${@}"
|
||||
}
|
||||
|
||||
local_handler()
|
||||
{
|
||||
cleanse_prefix()
|
||||
{
|
||||
printf "%s" "$(echo "${1}" | sed -ne 's&file://&&p')"
|
||||
printf "%s" "$(printf "%s" "${1}" | sed -ne 's&file://&&p')"
|
||||
}
|
||||
|
||||
target="$(cleanse_prefix "${1}")"
|
||||
if [ -e "${target}" ]
|
||||
then
|
||||
mime="$(file --mime-type -b "${target}")"
|
||||
|
||||
case ${mime} in
|
||||
@ -45,27 +61,13 @@ local_handler()
|
||||
audio*) exec fpm "${target}" & ;;
|
||||
image*) exec iview "${target}" & ;;
|
||||
*pdf) exec gv "${target}" & ;;
|
||||
*) edgecase ;;
|
||||
*) exec exit 1 ;; #Abort. This should never be reached.
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
edgecase()
|
||||
{
|
||||
err()
|
||||
{
|
||||
printf "Plumber wasn't able to find a way to handle the following URI.\n%s\n" "${1}"
|
||||
}
|
||||
|
||||
# If first character is / or a ~ and it exists, we're dealing with local data.
|
||||
firstchar=$(echo"${1}"|cut -b1)
|
||||
if [ "${firstchar}" = '~' || "${firstchar}" = '/' ]
|
||||
then
|
||||
local_handler "${1}"
|
||||
else
|
||||
err "${1}"
|
||||
# Set the error code and throw an error.
|
||||
set -- "${1}" "1"
|
||||
edgecase "${@}"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# Commented lines will have support in the future.
|
||||
@ -75,7 +77,13 @@ case "$(printf "%s" "${1}"|cut -b 1,2,3,4)" in
|
||||
file) local_handler "${@}" ;;
|
||||
# ftp) err "${@}" ;;
|
||||
# ssh) err "${@}" ;;
|
||||
*) edgecase "${2}" ;;
|
||||
*) firstchar=$(printf "%s" "${1}"|cut -b1)
|
||||
if [ "${firstchar}" = '~' ] || [ "${firstchar}" = '/' ]
|
||||
then
|
||||
local_handler "${@}"
|
||||
else
|
||||
edgecase "${@}"
|
||||
fi
|
||||
esac
|
||||
|
||||
exit
|
||||
|
Loading…
Reference in New Issue
Block a user