diff --git a/app.py b/app.py index 41dce1b..6d79399 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ from authlib.integrations.flask_client import OAuth, token_update, OAuthError from flask import Flask, request, url_for, render_template, redirect, session, flash +from jinja2 import escape from config import SETTINGS import urllib import base64 @@ -117,7 +118,7 @@ def update(): sample = { "branch": "master", "content": "", - "sha": "c7ef6a89fe8b888ad897479ac592f1e4841e4f18", + "sha": "", "message": "Web API Update"} content = request.form.get('content') content = base64.b64encode(content.encode('UTF-8')) @@ -125,11 +126,18 @@ def update(): path = request.form.get('path') sample['content'] = content.decode('UTF-8') sample['sha'] = sha - - resp = oauth.gitea.request('PUT', urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)), data=json.dumps(sample), headers={'Content-type': 'application/json'}) - print(resp) - - return str(resp) + check = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path))) + check = check.json() + if sha == check['sha']: + resp = oauth.gitea.request('PUT', urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)), data=json.dumps(sample), headers={'Content-type': 'application/json'}) + return redirect('/') + else: + print('file changed on server!') + filecontent_remote = check['content'] + filecontent_local = sample['content'] + sha_remote = check['sha'] + user = session.get('user') + return render_template('diff.html', filecontent_local=filecontent_local, path=path, filecontent_remote=filecontent_remote, sha_remote=sha_remote, user=user) @app.route('/upload', methods=['POST']) def upload(): diff --git a/templates/layout.html b/templates/layout.html index 665a526..1d32732 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -11,6 +11,7 @@ {% block title %}{% endblock %} {% endblock %} + {% block header_addition %}{% endblock %}
{% block content %}{% endblock %}
-