69 lines
1.8 KiB
Python
69 lines
1.8 KiB
Python
from typing import Any, Dict, List, Optional
|
|
|
|
from fastapi import Request, UploadFile
|
|
|
|
from models.bot import BotInstance
|
|
from providers.selector import get_workspace_provider
|
|
|
|
|
|
class WorkspaceService:
|
|
def list_tree(
|
|
self,
|
|
*,
|
|
app_state: Any,
|
|
bot: BotInstance,
|
|
path: Optional[str] = None,
|
|
recursive: bool = False,
|
|
) -> Dict[str, Any]:
|
|
return get_workspace_provider(app_state, bot).list_tree(bot_id=bot.id, path=path, recursive=recursive)
|
|
|
|
def read_file(
|
|
self,
|
|
*,
|
|
app_state: Any,
|
|
bot: BotInstance,
|
|
path: str,
|
|
max_bytes: int = 200000,
|
|
) -> Dict[str, Any]:
|
|
return get_workspace_provider(app_state, bot).read_file(bot_id=bot.id, path=path, max_bytes=max_bytes)
|
|
|
|
def write_markdown(
|
|
self,
|
|
*,
|
|
app_state: Any,
|
|
bot: BotInstance,
|
|
path: str,
|
|
content: str,
|
|
) -> Dict[str, Any]:
|
|
return get_workspace_provider(app_state, bot).write_markdown(bot_id=bot.id, path=path, content=content)
|
|
|
|
async def upload_files(
|
|
self,
|
|
*,
|
|
app_state: Any,
|
|
bot: BotInstance,
|
|
files: List[UploadFile],
|
|
path: Optional[str] = None,
|
|
) -> Dict[str, Any]:
|
|
return await get_workspace_provider(app_state, bot).upload_files(bot_id=bot.id, files=files, path=path)
|
|
|
|
def serve_file(
|
|
self,
|
|
*,
|
|
app_state: Any,
|
|
bot: BotInstance,
|
|
path: str,
|
|
download: bool,
|
|
request: Request,
|
|
public: bool = False,
|
|
redirect_html_to_raw: bool = False,
|
|
):
|
|
return get_workspace_provider(app_state, bot).serve_file(
|
|
bot_id=bot.id,
|
|
path=path,
|
|
download=download,
|
|
request=request,
|
|
public=public,
|
|
redirect_html_to_raw=redirect_html_to_raw,
|
|
)
|