This repository has been archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from openchatai/falta/patch-ci
Falta/patch ci
- Loading branch information
Showing
12 changed files
with
202 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import json | ||
import yaml | ||
|
||
from utils.db import Database | ||
|
||
db_instance = Database() | ||
mongo = db_instance.get_db() | ||
from typing import Dict | ||
from flask import Request | ||
|
||
|
||
def add_swagger_file(request: Request, id: str) -> Dict[str, str]: | ||
if request.content_type == "application/json": | ||
# JSON file | ||
file_content = request.get_json() | ||
|
||
elif "multipart/form-data" in request.content_type: | ||
# Uploaded file | ||
file = request.files.get("file") | ||
if file is None: | ||
return {"error": "File upload is required"} | ||
|
||
if file.filename and file.filename.endswith(".json"): | ||
try: | ||
file_content = json.load(file) | ||
except json.JSONDecodeError as e: | ||
return {"error": "Invalid JSON format in uploaded file"} | ||
|
||
elif file.filename and ( | ||
file.filename.endswith(".yaml") or file.filename.endswith(".yml") | ||
): | ||
try: | ||
file_content = yaml.safe_load(file) | ||
except yaml.YAMLError as e: | ||
return {"error": "Invalid YAML format in uploaded file"} | ||
|
||
else: | ||
return {"error": "Unsupported content type"} | ||
|
||
# Insert into MongoDB | ||
file_content["bot_id"] = id | ||
mongo.swagger_files.insert_one(file_content) | ||
|
||
return {"message": "File added successfully"} |
Oops, something went wrong.