Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added app/media/MyHelm_zip.zip
Binary file not shown.
46 changes: 20 additions & 26 deletions app/routes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,33 @@
from fastapi import FastAPI, HTTPException,Response
from fastapi.responses import FileResponse
import os
import zipfile


@app.get("/download-helm/{filename}")
def download_file_helm(filename: str):
def zip_folder(folder_path: str, output_zip_path: str):
"""Zip the entire folder."""
with zipfile.ZipFile(output_zip_path, 'w', zipfile.ZIP_DEFLATED) as zip_file:
for root, dirs, files in os.walk(folder_path):
for file in files:
file_path = os.path.join(root, file)
# Add file to the zip file
zip_file.write(file_path, os.path.relpath(file_path, folder_path))

folder = 'app/media/MyHelm'
file_path = os.path.join(folder, filename)

if not os.path.isfile(file_path):
raise HTTPException(status_code=404, detail="File not found.")


return FileResponse(file_path, media_type='application/octet-stream', filename=filename)


@app.get("/download-terraform/{filename}")
def download_file_terraform(filename: str):
@app.get("/download-folder{folder_name}")
async def download_folder_MyHelm(folder_name: str):
folder_path = f"app/media/{folder_name}" # Adjust the path as needed
if not os.path.exists(folder_path):
raise HTTPException(status_code=404, detail="Folder not found")

folder = 'app/media/MyTerraform'
file_path = os.path.join(folder, filename)

if not os.path.isfile(file_path):
raise HTTPException(status_code=404, detail="File not found.")
zip_file_path = f"app/media/{folder_name}_zip.zip"


return FileResponse(file_path, media_type='application/octet-stream', filename=filename)
# Zip the folder
zip_folder(folder_path, zip_file_path)

# Return the zip file as a response
return FileResponse(zip_file_path, media_type='application/zip', filename=f"app/media{folder_name}_zip.zip")

@app.get("/list-directory")
def list_directory(folder: str):
# Ensure the folder exists
if not os.path.isdir(folder):
raise HTTPException(status_code=404, detail=f"{folder} does not exist.")

# List the contents of the directory
contents = os.listdir(folder)
return {"folder": folder, "contents": contents}
Loading