diff --git a/app.py b/app.py
index 947634a..3b1bd24 100644
--- a/app.py
+++ b/app.py
@@ -5,6 +5,7 @@ import urllib
import base64
import hashlib
import json
+import os
def fetch_token(name):
return session['token']
@@ -69,8 +70,10 @@ def home():
path = request.args.get('path')
if not path:
path = '/'
- resp = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)))
- files = resp.json()
+ if user:
+ 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)
@app.route('/edit')
@@ -112,11 +115,14 @@ def update():
@app.route('/upload', methods=['POST'])
def upload():
file = request.files
+ path = request.form.get('path')
+ head, tail = os.path.split(path)
+ path = head + '/' + file['file'].filename
image_string = base64.b64encode(file['file'].read())
payload = {"content": "", "message": "WEB API add file"}
payload['content'] = image_string.decode('UTF-8')
- resp = oauth.gitea.request('POST', urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), 'static/test.png')), data=json.dumps(payload), headers={'Content-type': 'application/json'})
- print(resp.json())
+ 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 'OK'
if __name__ == "__main__":
diff --git a/static/upload.js b/static/upload.js
index bb73fc1..6d757ac 100644
--- a/static/upload.js
+++ b/static/upload.js
@@ -49,6 +49,7 @@ function uploadFile(file) {
let formData = new FormData()
formData.append('file', file)
+ formData.append('path', document.getElementById('path').value)
fetch(url, {
method: 'POST',
diff --git a/templates/home.html b/templates/home.html
index 3add2e8..40724a2 100644
--- a/templates/home.html
+++ b/templates/home.html
@@ -12,6 +12,6 @@
{% else %}
-login
+not logged in!
{% endif %}
{% endblock %}
diff --git a/templates/layout.html b/templates/layout.html
index 1cdd693..d361c22 100644
--- a/templates/layout.html
+++ b/templates/layout.html
@@ -27,7 +27,12 @@
Logged in as: {{ user.username }}
Logout
+ {% else %}
+
+ login
+
{% endif %}
+