From 751ade153d6f2bb6e073ac8c51f1846851c5b45c Mon Sep 17 00:00:00 2001 From: limwz01 <117669574+limwz01@users.noreply.github.com> Date: Tue, 9 Jan 2024 15:33:25 +0800 Subject: [PATCH] allow attachment download from slackdump standard export --- slackviewer/app.py | 22 ++++++++++++++++++++++ slackviewer/main.py | 1 + 2 files changed, 23 insertions(+) diff --git a/slackviewer/app.py b/slackviewer/app.py index a9b59a7..0b12e6e 100644 --- a/slackviewer/app.py +++ b/slackviewer/app.py @@ -1,3 +1,5 @@ +import os + import flask @@ -26,6 +28,11 @@ def channel_name(name): no_external_references=app.no_external_references) +@app.route("/channel//attachments/") +def channel_name_attachment(name, attachment): + return flask.send_file(os.path.join(flask._app_ctx_stack.path, name, "attachments", attachment)) + + @app.route("/group//") def group_name(name): messages = flask._app_ctx_stack.groups[name] @@ -44,6 +51,11 @@ def group_name(name): no_external_references=app.no_external_references) +@app.route("/group//attachments/") +def group_name_attachment(name, attachment): + return flask.send_file(os.path.join(flask._app_ctx_stack.path, name, "attachments", attachment)) + + @app.route("/dm//") def dm_id(id): messages = flask._app_ctx_stack.dms[id] @@ -62,6 +74,11 @@ def dm_id(id): no_external_references=app.no_external_references) +@app.route("/dm//attachments/") +def dm_name_attachment(name, attachment): + return flask.send_file(os.path.join(flask._app_ctx_stack.path, name, "attachments", attachment)) + + @app.route("/mpim//") def mpim_name(name): messages = flask._app_ctx_stack.mpims.get(name, list()) @@ -80,6 +97,11 @@ def mpim_name(name): no_external_references=app.no_external_references) +@app.route("/mpim//attachments/") +def mpim_name_attachment(name, attachment): + return flask.send_file(os.path.join(flask._app_ctx_stack.path, name, "attachments", attachment)) + + @app.route("/") def index(): channels = list(flask._app_ctx_stack.channels.keys()) diff --git a/slackviewer/main.py b/slackviewer/main.py index f39d0de..e29f911 100644 --- a/slackviewer/main.py +++ b/slackviewer/main.py @@ -22,6 +22,7 @@ def configure_app(app, archive, channels, no_sidebar, no_external_references, de reader = Reader(path) top = flask._app_ctx_stack + top.path = path top.channels = reader.compile_channels(channels) top.groups = reader.compile_groups() top.dms = reader.compile_dm_messages()