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 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
|
||||
import urllib
|
||||
import base64
|
||||
|
|
@ -74,13 +74,32 @@ def home():
|
|||
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)
|
||||
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')
|
||||
def test():
|
||||
def edit():
|
||||
path = request.args.get('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)))
|
||||
jresp = resp.json()
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#drop-area {
|
||||
border: 2px dashed #ccc;
|
||||
border-radius: 20px;
|
||||
width: 480px;
|
||||
width: 420px;
|
||||
font-family: sans-serif;
|
||||
margin: 100px auto;
|
||||
margin: 50px auto;
|
||||
padding: 20px;
|
||||
}
|
||||
#drop-area.highlight {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
{% if user %}
|
||||
<div class="row">
|
||||
<ul>
|
||||
{% for file in files %}
|
||||
{% if file.type == 'file' %}
|
||||
|
|
@ -10,6 +11,16 @@
|
|||
{% endif %}
|
||||
{% endfor %}
|
||||
</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 %}
|
||||
not logged in!
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
<body>
|
||||
<div id="header">
|
||||
<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">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<span class="navbar-text">
|
||||
|
|
@ -24,12 +24,11 @@
|
|||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
{% if user %}
|
||||
<span class="navbar-text">
|
||||
Logged in as: {{ user.username }} <span><img width='50px' src='{{ user.avatar_url }}'></span> <a class="nav-link" href="/logout">Logout</a>
|
||||
</span>
|
||||
<li class="nav-item nav-link">Logged in as: {{ user.username }} <img width='30px' src='{{ user.avatar_url }}'></li>
|
||||
<li class="nav-item"> <a class="nav-link" href="/logout">Logout</a></li>
|
||||
{% else %}
|
||||
<span class="navbar-text">
|
||||
<a href="/login">login</a>
|
||||
<li class="nav-item"><a href="/login">login</a></li>
|
||||
</span>
|
||||
{% endif %}
|
||||
|
||||
|
|
@ -38,7 +37,18 @@
|
|||
|
||||
</nav>
|
||||
</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">
|
||||
{% 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>.
|
||||
|
|
|
|||
Loading…
Reference in New Issue