Skip to content

Commit b1fc754

Browse files
committed
Improve File Management
Signed-off-by: Fabian Wolf <fabian@fawolf.de>
1 parent 09c0227 commit b1fc754

19 files changed

+3034
-310
lines changed

backend/src/dependencies.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import hashlib
12
import os
23
import uuid
34
from typing import Generator
@@ -31,6 +32,9 @@
3132
aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
3233
)
3334

35+
def calculate_file_hash(content: bytes) -> str:
36+
"""Calculate SHA-256 hash of file content"""
37+
return hashlib.sha256(content).hexdigest()
3438

3539
def get_file(file_name: str) -> bytes:
3640
"""

backend/src/models/project.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
String,
1313
Table,
1414
UniqueConstraint,
15+
Index,
1516
)
1617
from sqlalchemy.ext.mutable import MutableDict
1718
from sqlalchemy.orm import Mapped, mapped_column, relationship
@@ -128,12 +129,21 @@ class File(Base):
128129
Enum(FileCreator, native_enum=False, length=20), default=FileCreator.user
129130
)
130131
description: Mapped[str] = mapped_column(String(500), nullable=True)
132+
133+
# New fields for better file management
134+
file_size: Mapped[int] = mapped_column(nullable=True) # Size in bytes
135+
file_hash: Mapped[str] = mapped_column(String(64), nullable=True) # SHA-256 hash
136+
131137
created_at: Mapped[DateTime] = mapped_column(
132138
DateTime(timezone=True), server_default=func.now()
133139
)
134140
updated_at: Mapped[DateTime] = mapped_column(
135141
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
136142
)
143+
144+
# Add index for hash lookups
145+
__table_args__ = (Index("ix_file_hash_project", "file_hash", "project_id"),)
146+
137147
project: Mapped["Project"] = relationship(back_populates="files")
138148
documents_as_original: Mapped[list["Document"]] = relationship(
139149
foreign_keys="[Document.original_file_id]", back_populates="original_file"

0 commit comments

Comments
 (0)