diff --git a/app.py b/app.py index 3b1bd24..fee3b98 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,5 @@ from authlib.integrations.flask_client import OAuth, token_update, OAuthError -from flask import Flask, request, url_for, render_template, redirect, session +from flask import Flask, request, url_for, render_template, redirect, session, flash from config import SETTINGS import urllib import base64 @@ -74,13 +74,32 @@ def home(): resp = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path))) files = resp.json() - return render_template('home.html', user=user, files=files) + return render_template('home.html', user=user, files=files, path=path) + +@app.route('/create', methods=['POST']) +def create(): + path = request.form.get('path') + filename = request.form.get('filename') + if not path: + flash('No path given') + redirect(request.referrer) + if not filename: + flash('no filename given') + redirect(request.referrer) + + payload = {"content": "", "message": "WEB API file created"} + path = path+"/"+filename + resp = oauth.gitea.request('POST', urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)), data=json.dumps(payload), headers={'Content-type': 'application/json'}) + return redirect('/edit?path='+path) + + @app.route('/edit') -def test(): +def edit(): path = request.args.get('path') if not path: - return 'no path given' + flash('no path given') + redirect(request.referrer) resp = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path))) jresp = resp.json() diff --git a/static/style.css b/static/style.css index 49a429c..ac3d7b7 100644 --- a/static/style.css +++ b/static/style.css @@ -1,9 +1,9 @@ #drop-area { border: 2px dashed #ccc; border-radius: 20px; - width: 480px; + width: 420px; font-family: sans-serif; - margin: 100px auto; + margin: 50px auto; padding: 20px; } #drop-area.highlight { diff --git a/templates/home.html b/templates/home.html index 40724a2..003c64f 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,6 +1,7 @@ {% extends "layout.html" %} {% block content %} {% if user %} +
+
+
+
+
+ + + +
+
+
{% else %} not logged in! diff --git a/templates/layout.html b/templates/layout.html index d361c22..665a526 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -15,7 +15,7 @@ -
{% block content %}{% endblock %}
+
+ {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %} +
+
{% block content %}{% endblock %}