simple repo browser added
This commit is contained in:
parent
f945c858da
commit
31a98e2817
27
app.py
27
app.py
|
|
@ -65,15 +65,21 @@ def logout():
|
|||
@app.route('/')
|
||||
def home():
|
||||
user = session.get('user')
|
||||
return render_template('home.html', user=user)
|
||||
files = {}
|
||||
path = request.args.get('path')
|
||||
if not path:
|
||||
path = '/'
|
||||
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)
|
||||
|
||||
@app.route('/test')
|
||||
@app.route('/edit')
|
||||
def test():
|
||||
path = request.args.get('path')
|
||||
if not path:
|
||||
return 'no path given'
|
||||
|
||||
resp = oauth.gitea.get(urllib.parse.quote('repos/seidl/rstcms/contents/{}'.format(path)))
|
||||
resp = oauth.gitea.get(urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), path)))
|
||||
jresp = resp.json()
|
||||
if 'errors' in jresp:
|
||||
error = {}
|
||||
|
|
@ -81,7 +87,8 @@ def test():
|
|||
return render_template('error.html', error=error)
|
||||
content = base64.b64decode(jresp['content']).decode('UTF-8')
|
||||
sha = jresp['sha']
|
||||
return render_template('test.html',filecontent=content,sha=sha,path=path)
|
||||
user = session.get('user')
|
||||
return render_template('edit.html',filecontent=content,sha=sha,path=path, user=user)
|
||||
|
||||
@app.route('/update', methods=['POST'])
|
||||
def update():
|
||||
|
|
@ -97,11 +104,21 @@ def update():
|
|||
sample['content'] = content.decode('UTF-8')
|
||||
sample['sha'] = sha
|
||||
|
||||
resp = oauth.gitea.request('PUT', 'repos/seidl/rstcms/contents/{}'.format(path), data=json.dumps(sample), headers={'Content-type': 'application/json'})
|
||||
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)
|
||||
|
||||
@app.route('/upload', methods=['POST'])
|
||||
def upload():
|
||||
file = request.files
|
||||
image_string = base64.b64encode(file['file'].read())
|
||||
payload = {"content": "", "message": "WEB API add file"}
|
||||
payload['content'] = image_string.decode('UTF-8')
|
||||
resp = oauth.gitea.request('POST', urllib.parse.quote('{}/contents/{}'.format(app.config.get('REPO_URL'), 'static/test.png')), data=json.dumps(payload), headers={'Content-type': 'application/json'})
|
||||
print(resp.json())
|
||||
return 'OK'
|
||||
|
||||
if __name__ == "__main__":
|
||||
gitea = oauth.create_client('gitea')
|
||||
app.run(debug=True)
|
||||
|
|
|
|||
|
|
@ -7,28 +7,28 @@ let progressBar = document.getElementById('progress-bar')
|
|||
dropArea.addEventListener(eventName, preventDefaults, false)
|
||||
})
|
||||
|
||||
function preventDefaults (e) {
|
||||
function preventDefaults (e) {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
}
|
||||
}
|
||||
|
||||
;['dragenter', 'dragover'].forEach(eventName => {
|
||||
;['dragenter', 'dragover'].forEach(eventName => {
|
||||
dropArea.addEventListener(eventName, highlight, false)
|
||||
})
|
||||
|
||||
;['dragleave', 'drop'].forEach(eventName => {
|
||||
;['dragleave', 'drop'].forEach(eventName => {
|
||||
dropArea.addEventListener(eventName, unhighlight, false)
|
||||
})
|
||||
|
||||
function highlight(e) {
|
||||
function highlight(e) {
|
||||
dropArea.classList.add('highlight')
|
||||
}
|
||||
}
|
||||
|
||||
function unhighlight(e) {
|
||||
function unhighlight(e) {
|
||||
dropArea.classList.remove('highlight')
|
||||
}
|
||||
}
|
||||
|
||||
dropArea.addEventListener('drop', handleDrop, false)
|
||||
dropArea.addEventListener('drop', handleDrop, false)
|
||||
|
||||
function handleDrop(e) {
|
||||
let dt = e.dataTransfer
|
||||
|
|
@ -42,9 +42,10 @@ function handleFiles(files) {
|
|||
initializeProgress(files.length)
|
||||
files.forEach(uploadFile)
|
||||
files.forEach(previewFile)
|
||||
}
|
||||
function uploadFile(file) {
|
||||
let url = 'YOUR URL HERE'
|
||||
}
|
||||
|
||||
function uploadFile(file) {
|
||||
let url = '/upload'
|
||||
let formData = new FormData()
|
||||
|
||||
formData.append('file', file)
|
||||
|
|
@ -55,9 +56,9 @@ function handleFiles(files) {
|
|||
})
|
||||
.then(progressDone) // <- Add `progressDone` call here
|
||||
.catch(() => { /* Error. Inform the user */ })
|
||||
}
|
||||
}
|
||||
|
||||
function previewFile(file) {
|
||||
function previewFile(file) {
|
||||
let reader = new FileReader()
|
||||
reader.readAsDataURL(file)
|
||||
reader.onloadend = function() {
|
||||
|
|
@ -71,15 +72,15 @@ function handleFiles(files) {
|
|||
caption.textContent = file.name
|
||||
document.getElementById(file.name).appendChild(caption)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initializeProgress(numfiles) {
|
||||
function initializeProgress(numfiles) {
|
||||
progressBar.value = 0
|
||||
filesDone = 0
|
||||
filesToDo = numfiles
|
||||
}
|
||||
}
|
||||
|
||||
function progressDone() {
|
||||
function progressDone() {
|
||||
filesDone++
|
||||
progressBar.value = filesDone / filesToDo * 100
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
<div class="row">
|
||||
<div class="col-md">
|
||||
<form action='/update' method='POST'>
|
||||
<textarea rows = "30" cols = "120" name = "content" id="content">
|
||||
{% if filecontent %}
|
||||
{{ filecontent }}
|
||||
<textarea rows = "30" cols = "120" name = "content" id="content">{% if filecontent %}{{ filecontent }}
|
||||
{% endif %}
|
||||
</textarea><br>
|
||||
<input type='hidden' id='sha' name='sha' value="{{ sha }}">
|
||||
|
|
@ -17,13 +15,13 @@
|
|||
<div class='col-md'>
|
||||
<div id="drop-area">
|
||||
<form class="my-form">
|
||||
<p>Upload multiple files with the file dialog or by dragging and dropping images onto the dashed region</p>
|
||||
<p>Upload multiple files with the file dialog or by dragging and dropping images onto the dashed region. Files are automatically uploaded to git!</p>
|
||||
<input type="file" id="fileElem" multiple accept="image/*" onchange="handleFiles(this.files)">
|
||||
<label class="button" for="fileElem">Select some files</label>
|
||||
</form>
|
||||
<progress id="progress-bar" max=100 value=0></progress>
|
||||
<div id="gallery"></div>
|
||||
</div>
|
||||
<div id="gallery"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,13 +1,16 @@
|
|||
{% extends "layout.html" %}
|
||||
{% block content %}
|
||||
{% if user %}
|
||||
<div>
|
||||
Logged in as
|
||||
<span><img src='{{ user.avatar_url }}'></span>
|
||||
<span>{{ user.username }}</span>
|
||||
</div>
|
||||
<a href="/test">test</a>
|
||||
<a href="/logout">logout</a>
|
||||
<ul>
|
||||
{% for file in files %}
|
||||
{% if file.type == 'file' %}
|
||||
<li><a href="/edit?path={{ file.path }}">{{ file.name }}</a></li>
|
||||
{% else %}
|
||||
<li><a href="/?path={{ file.path }}">{{ file.name }}/</a></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% else %}
|
||||
<a href="/login">login</a>
|
||||
{% endif %}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,30 @@
|
|||
{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<div id="header">
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<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">
|
||||
a no bs CMS
|
||||
</span>
|
||||
</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>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
<div id="content">{% block content %}{% endblock %}</div>
|
||||
<div id="footer">
|
||||
{% block footer %}
|
||||
© 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 %}
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Reference in New Issue