added basic download capabilities
git-svn-id: http://yolanda.mister-muffin.de/svn@378 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
parent
243cf1fa7f
commit
e3c4f65849
3 changed files with 24 additions and 1 deletions
|
@ -38,7 +38,9 @@ def make_map():
|
||||||
|
|
||||||
map.connect('video_page', 'video/:id/:title', controller='video', _filter=video_expand)
|
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('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
|
# everything else
|
||||||
map.connect(':controller/:action/:id')
|
map.connect(':controller/:action/:id')
|
||||||
# map.connect('*url', controller='template', action='view')
|
# map.connect('*url', controller='template', action='view')
|
||||||
|
|
19
trunk/yolanda/controllers/download.py
Normal file
19
trunk/yolanda/controllers/download.py
Normal 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)
|
|
@ -27,9 +27,11 @@ class UploadController(BaseController):
|
||||||
if model.Video.query.filter_by(sha256=sha256).count():
|
if model.Video.query.filter_by(sha256=sha256).count():
|
||||||
return "duplicate"
|
return "duplicate"
|
||||||
|
|
||||||
|
#set up database entry
|
||||||
video = model.Video(title=request.params['title'],sha256=sha256)
|
video = model.Video(title=request.params['title'],sha256=sha256)
|
||||||
model.session.commit()
|
model.session.commit()
|
||||||
|
|
||||||
|
#copy file to temp destination
|
||||||
temp_file = open(os.path.join(config['cache.dir'], str(video.id)), 'w')
|
temp_file = open(os.path.join(config['cache.dir'], str(video.id)), 'w')
|
||||||
upload.file.seek(0)
|
upload.file.seek(0)
|
||||||
u.copyfileobj(upload.file, temp_file)
|
u.copyfileobj(upload.file, temp_file)
|
||||||
|
|
Loading…
Reference in a new issue