shithub: rc-gemd

ref: 91805c65b6cc0db891b87d64eea1f240dae7021b
dir: /handlers/serve-static/

View raw version
#!/bin/rc
full_path=`{echo $"fs_root^$"location | urlencode -d}
full_path=$"full_path
if(! ~ `{cleanname -d$fs_root $full_path} `{cleanname $fs_root}^*){
	error 53 'path not allowed'
	exit
}

if(! test -e $full_path){
	error 51 'file does not exist'
	exit
}

if(! test -r $full_path){
	error 40 'file is not readable'
	exit
}

switch($full_path){
case *.gem *.gemini *.gmi
        type=text/gemini
case *.md
		type=text/markdown
case *.txt
        type=text/plain
case *.jpg *.jpeg
        type=image/jpeg
case *.gif
        type=image/gif
case *.png
        type=image/png
case *
        type=`{file -m $full_path}
}

echo 20' '$type^$cr
cat $full_path