2009-05-13 05:34:52 +01:00
|
|
|
import fileAbstraction
|
2009-05-13 05:34:33 +01:00
|
|
|
from django.http import HttpResponse, Http404
|
2009-05-13 05:34:52 +01:00
|
|
|
|
2009-05-13 05:34:33 +01:00
|
|
|
|
|
|
|
def listdir(request, path):
|
2009-05-13 05:34:52 +01:00
|
|
|
#try:
|
|
|
|
return HttpResponse(fileAbstraction.listdir(path), mimetype = "text/plain")
|
|
|
|
#except:
|
|
|
|
# raise Http404
|
2009-05-13 05:34:33 +01:00
|
|
|
|
|
|
|
def upload(request, path):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def download(request, path):
|
2009-05-13 05:34:52 +01:00
|
|
|
#try:
|
|
|
|
return HttpResponse(fileAbstraction.readFile(path), mimetype=getMimeType(path.split(".")[-1]))
|
|
|
|
#except:
|
|
|
|
# raise Http404
|
|
|
|
|
2009-05-13 05:34:33 +01:00
|
|
|
|
|
|
|
def getMimeType(extension):
|
|
|
|
try:
|
|
|
|
return {"txt": "text/plain",
|
|
|
|
"html": "text/html",
|
|
|
|
}[extension]
|
|
|
|
except:
|
|
|
|
print "unknown file type"
|
|
|
|
return "text/plain"
|