files and folders can now be created using the file browser page
This commit is contained in:
parent
80d07f140f
commit
1ceb39319f
27
app.py
27
app.py
|
|
@ -1,5 +1,5 @@
|
||||||
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
|
from flask import Flask, request, url_for, render_template, redirect, session, flash
|
||||||
from config import SETTINGS
|
from config import SETTINGS
|
||||||
import urllib
|
import urllib
|
||||||
import base64
|
import base64
|
||||||
|
|
@ -74,13 +74,32 @@ def home():
|
||||||
resp = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)))
|
resp = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)))
|
||||||
files = resp.json()
|
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')
|
@app.route('/edit')
|
||||||
def test():
|
def edit():
|
||||||
path = request.args.get('path')
|
path = request.args.get('path')
|
||||||
if not 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)))
|
resp = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)))
|
||||||
jresp = resp.json()
|
jresp = resp.json()
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
#drop-area {
|
#drop-area {
|
||||||
border: 2px dashed #ccc;
|
border: 2px dashed #ccc;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
width: 480px;
|
width: 420px;
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
margin: 100px auto;
|
margin: 50px auto;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
#drop-area.highlight {
|
#drop-area.highlight {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
{% extends "layout.html" %}
|
{% extends "layout.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% if user %}
|
{% if user %}
|
||||||
|
<div class="row">
|
||||||
<ul>
|
<ul>
|
||||||
{% for file in files %}
|
{% for file in files %}
|
||||||
{% if file.type == 'file' %}
|
{% if file.type == 'file' %}
|
||||||
|
|
@ -10,6 +11,16 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class='row'>
|
||||||
|
<div class="col-md">
|
||||||
|
<form action="/create" method="POST">
|
||||||
|
<input type="text" id='filename' name='filename'>
|
||||||
|
<input type="hidden" id='path' name='path' value="{{ path }}">
|
||||||
|
<input type="submit" value="Create new file">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
not logged in!
|
not logged in!
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
<a class="navbar-brand" href="#">rst CMS</a>
|
<a class="navbar-brand" href="/">rst CMS</a>
|
||||||
<div class="navbar-collapse collapse justify-content-between">
|
<div class="navbar-collapse collapse justify-content-between">
|
||||||
<ul class="navbar-nav mr-auto">
|
<ul class="navbar-nav mr-auto">
|
||||||
<span class="navbar-text">
|
<span class="navbar-text">
|
||||||
|
|
@ -24,12 +24,11 @@
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="navbar-nav">
|
<ul class="navbar-nav">
|
||||||
{% if user %}
|
{% if user %}
|
||||||
<span class="navbar-text">
|
<li class="nav-item nav-link">Logged in as: {{ user.username }} <img width='30px' src='{{ user.avatar_url }}'></li>
|
||||||
Logged in as: {{ user.username }} <span><img width='50px' src='{{ user.avatar_url }}'></span> <a class="nav-link" href="/logout">Logout</a>
|
<li class="nav-item"> <a class="nav-link" href="/logout">Logout</a></li>
|
||||||
</span>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="navbar-text">
|
<span class="navbar-text">
|
||||||
<a href="/login">login</a>
|
<li class="nav-item"><a href="/login">login</a></li>
|
||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
@ -38,7 +37,18 @@
|
||||||
|
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
<div id="content">{% block content %}{% endblock %}</div>
|
<div id='messages'>
|
||||||
|
{% with messages = get_flashed_messages() %}
|
||||||
|
{% if messages %}
|
||||||
|
<ul class=flashes>
|
||||||
|
{% for message in messages %}
|
||||||
|
<li>{{ message }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
{% endwith %}
|
||||||
|
</div>
|
||||||
|
<div id="content" class="container-fluid">{% block content %}{% endblock %}</div>
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
{% 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>.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue