This commit is contained in:
Matthias Seidl 2020-11-24 23:12:33 +01:00
parent 77f75c895d
commit 60929bb19c
2 changed files with 16 additions and 7 deletions

18
app.py
View File

@ -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
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'})
print(resp)
return str(resp)
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():

View File

@ -11,6 +11,7 @@
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
<title>{% block title %}{% endblock %}</title>
{% endblock %}
{% block header_addition %}{% endblock %}
</head>
<body>
<div id="header">
@ -49,7 +50,7 @@
{% endwith %}
</div>
<div id="content" class="container-fluid">{% block content %}{% endblock %}</div>
<div id="footer">
<div id="footer" class="mt-auto">
{% block footer %}
powered by <a href=''>gitea</a> &amp; <a href=''>flask</a> / themed with <a href="">bootstrap</a> &copy; Copyright 2020 by <a href="https://seidlm.at/">Matthias Seidl</a>.
{% endblock %}