From 8b6fd105f67898a516b5e21cad566950e5dac99d Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 18 Jul 2011 16:38:12 +0200 Subject: Fixed breakage caused by using wrong hash. --- fbin.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fbin.py b/fbin.py index 0a5f578..e6a11c1 100755 --- a/fbin.py +++ b/fbin.py @@ -56,6 +56,15 @@ class Application(object): return user + def get_file(self, hash): + session = db.Session() + try: + return session.query(db.File).filter(db.File.hash == hash).one() + except db.NoResultFound: + return None + finally: + session.close() + def add_file(self, path, filename, file_hash, user = None): hash = ''.join(random.choice(base62_alphabet) for x in xrange(5)) new_path = os.path.join(settings.file_directory, hash + os.path.splitext(filename)[1]) @@ -122,7 +131,7 @@ class Application(object): hash = path[1] if '.' in hash: hash = hash.split('.')[0] - file = self.get_file_by_file_hash(hash) + file = self.get_file(hash) filename = file.get_path() if filename == None: start_response('404 Not Found', [('Content-Type', 'text/html')]) @@ -311,7 +320,7 @@ class Application(object): hash = path[1] thumbfile = os.path.join(settings.thumb_directory, hash + '.jpg') if not os.access(thumbfile, os.F_OK): - file = self.get_file_by_file_hash(hash) + file = self.get_file(hash) im = Image.open(file.get_path()) im.thumbnail(settings.thumb_size, Image.ANTIALIAS) im.save(thumbfile) -- cgit v1.2.3