mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
add resource api route
This commit is contained in:
@@ -6,11 +6,7 @@ from fastapi import FastAPI
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory import db
|
||||
from .routers import knowledge
|
||||
from .routers import discovery
|
||||
from .routers import memory
|
||||
from .routers.activity_router import router as activity_router
|
||||
from .routers.search_router import router as search_router
|
||||
from .routers import knowledge, discovery, search, activity, memory, resource
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
@@ -33,7 +29,7 @@ app = FastAPI(
|
||||
# Include routers
|
||||
app.include_router(knowledge.router)
|
||||
app.include_router(discovery.router)
|
||||
app.include_router(activity_router)
|
||||
app.include_router(search_router)
|
||||
|
||||
app.include_router(memory.router)
|
||||
app.include_router(activity.router)
|
||||
app.include_router(search.router)
|
||||
app.include_router(memory.router)
|
||||
app.include_router(resource.router)
|
||||
@@ -3,5 +3,8 @@
|
||||
from . import knowledge_router as knowledge
|
||||
from . import discovery_router as discovery
|
||||
from . import memory_router as memory
|
||||
from . import resource_router as resource
|
||||
from . import activity_router as activity
|
||||
from . import search_router as search
|
||||
|
||||
__all__ = ["knowledge", "discovery", "memory"]
|
||||
__all__ = ["knowledge", "discovery", "memory", "resource", "activity", "search"]
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
"""Routes for getting entity content."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
from loguru import logger
|
||||
|
||||
from basic_memory.deps import EntityRepositoryDep, ProjectConfigDep
|
||||
|
||||
router = APIRouter(prefix="/resource", tags=["resources"])
|
||||
|
||||
|
||||
@router.get("/{permalink:path}")
|
||||
async def get_resource_content(
|
||||
config: ProjectConfigDep,
|
||||
entity_repository: EntityRepositoryDep,
|
||||
permalink: str,
|
||||
) -> FileResponse:
|
||||
"""Get resource content by permalink."""
|
||||
logger.debug(f"Getting content for permalink: {permalink}")
|
||||
|
||||
# Find entity by permalink
|
||||
entity = await entity_repository.get_by_permalink(permalink)
|
||||
if not entity:
|
||||
raise HTTPException(status_code=404, detail=f"Entity not found: {permalink}")
|
||||
|
||||
file_path = Path(f"{config.home}/{entity.file_path}")
|
||||
if not file_path.exists():
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail=f"File not found: {file_path}",
|
||||
)
|
||||
return FileResponse(path=file_path)
|
||||
Reference in New Issue
Block a user