From 0ad49bfed63e7de0c50402daa63934db5660a354 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 23 Feb 2024 20:07:40 +0000 Subject: [PATCH] nopaste: Bring back the upload page Signed-off-by: Michael Tremer --- src/templates/nopaste/create.html | 4 +- src/templates/nopaste/upload.html | 82 +++++++++++++++++++++++++++++++ src/web/__init__.py | 3 ++ src/web/nopaste.py | 24 +++++++++ 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 src/templates/nopaste/upload.html diff --git a/src/templates/nopaste/create.html b/src/templates/nopaste/create.html index 334b0d83..7cafb5cb 100644 --- a/src/templates/nopaste/create.html +++ b/src/templates/nopaste/create.html @@ -53,8 +53,8 @@
-
diff --git a/src/templates/nopaste/upload.html b/src/templates/nopaste/upload.html new file mode 100644 index 00000000..f953bfc9 --- /dev/null +++ b/src/templates/nopaste/upload.html @@ -0,0 +1,82 @@ +{% extends "../base.html" %} + +{% block title %}{{ _("Upload File") }}{% end block %} + +{% block container %} +
+
+
+

{{ _("Upload File") }}

+
+
+
+ +
+
+
+
+
+ {% raw xsrf_form_html() %} + +
+ + +
+
+ +
+
+
+ +
+ + +
+ +
+
+ +
+ + +
+
+ +
+
+
+ +
+
+ +
+
+
+
+
+
+
+{% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 0ea16fcd..52aab699 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -330,6 +330,9 @@ class Application(tornado.web.Application): # nopaste.ipfire.org self.add_handlers(r"nopaste\.([a-z]+\.dev\.)?ipfire\.org", [ (r"/", nopaste.CreateHandler), + (r"/upload", nopaste.UploadHandler), + + # View (r"/raw/(.*)", nopaste.RawHandler), (r"/view/(.*)", nopaste.ViewHandler), diff --git a/src/web/nopaste.py b/src/web/nopaste.py index 910d5364..f643813e 100644 --- a/src/web/nopaste.py +++ b/src/web/nopaste.py @@ -68,6 +68,30 @@ class CreateHandler(base.AnalyticsMixin, base.BaseHandler): self.finish() +class UploadHandler(base.AnalyticsMixin, base.BaseHandler): + @tornado.web.authenticated + def get(self): + self.render("nopaste/upload.html") + + @tornado.web.authenticated + def post(self): + subject = self.get_argument("subject", None) + + # Fetch expires time + expires = self.get_argument_int("expires", "0") + + with self.db.transaction(): + for f in self.request.files.get("file"): + paste = self.backend.nopaste.create(f.body, subject=subject, expires=expires, + account=self.current_user, address=self.get_remote_ip()) + + # Only accept one file + break + + # Redirect to the paste + return self.redirect("/view/%s" % paste.uuid) + + class RawHandler(base.AnalyticsMixin, base.BaseHandler): def get(self, uid): with self.db.transaction(): -- 2.47.2