def home(): user = validateAuth() if user is None: return redirect('/login') prefix = '' file_list = [] directory_list = [] try: blob_list = blobList(prefix) for i in blob_list: if user['uid'] in i.name: if i.name[len(i.name) - 1] == '/': directory_list.append(i) else: file_list.append(i) except ValueError as exc: flash('Error: ', str(exc)) return render_template('home.html', user=user, prefix=prefix, directory_list=directory_list, file_list=file_list)
def shareFileHandler(path): user = validateAuth() if user is None: return redirect('/login') try: shareFile(path) except ValueError as exc: flash('Error: ', str(exc))
def blobList(prefix): user = validateAuth() if user is None: return redirect('/login') storage_client = storage.Client(project=local_constants.PROJECT_NAME) return storage_client.list_blobs(local_constants.PROJECT_STORAGE_BUCKET, prefix=prefix, delimiter='')
def createRootHandler(): user = validateAuth() if user is None: return redirect('/login') try: root = user['uid'] + '/' addDirectory(root) except ValueError as exc: flash('Error: ', str(exc)) return redirect('/')
def createFileModel(file): user = validateAuth() if user is None: return redirect('/login') entity_key = datastore_client.key('File', user['email']) entity = datastore.Entity(key=entity_key) entity.update({ 'file_id': str(uuid.uuid4()), 'file_name': file.filename, 'file_created': datetime.datetime.utcnow(), 'file_uid': user['uid'] }) datastore_client.put(entity)
def createDirectoryModel(directory_name): user = validateAuth() if user is None: return redirect('/login') entity_key = datastore_client.key('Directory', user['email']) entity = datastore.Entity(key=entity_key) entity.update({ 'dir_id': str(uuid.uuid4()), 'dir_name': directory_name, 'dir_created': datetime.datetime.utcnow(), 'dir_user_id': user['uid'] }) datastore_client.put(entity)
def thisDirectoryHandler(path): user = validateAuth() if user is None: return redirect('/login') try: if path == '' or path[len(path) - 1] != '/': return redirect('/') thisDirectory(path) except ValueError as exc: flash('Error: ', str(exc)) return redirect('/')
def uploadFileHandler(prefix): user = validateAuth() if user is None: return redirect('/login') try: file = request.files['file_name'] if file.filename == '': return redirect('/') createFileModel(file) addFile(prefix, file) except ValueError as exc: flash('Error: ', str(exc)) return redirect('/home/'+prefix)
def addDirectoryHandler(prefix): user = validateAuth() if user is None: return redirect('/login') try: directory_name = prefix + request.form['dir_name'] if directory_name == '' or directory_name[len(directory_name) - 1] != '/': return redirect('/') createDirectoryModel(directory_name) addDirectory(directory_name) except ValueError as exc: flash('Error: ', str(exc)) return redirect('/home/'+prefix)
def downloadFileHandler(path): user = validateAuth() if user is None: return redirect('/login') return Response(downloadBlob(path), mimetype='application/octet-stream')
def shared_files(): user = validateAuth() if user is None: return redirect('/login') return None
def login(): user = validateAuth() if user is not None: return redirect('/') return render_template('login.html')