From 1d8109ca5712f7a3eccd9f1d089ee716cc64458e Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 13 Dec 2021 09:59:51 +0000 Subject: [PATCH] Allow uploading multiple artifacts at once Useful to upload both the tarball and the PGP signature at once, for instance. For some reason getlist returns a non-empty list even if the user selects no file. If the user selects one or multiple files, it behaves as expected. That's why len(file_list) isn't used for validation. --- gitsrht/blueprints/artifacts.py | 17 +++++++++-------- gitsrht/templates/ref.html | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gitsrht/blueprints/artifacts.py b/gitsrht/blueprints/artifacts.py index a5c2e79..126472b 100644 --- a/gitsrht/blueprints/artifacts.py +++ b/gitsrht/blueprints/artifacts.py @@ -38,20 +38,21 @@ def ref_upload(owner, repo, ref): else: target = tag.target.hex valid = Validation(request) - f = request.files.get("file") - valid.expect(f, "File is required", field="file") + valid.expect(request.files.get("file"), "File is required", field="file") + file_list = request.files.getlist("file") default_branch = git_repo.default_branch() if not valid.ok: return render_template("ref.html", view="refs", owner=owner, repo=repo, git_repo=git_repo, tag=tag, strip_pgp_signature=strip_pgp_signature, default_branch=default_branch, **valid.kwargs) - artifact = upload_artifact(valid, repo, target, f, f.filename) - if not valid.ok: - return render_template("ref.html", view="refs", - owner=owner, repo=repo, git_repo=git_repo, tag=tag, - strip_pgp_signature=strip_pgp_signature, - default_branch=default_branch, **valid.kwargs) + for f in file_list: + artifact = upload_artifact(valid, repo, target, f, f.filename) + if not valid.ok: + return render_template("ref.html", view="refs", + owner=owner, repo=repo, git_repo=git_repo, tag=tag, + strip_pgp_signature=strip_pgp_signature, + default_branch=default_branch, **valid.kwargs) db.session.commit() return redirect(url_for("repo.ref", owner=owner.canonical_name, diff --git a/gitsrht/templates/ref.html b/gitsrht/templates/ref.html index ff35ef2..632bf53 100644 --- a/gitsrht/templates/ref.html +++ b/gitsrht/templates/ref.html @@ -83,6 +83,7 @@ type="file" name="file" id="file" + multiple class="form-control {{valid.cls("file")}}" /> {{valid.summary("file")}} -- 2.38.4