added basic download capabilities

git-svn-id: http://yolanda.mister-muffin.de/svn@378 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2008-08-27 10:49:46 +00:00
parent 243cf1fa7f
commit e3c4f65849
3 changed files with 24 additions and 1 deletions

View file

@ -39,6 +39,8 @@ def make_map():
map.connect('video_page', 'video/:id/:title', controller='video', _filter=video_expand)
# map.connect('video_file', 'video/:id.ogv', controller='video', action='file' _filter=video_expand)
map.connect('download_page', 'download/:id/:title', controller='download', action="download")
# everything else
map.connect(':controller/:action/:id')
# map.connect('*url', controller='template', action='view')

View file

@ -0,0 +1,19 @@
from yolanda.lib.base import *
import paste.fileapp
import os
class DownloadFileApp(paste.fileapp.FileApp):
def __init__(self, path, filename, headers=None, **kwargs):
self.filename = path
kwargs['content-type'] = "video/ogg"
kwargs['Content-Disposition'] =' attachment; filename="'+filename+'"'
paste.fileapp.DataApp.__init__(self, None, headers, **kwargs)
class DownloadController(BaseController):
def download(self, id, title):
fapp = DownloadFileApp(
path=os.path.join(config['pylons.paths']['static_files'], "videos", id),
filename=title+".ogv")
return fapp(request.environ, self.start_response)

View file

@ -27,9 +27,11 @@ class UploadController(BaseController):
if model.Video.query.filter_by(sha256=sha256).count():
return "duplicate"
#set up database entry
video = model.Video(title=request.params['title'],sha256=sha256)
model.session.commit()
#copy file to temp destination
temp_file = open(os.path.join(config['cache.dir'], str(video.id)), 'w')
upload.file.seek(0)
u.copyfileobj(upload.file, temp_file)