fix(inst): fixed folder path for instructions

This commit is contained in:
FrederikBaerentsen
2025-12-05 22:38:38 +01:00
parent 00ca611217
commit 85728e2d68
2 changed files with 18 additions and 9 deletions

View File

@@ -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:

View File

@@ -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)