From 85728e2d68bb783e2ca6a0c1dec61383b950a501 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Fri, 5 Dec 2025 22:38:38 +0100 Subject: [PATCH] fix(inst): fixed folder path for instructions --- bricktracker/instructions.py | 14 ++++++++++---- bricktracker/instructions_list.py | 13 ++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/bricktracker/instructions.py b/bricktracker/instructions.py index 317bf37..3f9ff4e 100644 --- a/bricktracker/instructions.py +++ b/bricktracker/instructions.py @@ -230,10 +230,16 @@ class BrickInstructions(object): folder: str = current_app.config['INSTRUCTIONS_FOLDER'] - # Compute the path - path = os.path.join(folder, self.filename) - - return url_for('static', filename=path) + # Determine which route to use based on folder path + # If folder contains 'data' (new structure), use data route + # Otherwise use static route (legacy) + if 'data' in folder: + return url_for('data.serve_data_file', folder='instructions', filename=self.filename) + else: + # Legacy: folder is relative to static/ + folder_clean = folder.removeprefix('static/') + path = os.path.join(folder_clean, self.filename) + return url_for('static', filename=path) # Return the icon depending on the extension def icon(self, /) -> str: diff --git a/bricktracker/instructions_list.py b/bricktracker/instructions_list.py index 6fc364d..259d1d7 100644 --- a/bricktracker/instructions_list.py +++ b/bricktracker/instructions_list.py @@ -36,11 +36,14 @@ class BrickInstructionsList(object): # Try to list the files in the instruction folder try: - # Make a folder relative to static - folder: str = os.path.join( - current_app.static_folder, # type: ignore - current_app.config['INSTRUCTIONS_FOLDER'], - ) + folder_config: str = current_app.config['INSTRUCTIONS_FOLDER'] + + # If folder is absolute, use it directly + # Otherwise, make it relative to app root (not static folder) + if os.path.isabs(folder_config): + folder = folder_config + else: + folder = os.path.join(current_app.root_path, folder_config) for file in os.scandir(folder): instruction = BrickInstructions(file)