Commit 152169ba authored by charitha.p's avatar charitha.p

changes in to 1.1

parent 9ef99b14
......@@ -5,7 +5,7 @@ class _Service(BaseSettings):
HOST: str = Field(default="0.0.0.0", env="service_host")
PORT: int = Field(default=9192, env="service_port")
BUILD_DIR: str = Field(default="scripts/templates")
PROXY: str = Field(default="gateway/plugin/<gen-proxy>")
PROXY: str = Field(default="gateway/plugin/deval")
BACKEND_DIR: str = Field(default=".")
......
import json
import logging
import os
from fastapi.responses import FileResponse
from scripts.config import Service, PathToDir
from scripts.core.schemas.response_models import DefaultSuccessResponse,DefaultResponse
from scripts.core.schemas.response_models import LoadStylesResponse
class DefaultHandler:
@staticmethod
def load_styles():
try:
response = LoadStylesResponse()
for each_file in os.listdir(Service.BUILD_DIR):
path = f"{Service.PROXY}/widget/load_file?filename={each_file}"
if each_file.endswith(".js"):
response.js_files.append(path)
elif each_file.endswith(".css"):
response.styles.append(path)
elif each_file == "assets":
response.assetPath = f"{Service.PROXY}/assets"
return DefaultSuccessResponse(message="Styles loaded successfully", data=response)
except Exception as e:
logging.exception(e)
return DefaultResponse(message="Failed to load file paths", status="failed")
@staticmethod
def download_resources(filename: str):
try:
file_path = os.path.join(Service.BUILD_DIR, filename)
if os.path.isfile(os.path.join(Service.BUILD_DIR, filename)) and filename.endswith(".js"):
return FileResponse(file_path, media_type='application/octet-stream', filename=filename)
else:
return DefaultResponse(message="Failed to load resources")
except Exception as e:
logging.error("Exception " + str(e))
return DefaultResponse(message="Filename is not available")
@staticmethod
def load_configuration():
try:
with open(f"{PathToDir.ASSETS}/widgetConfig.json", "r") as file:
file_content = json.loads(file.read())
return file_content
except Exception as e:
logging.error(e)
return DefaultResponse(message="Failed to load configurations")
\ No newline at end of file
from fastapi import APIRouter
from scripts.api import EndPoints
from scripts.core.handlers.defaults import DefaultHandler
router = APIRouter(prefix="/widget")
handler = DefaultHandler
@router.get(EndPoints.load_styles)
async def load_styles():
"""
Default: Loads required endpoints to get filenames in the build
Do not edit this
"""
return handler.load_styles()
@router.get(EndPoints.load_file)
def download_resource(filename: str):
"""Default: Request Build Files to redner widget configurations on the frontend
Do not edit this
"""
return handler.download_resources(filename)
# TODO: Add preview logic. Do not change the API endpoint
@router.get(EndPoints.load_configuration)
async def load_configuration():
"""
Default: Load widget configuration JSON for listing plugins while creating widgets
Do not edit this
"""
return handler.load_configuration()
\ No newline at end of file
......@@ -73,7 +73,7 @@ async def preview(request_type: str = "refresh"):
if request_type not in ["refresh", "preview"]:
return DefaultResponse(message="Invalid Query Parameter")
# Route to Handler for Processing Chart json
return {}
return {"Hello World"}
except Exception as e:
logging.error(e)
return DefaultResponse(message="Not found")
......@@ -5,5 +5,5 @@
"branch": "master",
"environment_variables": {
},
"version": "1.0"
"version": "1.1"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment