示例#1
0
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)
示例#2
0
def shareFileHandler(path):
	user = validateAuth()
	if user is None:
		return redirect('/login')

	try:
		shareFile(path)
	except ValueError as exc:
		flash('Error: ', str(exc))
示例#3
0
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='')
示例#4
0
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('/')
示例#5
0
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)
示例#6
0
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)
示例#7
0
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('/')
示例#8
0
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)
示例#9
0
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)
示例#10
0
def downloadFileHandler(path):
	user = validateAuth()
	if user is None:
		return redirect('/login')

	return Response(downloadBlob(path), mimetype='application/octet-stream')
示例#11
0
def shared_files():
    user = validateAuth()
    if user is None:
        return redirect('/login')

    return None
示例#12
0
def login():
    user = validateAuth()
    if user is not None:
        return redirect('/')

    return render_template('login.html')