mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-03 19:57:29 +01:00
Add file upload for releases
This commit is contained in:
parent
5a9fc51ffc
commit
73a79d5eef
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,7 +1,7 @@
|
||||
config.cfg
|
||||
*.sqlite
|
||||
main.css
|
||||
|
||||
tmp
|
||||
|
||||
# Created by https://www.gitignore.io/api/linux,macos,python,windows
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
{% block content %}
|
||||
{% from "macros/forms.html" import render_field, render_submit_field %}
|
||||
<form method="POST" action="">
|
||||
<form method="POST" action="" enctype="multipart/form-data">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
{{ render_field(form.title) }}
|
||||
|
@ -14,11 +14,16 @@ cache = SimpleCache()
|
||||
def domain(url):
|
||||
return urlparse(url).netloc
|
||||
|
||||
# TODO: remove on production!
|
||||
# Use nginx to serve files on production instead
|
||||
@app.route("/static/<path:path>")
|
||||
def send_static(path):
|
||||
return send_from_directory("static", path)
|
||||
|
||||
@app.route("/uploads/<path:path>")
|
||||
def send_upload(path):
|
||||
import os
|
||||
return send_from_directory(os.path.abspath(app.config["UPLOAD_FOLDER"]), path)
|
||||
|
||||
@app.route("/")
|
||||
@menu.register_menu(app, ".", "Home")
|
||||
def home_page():
|
||||
|
@ -8,8 +8,12 @@ from flask_wtf import FlaskForm
|
||||
from wtforms import *
|
||||
from wtforms.validators import *
|
||||
|
||||
def isFilenameAllowed(filename, exts):
|
||||
return "." in filename and \
|
||||
filename.rsplit(".", 1)[1].lower() in exts
|
||||
|
||||
# TODO: the following could be made into one route, except I'm not sure how
|
||||
|
||||
# TODO: the following could be made into one route, except I"m not sure how
|
||||
# to do the menu
|
||||
|
||||
def doPackageList(type):
|
||||
@ -197,8 +201,10 @@ def create_release_page(type, author, name):
|
||||
return redirect(package.getDetailsURL())
|
||||
|
||||
# Initial form class from post data and default data
|
||||
form = CreatePackageReleaseForm(formdata=request.form)
|
||||
form = CreatePackageReleaseForm()
|
||||
if request.method == "POST" and form.validate():
|
||||
for key, value in request.files.items() :
|
||||
print (key, value)
|
||||
if form["uploadOpt"].data == "vcs":
|
||||
rel = PackageRelease()
|
||||
rel.package = package
|
||||
@ -206,9 +212,24 @@ def create_release_page(type, author, name):
|
||||
rel.url = form["vcsLabel"].data
|
||||
# TODO: get URL to commit from branch name
|
||||
db.session.commit()
|
||||
return redirect(package.getDetailsURL()) # redirect
|
||||
return redirect(package.getDetailsURL())
|
||||
else:
|
||||
raise Exception("Unimplemented option = file upload")
|
||||
file = form.fileUpload.data
|
||||
if not file or file.filename == "":
|
||||
flash("No selected file", "error")
|
||||
elif not isFilenameAllowed(file.filename, ["zip"]):
|
||||
flash("Please select a zip file", "error")
|
||||
else:
|
||||
import random, string, os
|
||||
filename = ''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(10)) + ".zip"
|
||||
file.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))
|
||||
|
||||
rel = PackageRelease()
|
||||
rel.package = package
|
||||
rel.title = form["title"].data
|
||||
rel.url = "/uploads/" + filename
|
||||
db.session.commit()
|
||||
return redirect(package.getDetailsURL())
|
||||
|
||||
return render_template("packages/release_new.html", package=package, form=form)
|
||||
|
||||
|
@ -7,3 +7,5 @@ SQLALCHEMY_DATABASE_URI = "sqlite:///../db.sqlite"
|
||||
|
||||
GITHUB_CLIENT_ID = ""
|
||||
GITHUB_CLIENT_SECRET = ""
|
||||
|
||||
UPLOAD_FOLDER="tmp"
|
||||
|
Loading…
Reference in New Issue
Block a user