edit txt files. keyboard shortcut for share tools

This commit is contained in:
ville rantanen
2018-07-20 21:29:11 +03:00
parent b53418b53f
commit 7d123db05f
7 changed files with 158 additions and 5 deletions

View File

@@ -14,7 +14,7 @@ from utils.utils import *
from utils.crypt import *
__FLEES_VERSION__ = "20180702.0"
__FLEES_VERSION__ = "20180720.0"
app = Flask(__name__)
app.config.from_object(__name__)
# Read config from json !
@@ -227,6 +227,85 @@ def upload_url():
return "File uploaded\n", 200
@app.route('/editor', methods = ['GET','POST'])
@app.route('/editor/<name>', methods = ['GET','POST'])
def editor(name = None):
filename = 'paste.txt'
if request.method == 'POST':
name = request.form['editor_name']
filename = request.form['editor_filename']
(ok,share) = get_share(name)
if not ok:
notify({
"share": name,
"operation": "unauthorized_editor"
})
return share
pathname = os.path.join(
share['path'],
filename
)
content = ""
if os.path.isfile(pathname):
if pathname.endswith(".txt"):
content = open(pathname, 'rt').read(10 * 1024)
return render_template(
'editor.html',
name = name,
filename = filename,
content = content
)
@app.route('/paste/<name>/<token>', methods=['POST'])
@app.route('/paste/<name>', methods=['POST'])
def paste(name = None, token = None):
if request.method == 'POST':
file = request.form['filename']
paste = request.form['paste']
if name == None:
name = request.form['name']
(ok,share) = get_share(name, token = token)
if not ok:
notify({
"share": name,
"operation": "unauthorized_paste"
})
return share
if not get_or_none('upload', share) == True:
return "Upload not allowed\n",400
if file:
filename = os.path.join(
share['path'],
secure_filename(
file
)
)
if get_or_none('overwrite', share) == False:
if os.path.exists(filename):
file_versionize(filename)
#~ return "Overwrite forbidden", 403
print_debug("Saving " + filename)
with open(filename, 'wt') as fp:
fp.write(paste)
fp.close()
set_rights(filename)
notify({
"recipient": get_or_none('recipient', share),
"share": name,
"filename": filename,
"operation": "paste"
})
if 'from_gui' in request.form:
if request.form['from_gui'] == "true":
return redirect(url_for('list_view',name=name))
return "File uploaded\n", 200
else:
return "Use the 'file' variable to paste\n",400
@app.route('/file/list/<name>/<token>', methods=['GET'])
def file_list(name, token):