fixes 3
This commit is contained in:
parent
77f75c895d
commit
60929bb19c
20
app.py
20
app.py
|
|
@ -1,5 +1,6 @@
|
||||||
from authlib.integrations.flask_client import OAuth, token_update, OAuthError
|
from authlib.integrations.flask_client import OAuth, token_update, OAuthError
|
||||||
from flask import Flask, request, url_for, render_template, redirect, session, flash
|
from flask import Flask, request, url_for, render_template, redirect, session, flash
|
||||||
|
from jinja2 import escape
|
||||||
from config import SETTINGS
|
from config import SETTINGS
|
||||||
import urllib
|
import urllib
|
||||||
import base64
|
import base64
|
||||||
|
|
@ -117,7 +118,7 @@ def update():
|
||||||
sample = {
|
sample = {
|
||||||
"branch": "master",
|
"branch": "master",
|
||||||
"content": "",
|
"content": "",
|
||||||
"sha": "c7ef6a89fe8b888ad897479ac592f1e4841e4f18",
|
"sha": "",
|
||||||
"message": "Web API Update"}
|
"message": "Web API Update"}
|
||||||
content = request.form.get('content')
|
content = request.form.get('content')
|
||||||
content = base64.b64encode(content.encode('UTF-8'))
|
content = base64.b64encode(content.encode('UTF-8'))
|
||||||
|
|
@ -125,11 +126,18 @@ def update():
|
||||||
path = request.form.get('path')
|
path = request.form.get('path')
|
||||||
sample['content'] = content.decode('UTF-8')
|
sample['content'] = content.decode('UTF-8')
|
||||||
sample['sha'] = sha
|
sample['sha'] = sha
|
||||||
|
check = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)))
|
||||||
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'})
|
check = check.json()
|
||||||
print(resp)
|
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 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'])
|
@app.route('/upload', methods=['POST'])
|
||||||
def upload():
|
def upload():
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
|
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='style.css') }}">
|
||||||
<title>{% block title %}{% endblock %}</title>
|
<title>{% block title %}{% endblock %}</title>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
{% block header_addition %}{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="header">
|
<div id="header">
|
||||||
|
|
@ -49,7 +50,7 @@
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
</div>
|
</div>
|
||||||
<div id="content" class="container-fluid">{% block content %}{% endblock %}</div>
|
<div id="content" class="container-fluid">{% block content %}{% endblock %}</div>
|
||||||
<div id="footer">
|
<div id="footer" class="mt-auto">
|
||||||
{% block footer %}
|
{% block footer %}
|
||||||
powered by <a href=''>gitea</a> & <a href=''>flask</a> / themed with <a href="">bootstrap</a> © Copyright 2020 by <a href="https://seidlm.at/">Matthias Seidl</a>.
|
powered by <a href=''>gitea</a> & <a href=''>flask</a> / themed with <a href="">bootstrap</a> © Copyright 2020 by <a href="https://seidlm.at/">Matthias Seidl</a>.
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue