From 1945f2e5ed537a9eb20e3e593bbf822b0e9b27c0 Mon Sep 17 00:00:00 2001 From: Ralph Thesen Date: Sat, 16 Nov 2024 22:21:05 +0100 Subject: [PATCH] feature: pasted pictures now use relative paths by default --- otterwiki/wiki.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/otterwiki/wiki.py b/otterwiki/wiki.py index dd7b3b0..7e06e4d 100644 --- a/otterwiki/wiki.py +++ b/otterwiki/wiki.py @@ -983,6 +983,7 @@ def render_attachments(self): def upload_attachments( self, files, message, filename, author, inline=False ): + last_uploaded_filename = None if not has_permission("UPLOAD"): abort(403) # attachments to commit in the second step @@ -1000,6 +1001,7 @@ def upload_attachments( os.makedirs(attachment.absdirectory, mode=0o775, exist_ok=True) upload.save(attachment.abspath) to_commit.append(attachment) + last_uploaded_filename = fn if len(to_commit) > 0: if filename is None: toastmsg = "Added attachment(s): {}.".format( @@ -1018,12 +1020,9 @@ def upload_attachments( if not inline: toast(toastmsg) if inline: - attachment_url = url_for( - "get_attachment", - pagepath=self.pagepath, - filename=fn, # pyright: ignore - ) - return jsonify(filename=attachment_url) + if last_uploaded_filename is None: + abort(500) + return jsonify(filename=f"./{last_uploaded_filename}") return redirect(url_for("attachments", pagepath=self.pagepath)) def get_attachment(self, filename, revision=None):