Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 0.0
os: linux
files:
- source: /index.html
destination: /var/www/html/
hooks:
BeforeInstall:
- location: scripts/install_dependencies
timeout: 300
runas: root
- location: scripts/start_server
timeout: 300
runas: root
ApplicationStop:
- location: scripts/stop_server
timeout: 300
runas: root

10 changes: 7 additions & 3 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from filesystem import Folder, File
from action import *
from flask import request
from os import error

from flask import send_file
#from os import error
app = Flask(__name__)
app.config.update(
DEBUG=True,
Expand All @@ -25,7 +25,11 @@ def index(path=''):
context = my_file.apply_action(View)
folder = Folder(app.config['FILES_ROOT'], my_file.get_path())
if context == None:
return render_template('file_unreadable.html', folder=folder)

raw_file = my_file.path

return send_file(raw_file)

return render_template('file_view.html', text=context['text'], file=my_file, folder=folder)

@app.route('/search', methods=['POST'])
Expand Down
55 changes: 55 additions & 0 deletions manager.py~
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
import os
from flask import Flask, render_template, redirect, request
from filesystem import Folder, File
from action import *
from flask import request
from os import error

app = Flask(__name__)
app.config.update(
DEBUG=True,
FILES_ROOT=os.path.dirname(os.path.abspath(__file__)),
)

@app.route('/')
@app.route('/files/<path:path>')
def index(path=''):
path_join = os.path.join(app.config['FILES_ROOT'], path)
if os.path.isdir(path_join):
folder = Folder(app.config['FILES_ROOT'], path)
folder.read()
return render_template('folder.html', folder=folder)
else:
my_file = File(app.config['FILES_ROOT'], path)
context = my_file.apply_action(View)
folder = Folder(app.config['FILES_ROOT'], my_file.get_path())
if context == None:

raw_file = my_file.path

return send_file(raw_file)

return render_template('file_view.html', text=context['text'], file=my_file, folder=folder)

@app.route('/search', methods=['POST'])
def search():
q = request.form['q']
return render_template('search.html', request = q)

@app.route('/new_directory', methods=["POST"])
@app.route('/<path:path>/new_directory', methods=["POST"])
def create_directory(path = "/"):
dirname = request.form["new_directory_name"]
directory_root = request.form["directory_root"]
full_path = os.path.join(directory_root, dirname)
try:
os.mkdir(full_path)
except error:
pass
return redirect('/files/' + directory_root)



if __name__ == '__main__':
app.run(host="0.0.0.0")
Binary file not shown.
Binary file added test_files/aman.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_files/archi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions test_files/archi.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_files/dream_career.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_files/fv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added test_files/hello.mp3
Empty file.
Binary file added test_files/honey1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading