Skip to content

Commit

Permalink
add way to list user's files
Browse files Browse the repository at this point in the history
  • Loading branch information
zhemao committed Apr 28, 2012
1 parent 07d5a42 commit 7b62f65
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@
*.pyo
*.swp
*.pem
*.egg-info
16 changes: 12 additions & 4 deletions wsgi/routes.py
Expand Up @@ -66,8 +66,7 @@ def upload_file():
return json_success()
return json_error('database error', 500)

else:
return json_error('not authenticated', 401)
return json_error('not authenticated', 401)

@app.route('/file/download/<filename>')
def download_file(filename):
Expand All @@ -81,6 +80,15 @@ def download_file(filename):
'X-Symmetric-Key': aes_key}

return f.read(), 200, headers
else:
return json_error('not authenticated', 401)

return json_error('not authenticated', 401)

@app.route('/file/list')
def file_list():
username = current_user(app, request.cookies)
if username:
files = list_files(mongo.db, username)
return json_result({'result': 'success', 'files': files})

return json_error('not authenticated', 401)

15 changes: 15 additions & 0 deletions wsgi/storage.py
Expand Up @@ -35,3 +35,18 @@ def find_file(db, username, filename):
return gfs.get(finfo['file_id']), finfo['aes_key']

return None

def list_files(db, username):
files = db.fileinfo.group(['filename'], {'username': username},
{'date': datetime(1970, 1, 1)},
'''
function(obj, prev){
if(obj.date > prev){
prev.datae = obj.date;
prev.filename = obj.filename;
prev.aes_key = obj.aes_key;
}
}
''')

return [f for f in files]

0 comments on commit 7b62f65

Please sign in to comment.