Skip to content

Commit 4b35fa9

Browse files
committed
feat: add recent canvas backups endpoint
- Introduced a new endpoint to retrieve the most recent canvas backups for authenticated users. - Implemented logic to limit the number of backups returned based on a maximum configured value. - Enhanced the canvas router with JWT decoding to identify the user associated with the backups.
1 parent e0285df commit 4b35fa9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/backend/routers/canvas.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import json
22
import jwt
3-
from typing import Dict, Any
3+
from typing import Dict, Any, List
44
from fastapi import APIRouter, HTTPException, Depends, Request
55
from fastapi.responses import JSONResponse
66

77
from dependencies import SessionData, require_auth
8-
from db import store_canvas_data, get_canvas_data
8+
from db import store_canvas_data, get_canvas_data, get_recent_canvases, MAX_BACKUPS_PER_USER
99
import posthog
1010

1111
canvas_router = APIRouter()
@@ -74,3 +74,17 @@ async def get_canvas(auth: SessionData = Depends(require_auth)):
7474
if data is None:
7575
return get_default_canvas_data()
7676
return data
77+
78+
@canvas_router.get("/recent")
79+
async def get_recent_canvas_backups(limit: int = MAX_BACKUPS_PER_USER, auth: SessionData = Depends(require_auth)):
80+
"""Get the most recent canvas backups for the authenticated user"""
81+
access_token = auth.token_data.get("access_token")
82+
decoded = jwt.decode(access_token, options={"verify_signature": False})
83+
user_id = decoded["sub"]
84+
85+
# Limit the number of backups to the maximum configured value
86+
if limit > MAX_BACKUPS_PER_USER:
87+
limit = MAX_BACKUPS_PER_USER
88+
89+
backups = await get_recent_canvases(user_id, limit)
90+
return {"backups": backups}

0 commit comments

Comments
 (0)