Get Saved Themes API (api/editor/themes/getSavedThemes.ts)¶
Endpoint Overview¶
Retrieves saved themes for a specific document or user, including both document-specific and global themes. Supports filtering and includes theme metadata.
Request Handlers¶
GET¶
- Query Parameters:
- Response:
{ success: boolean; themes: Array<{ id: string; // Theme unique identifier name: string; // Theme name description: string; // Theme description color: string; // Theme color (hex) type: 'document' | 'global'; // Theme scope documentId?: string; // Associated document (if document-specific) createdAt: string; // Creation timestamp updatedAt: string; // Last update timestamp usageCount: number; // Number of times used }>; metadata: { totalThemes: number; // Total themes returned documentThemes: number; // Document-specific themes globalThemes: number; // Global themes }; } - Status: 200 OK, 400 Bad Request, 401 Unauthorized, 404 Not Found
Error Handling¶
try {
// Theme retrieval logic
} catch (error) {
return {
error: error.message,
code: error.code
};
}
Common errors: - UNAUTHORIZED: User not authorized - INVALID_ID: Document or user ID is invalid - DOCUMENT_NOT_FOUND: Document does not exist - USER_NOT_FOUND: User does not exist
Usage Example¶
const response = await fetch("/api/editor/themes/getSavedThemes?documentId=doc_123&includeGlobal=true");
const { success, themes, metadata } = await response.json();
if (success) {
console.log(`Total themes: ${metadata.totalThemes}`);
themes.forEach(theme => {
console.log(`Theme: ${theme.name} (${theme.type})`);
});
}
Implementation Details¶
- Supports theme filtering
- Includes usage statistics
- Maintains theme history
- Handles global themes
- Tracks theme usage
- Optimizes retrieval
- Validates permissions
- Manages theme metadata
- Supports theme reuse
Pages/Components Referenced By¶
- Editor Module - Theme management
- Theme Card - Theme display
- Set Saved Themes API - Theme updates
- Editor State API - State management
- Save State API - Document persistence
Notes¶
- Requires authentication
- Sorts by usage count
- Includes metadata
- Supports reuse
- Maintains history
- Quick retrieval
- Theme versioning
- Efficient caching
- Scope management