diff options
-rwxr-xr-x | fbin.py | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -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) |