Skip to content

Commit 00e5784

Browse files
Add lasuite tools
1 parent f4a4ebe commit 00e5784

8 files changed

Lines changed: 176 additions & 0 deletions

File tree

backend/app/clients/drive.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import httpx
2+
from app.models import Document
3+
from pydantic import TypeAdapter
4+
5+
6+
class DriveClient:
7+
def __init__(self, base_url: str, token: str) -> None:
8+
self.base_url = base_url
9+
self.token = token
10+
self.client = httpx.Client(
11+
headers={"Authorization": f"Bearer {self.token}", "Content-Type": "application/json"}
12+
)
13+
14+
15+
def get_documents(
16+
self, path: str = "api/v1.0/items/", page: int = 1, title: str | None = None, favorite: bool = False
17+
) -> list[Document]:
18+
url = httpx.URL(f"{self.base_url}/{path}", params={"page": page})
19+
20+
if title:
21+
url = url.copy_add_param("title", str(title))
22+
23+
response = self.client.request("GET", url)
24+
if response.status_code != 200:
25+
return TypeAdapter(list[Document]).validate_python([])
26+
27+
results = response.json().get("results", [])
28+
29+
if len(results) < 1:
30+
return TypeAdapter(list[Document]).validate_python([])
31+
32+
33+
workspace_id = results[0]['id']
34+
35+
item_url = f"{self.base_url}/api/v1.0/items/{workspace_id}/children/"
36+
37+
response = self.client.request("GET", item_url)
38+
if response.status_code != 200:
39+
return TypeAdapter(list[Document]).validate_python([])
40+
41+
results = response.json().get("results", [])
42+
43+
print(results)
44+
45+
46+
notes: list[Document] = TypeAdapter(list[Document]).validate_python(results)
47+
48+
return notes

backend/app/clients/meet.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import httpx
2+
from app.models import Meeting
3+
from pydantic import TypeAdapter
4+
5+
6+
class MeetClient:
7+
def __init__(self, base_url: str, token: str) -> None:
8+
self.base_url = base_url
9+
self.token = token
10+
self.client = httpx.Client(
11+
headers={"Authorization": f"Bearer {self.token}", "Content-Type": "application/json"}
12+
)
13+
14+
def get_meetings(
15+
self, path: str = "api/v1.0/documents/", page: int = 1, title: str | None = None, favorite: bool = False
16+
) -> list[Meeting]:
17+
url = httpx.URL(f"{self.base_url}/{path}", params={"page": page})
18+
19+
if title:
20+
url = url.copy_add_param("title", str(title))
21+
22+
if favorite:
23+
url = url.copy_add_param("favorite", str(favorite))
24+
25+
response = self.client.request("GET", url)
26+
if response.status_code != 200:
27+
return TypeAdapter(list[Meeting]).validate_python([])
28+
29+
results = response.json().get("results", [])
30+
31+
notes: list[Meeting] = TypeAdapter(list[Meeting]).validate_python(results)
32+
33+
return notes

backend/app/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class Settings(BaseSettings):
3030
OCS_AUDIENCE: str = "files"
3131
DOCS_URL: str = "https://docs.la-suite.apps.digilab.network"
3232
DOCS_AUDIENCE: str = "docs"
33+
DRIVE_URL: str = "http://localhost:3001"
34+
DRIVE_AUDIENCE: str = "drive"
35+
MEET_URL: str = "http://localhost:8085"
36+
MEET_AUDIENCE: str = "meet"
3337
CALENDAR_URL: str = "https://files.la-suite.apps.digilab.network"
3438
CALENDAR_AUDIENCE: str = "files"
3539
TASK_URL: str = "https://files.la-suite.apps.digilab.network"

backend/app/models/document.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from datetime import datetime
2+
3+
from pydantic import BaseModel, computed_field
4+
5+
6+
class Document(BaseModel):
7+
title: str
8+
url: str
9+
mimetype: str
10+
updated_at: str
11+
12+
@computed_field
13+
@property
14+
def updated_date(self) -> str:
15+
return datetime.fromisoformat(self.updated_at).strftime("%d %b %Y")

backend/app/models/meeting.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pydantic import BaseModel
2+
3+
4+
class Meeting(BaseModel):
5+
title: str

backend/app/routes/drive.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import logging
2+
3+
from fastapi import APIRouter, Request
4+
5+
from app.clients.drive import DriveClient
6+
from app.config import settings
7+
from app.models import Document, User
8+
from app.token_exchange import exchange_token
9+
10+
logger = logging.getLogger(__name__)
11+
12+
router = APIRouter(prefix="/drive", tags=["drive"])
13+
14+
15+
@router.get("/documents", response_model=list[Document])
16+
async def drive_documents(request: Request, title: str | None = None, favorite: bool = False) -> list[Document]:
17+
user: User = request.state.user
18+
access_token = user.access_token
19+
new_token = await exchange_token(access_token, audience=settings.DRIVE_AUDIENCE)
20+
21+
if not new_token:
22+
return []
23+
24+
client = DriveClient(base_url=settings.DRIVE_URL, token=new_token)
25+
26+
documents: list[Document] = client.get_documents(title=title, favorite=favorite)
27+
28+
return documents

backend/app/routes/meet.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import logging
2+
3+
from fastapi import APIRouter, Request
4+
5+
from app.clients.meet import MeetClient
6+
from app.config import settings
7+
from app.models import Meeting, User
8+
from app.token_exchange import exchange_token
9+
10+
logger = logging.getLogger(__name__)
11+
12+
router = APIRouter(prefix="/meet", tags=["meet"])
13+
14+
15+
@router.get("/meeting", response_model=list[Meeting])
16+
async def meet_dmeetings(request: Request, title: str | None = None, favorite: bool = False) -> list[Meeting]:
17+
user: User = request.state.user
18+
access_token = user.access_token
19+
new_token = await exchange_token(access_token, audience=settings.MEET_AUDIENCE)
20+
21+
if not new_token:
22+
return []
23+
24+
client = MeetClient(base_url=settings.MEET_URL, token=new_token)
25+
26+
documents: list[Meeting] = client.get_documents(title=title, favorite=favorite)
27+
28+
return documents

backend/app/routes/rss.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
import httpx
3+
from fastapi import APIRouter, Query, Response, status
4+
5+
router = APIRouter(prefix="/rss", tags=["rss"])
6+
7+
8+
@router.get("/")
9+
async def rss_feed(url: str = Query(..., description="URL of the RSS feed")):
10+
11+
client = httpx.AsyncClient(timeout=5.0)
12+
resp = await client.get(url)
13+
resp.raise_for_status()
14+
# Forward the raw RSS feed content and content-type header
15+
return Response(content=resp.content, media_type=resp.headers.get("content-type", "application/xml"))

0 commit comments

Comments
 (0)