fixed bugs and tested major functions
This commit is contained in:
parent
ae7f1494be
commit
c33700fa66
@ -2,7 +2,7 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
from .app_settings import app_settings
|
||||
|
||||
class LogSettings():
|
||||
class LogSettings(BaseSettings):
|
||||
LOG_LEVEL: str = "DEBUG"
|
||||
LOG_BASE_PATH: str = app_settings.LOG_BASE_PATH
|
||||
LOG_PATH: str = LOG_BASE_PATH + '/' + app_settings.BACKEND_LOG_FILE_NAME + '.log'
|
||||
|
||||
@ -10,7 +10,7 @@ export APPLICATION_ACTIVITY_LOG=$APP_NAME-activity
|
||||
export MONGODB_NAME=freeleaps2
|
||||
export MONGODB_PORT=27017
|
||||
GIT_REPO_ROOT=/mnt/freeleaps/freeleaps-service-hub
|
||||
CODEBASE_ROOT=/mnt/freeleaps/freeleaps-service-hub/app/central_storage
|
||||
CODEBASE_ROOT=/mnt/freeleaps/freeleaps-service-hub/apps/central_storage
|
||||
SITE_DEPLOY_FOLDER=/mnt/freeleaps/freeleaps-service-hub/sites/central_storage/deploy
|
||||
#!/bin/bash
|
||||
export VENV_DIR=venv_t
|
||||
@ -21,4 +21,5 @@ export DOCKER_BACKEND_HOME=$DOCKER_APP_HOME/$APP_NAME
|
||||
export DOCKER_BACKEND_LOG_HOME=$DOCKER_BACKEND_HOME/log
|
||||
export MONGODB_URI=mongodb://localhost:27017/
|
||||
export FREELEAPS_ENV=local
|
||||
export LOG_BASE_PATH=${CODEBASE_ROOT}/log
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
from .app_settings import app_settings
|
||||
|
||||
class LogSettings():
|
||||
class LogSettings(BaseSettings):
|
||||
LOG_LEVEL: str = "DEBUG"
|
||||
LOG_BASE_PATH: str = app_settings.LOG_BASE_PATH
|
||||
LOG_PATH: str = LOG_BASE_PATH + '/' + app_settings.BACKEND_LOG_FILE_NAME + '.log'
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
from fastapi import APIRouter
|
||||
from .retrieve_document_info import router as ri_router
|
||||
from .upload_document import router as ud_router
|
||||
from .upload_file import router as ud_router
|
||||
from .read_document_as_http_media import router as rd_router
|
||||
|
||||
api_router = APIRouter()
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
from fastapi import APIRouter, UploadFile, File, Form, HTTPException
|
||||
from fastapi import APIRouter, Depends
|
||||
from starlette.status import HTTP_401_UNAUTHORIZED
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.responses import JSONResponse
|
||||
from backend.application.document_hub import DocumentHub
|
||||
from pydantic import BaseModel
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
associated_with: str
|
||||
name: str
|
||||
blob: bytes
|
||||
|
||||
|
||||
@router.post(
|
||||
"/upload-document",
|
||||
summary="upload a document with a given associated_with id, document name and document data.",
|
||||
description="upload a document. If success, returning the document id",
|
||||
)
|
||||
async def upload_document(item: Item):
|
||||
|
||||
document_hub = DocumentHub()
|
||||
# File processing
|
||||
try:
|
||||
document_id = await document_hub.upload_document(
|
||||
item.associated_with, item.name, item.blob
|
||||
)
|
||||
|
||||
if document_id:
|
||||
result = {"document_id": str(document_id)}
|
||||
return JSONResponse(content=jsonable_encoder(result))
|
||||
else:
|
||||
return JSONResponse(
|
||||
status_code=500, content={"error": "Document upload failed"}
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return JSONResponse(status_code=500, content={"error": "Internal server error"})
|
||||
@ -1,6 +1,5 @@
|
||||
from fastapi import APIRouter, UploadFile, File, Form, HTTPException
|
||||
from fastapi import APIRouter, Depends
|
||||
from infra.token.token_manager import TokenManager
|
||||
from starlette.status import HTTP_401_UNAUTHORIZED
|
||||
from fastapi.encoders import jsonable_encoder
|
||||
from fastapi.responses import JSONResponse
|
||||
@ -8,7 +7,6 @@ from backend.application.document_hub import DocumentHub
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
token_manager = TokenManager()
|
||||
|
||||
|
||||
@router.post(
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from backend.content.models import ContentDirectory,ContentFolderDoc
|
||||
from backend.content.models import ContentFolderDoc
|
||||
|
||||
content_models = []
|
||||
content_models.extend([ContentDirectory, ContentFolderDoc])
|
||||
content_models.extend([ContentFolderDoc])
|
||||
|
||||
@ -20,12 +20,17 @@ class ContentService:
|
||||
ContentFolderDoc.folder_name == folder_name,
|
||||
ContentFolderDoc.region == region
|
||||
)
|
||||
|
||||
if folder is None:
|
||||
folder = await ContentSharePointManager().retrieve_directories_for_folder(folder_name=folder_name, region=region)
|
||||
await ContentSharePointManager().retrieve_directories_for_folder(folder_name=folder_name, region=region)
|
||||
|
||||
folder = await ContentFolderDoc.find_one(
|
||||
ContentFolderDoc.folder_name == folder_name,
|
||||
ContentFolderDoc.region == region
|
||||
)
|
||||
|
||||
return folder.content_directories if folder else None
|
||||
|
||||
async def retrieve_content_as_media_data(self, document_id: str) -> Optional[str]:
|
||||
document_manager = DocumentManager()
|
||||
await document_manager.load_document(document_id)
|
||||
return await document_manager.read_document_file_as_http_media_data()
|
||||
return await document_manager.retrieve_document_as_http_media(document_id)
|
||||
|
||||
@ -64,18 +64,10 @@ class ContentSharePointManager:
|
||||
):
|
||||
cover_file_content = self.sharepoint_client.get_file_content(sp_file['id'])
|
||||
cover_document_manager = DocumentManager()
|
||||
await cover_document_manager.new_document(
|
||||
file_name=sp_file['name'].lower(),
|
||||
media_type=ContentMediaType.PNG,
|
||||
data_format=ContentDataFormat.RAW,
|
||||
file_name=sp_file['name'].lower()
|
||||
created_by=self.__generate_created__by__(folder_name=folder_name)
|
||||
)
|
||||
content_directory.cover_document_id = (
|
||||
cover_document_manager.get_document_id()
|
||||
)
|
||||
|
||||
await cover_document_manager.save_document_file(
|
||||
cover_file_content
|
||||
content_directory.cover_document_id = await cover_document_manager.save_document_file(
|
||||
created_by, file_name, cover_file_content
|
||||
)
|
||||
|
||||
elif (
|
||||
@ -109,17 +101,10 @@ class ContentSharePointManager:
|
||||
):
|
||||
content_file_content = self.sharepoint_client.get_file_content(sp_file['id'])
|
||||
content_document_manager = DocumentManager()
|
||||
await content_document_manager.new_document(
|
||||
file_name=sp_file['name'],
|
||||
media_type=ContentMediaType.PDF,
|
||||
data_format=ContentDataFormat.RAW,
|
||||
file_name=sp_file['name']
|
||||
created_by=self.__generate_created__by__(folder_name=folder_name)
|
||||
)
|
||||
content_directory.content_document_id = (
|
||||
content_document_manager.get_document_id()
|
||||
)
|
||||
await content_document_manager.save_document_file(
|
||||
content_file_content
|
||||
content_directory.content_document_id = await content_document_manager.save_document_file(
|
||||
created_by, file_name, content_file_content
|
||||
)
|
||||
|
||||
folder.content_directories.append(content_directory)
|
||||
|
||||
@ -3,7 +3,7 @@ import httpx
|
||||
|
||||
class DocumentManager:
|
||||
def __init__(self):
|
||||
self.storage_service_api_base = app_settings.CENTRAL_STORAGE_WEBAPI_URL_BASE
|
||||
self.storage_service_api_base = app_settings.CENTRAL_STORAGE_WEBAPI_URL_BASE.rstrip('/') + '/'
|
||||
|
||||
async def retrieve_document_info(self, document_id:str):
|
||||
api_url = self.storage_service_api_base + "retrieve_document_info/" + document_id
|
||||
@ -18,13 +18,13 @@ class DocumentManager:
|
||||
return response.json()['media']
|
||||
|
||||
async def save_document_file(self,associated_with:str, name:str,blob:bytes)->str:
|
||||
api_url = self.storage_service_api_base + "upload_document/"
|
||||
api_url = self.storage_service_api_base + "upload-file"
|
||||
files = {'file':(name,blob)}
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.post(api_url,
|
||||
data={
|
||||
'associated_with':associated_with,
|
||||
'name':name,
|
||||
'blob':blob
|
||||
}
|
||||
'associated_with':associated_with
|
||||
},
|
||||
files=files
|
||||
)
|
||||
return response.json()['document_id']
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import os
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
class AppSettings():
|
||||
class AppSettings(BaseSettings):
|
||||
NAME: str = "content"
|
||||
APP_NAME:str = NAME
|
||||
|
||||
@ -9,6 +9,9 @@ class AppSettings():
|
||||
|
||||
CENTRAL_STORAGE_WEBAPI_URL_BASE:str =""
|
||||
|
||||
MONGODB_NAME:str =""
|
||||
MONGODB_URI:str =""
|
||||
|
||||
LOG_BASE_PATH : str = "./log"
|
||||
BACKEND_LOG_FILE_NAME: str = APP_NAME
|
||||
APPLICATION_ACTIVITY_LOG: str = APP_NAME + "-application-activity"
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
from .app_settings import app_settings
|
||||
|
||||
class LogSettings():
|
||||
class LogSettings(BaseSettings):
|
||||
LOG_LEVEL: str = "DEBUG"
|
||||
LOG_BASE_PATH: str = app_settings.LOG_BASE_PATH
|
||||
LOG_PATH: str = LOG_BASE_PATH + '/' + app_settings.BACKEND_LOG_FILE_NAME + '.log'
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
from webapi.config.site_settings import site_settings
|
||||
from common.config.app_settings import app_settings
|
||||
from beanie import init_beanie
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
from database.mongo.models import mongo_models
|
||||
@ -8,7 +8,7 @@ class MongoDriver:
|
||||
pass
|
||||
|
||||
async def initiate_database(self):
|
||||
client = AsyncIOMotorClient(site_settings.MONGODB_URI, serverSelectionTimeoutMS=60000)
|
||||
client = AsyncIOMotorClient(app_settings.MONGODB_URI, serverSelectionTimeoutMS=60000)
|
||||
await init_beanie(
|
||||
database=client[site_settings.MONGODB_NAME], document_models=mongo_models
|
||||
database=client[app_settings.MONGODB_NAME], document_models=mongo_models
|
||||
)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from webapi.config.site_settings import site_settings
|
||||
from beanie import init_beanie
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
|
||||
from database.mongo.mongo_driver import MongoDriver
|
||||
|
||||
def register(app):
|
||||
app.debug = site_settings.DEBUG
|
||||
@ -14,4 +14,4 @@ def register(app):
|
||||
|
||||
async def initiate_database():
|
||||
#init your database here
|
||||
pass
|
||||
await MongoDriver().initiate_database()
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
from .app_settings import app_settings
|
||||
|
||||
class LogSettings():
|
||||
class LogSettings(BaseSettings):
|
||||
LOG_LEVEL: str = "DEBUG"
|
||||
LOG_BASE_PATH: str = app_settings.LOG_BASE_PATH
|
||||
LOG_PATH: str = LOG_BASE_PATH + '/' + app_settings.BACKEND_LOG_FILE_NAME + '.log'
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
export MONGODB_URI='mongodb+srv://jetli:8IHKx6dZK8BfugGp@freeleaps2.hanbj.mongodb.net/'
|
||||
export CENTRAL_STORAGE_WEBAPI_URL_BASE="http://if030-w2-if-vm.mathmast.com:8005/api"
|
||||
export FREELEAPS_ENV=alpha
|
||||
|
||||
@ -4,7 +4,6 @@ export MONGODB_NAME=freeleaps2
|
||||
export MONGODB_PORT=27017
|
||||
export CONTAINER_APP_ROOT=/app
|
||||
export FREELEAPS_WWW_AS_AZURE_CLIENT_SECRET=3gK8Q~PJbyWmiNqaGgho2ZqCY~OXzABSyN8wWasK
|
||||
export CENTRAL_STORAGE_WEBAPI_URL_BASE="http://if010-w2-if-vm.mathmast.com:8005/api"
|
||||
export LOG_BASE_PATH=$CONTAINER_APP_ROOT/log/$APP_NAME
|
||||
export BACKEND_LOG_FILE_NAME=$APP_NAME
|
||||
export APPLICATION_ACTIVITY_LOG=$APP_NAME-activity
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
export MONGODB_URI=mongodb://freeleaps2-mongodb:27017/
|
||||
export CENTRAL_STORAGE_WEBAPI_URL_BASE="http://central_storage:8005/api"
|
||||
export FREELEAPS_ENV=dev
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
export MONGODB_URI=mongodb://localhost:27017/
|
||||
export CENTRAL_STORAGE_WEBAPI_URL_BASE="http://localhost:8005/api"
|
||||
export FREELEAPS_ENV=local
|
||||
export LOG_BASE_PATH=${CODEBASE_ROOT}/log
|
||||
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
export MONGODB_URI='mongodb+srv://freeadmin:0eMV0bt8oyaknA0m@freeleaps2.zmsmpos.mongodb.net/?retryWrites=true&w=majority'
|
||||
export CENTRAL_STORAGE_WEBAPI_URL_BASE="http://if010-w2-if-vm.mathmast.com:8005/api"
|
||||
export FREELEAPS_ENV=prod
|
||||
|
||||
Loading…
Reference in New Issue
Block a user