Improve file listing and fix notification metadata field
Backend:
- Optimize file listing for non-superusers with dedicated CRUD methods
- Add get_visible_for_user and count_visible_for_user for efficient queries
- Move /allowed-types/ and /max-size/ routes before /{file_id} for proper matching
- Rename notification 'metadata' field to 'extra_data' for clarity
- Fix settings export to use get_value() method
Frontend:
- Update NotificationItem interface to use extra_data field
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Optional, List, BinaryIO
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import or_
|
||||
|
||||
from app.models.file import StoredFile
|
||||
from app.schemas.file import FileCreate, FileUpdate, ALLOWED_CONTENT_TYPES, MAX_FILE_SIZE
|
||||
@@ -132,12 +133,36 @@ class CRUDFile:
|
||||
|
||||
return query.order_by(StoredFile.created_at.desc()).offset(skip).limit(limit).all()
|
||||
|
||||
def get_visible_for_user(
|
||||
self,
|
||||
db: Session,
|
||||
*,
|
||||
user_id: str,
|
||||
skip: int = 0,
|
||||
limit: int = 100,
|
||||
is_public: Optional[bool] = None,
|
||||
content_type: Optional[str] = None
|
||||
) -> List[StoredFile]:
|
||||
"""Get files visible to a user (own + public) with optional filtering."""
|
||||
query = db.query(StoredFile).filter(
|
||||
StoredFile.is_deleted == False,
|
||||
or_(StoredFile.uploaded_by == user_id, StoredFile.is_public == True)
|
||||
)
|
||||
|
||||
if is_public is not None:
|
||||
query = query.filter(StoredFile.is_public == is_public)
|
||||
if content_type:
|
||||
query = query.filter(StoredFile.content_type.like(f"{content_type}%"))
|
||||
|
||||
return query.order_by(StoredFile.created_at.desc()).offset(skip).limit(limit).all()
|
||||
|
||||
def count(
|
||||
self,
|
||||
db: Session,
|
||||
*,
|
||||
uploaded_by: Optional[str] = None,
|
||||
is_public: Optional[bool] = None
|
||||
is_public: Optional[bool] = None,
|
||||
content_type: Optional[str] = None
|
||||
) -> int:
|
||||
"""Count files with optional filtering."""
|
||||
query = db.query(StoredFile).filter(StoredFile.is_deleted == False)
|
||||
@@ -146,9 +171,31 @@ class CRUDFile:
|
||||
query = query.filter(StoredFile.uploaded_by == uploaded_by)
|
||||
if is_public is not None:
|
||||
query = query.filter(StoredFile.is_public == is_public)
|
||||
if content_type:
|
||||
query = query.filter(StoredFile.content_type.like(f"{content_type}%"))
|
||||
|
||||
return query.count()
|
||||
|
||||
def count_visible_for_user(
|
||||
self,
|
||||
db: Session,
|
||||
*,
|
||||
user_id: str,
|
||||
is_public: Optional[bool] = None,
|
||||
content_type: Optional[str] = None
|
||||
) -> int:
|
||||
"""Count files visible to a user (own + public) with optional filtering."""
|
||||
query = db.query(StoredFile).filter(
|
||||
StoredFile.is_deleted == False,
|
||||
or_(StoredFile.uploaded_by == user_id, StoredFile.is_public == True)
|
||||
)
|
||||
|
||||
if is_public is not None:
|
||||
query = query.filter(StoredFile.is_public == is_public)
|
||||
if content_type:
|
||||
query = query.filter(StoredFile.content_type.like(f"{content_type}%"))
|
||||
|
||||
return query.count()
|
||||
def create(
|
||||
self,
|
||||
db: Session,
|
||||
|
||||
Reference in New Issue
Block a user