mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-04 20:05:16 +02:00
feat(file-storage): add settings, key builder, and backend factory
This commit is contained in:
parent
74fcad6496
commit
1bb1022d35
4 changed files with 117 additions and 0 deletions
27
surfsense_backend/app/file_storage/keys.py
Normal file
27
surfsense_backend/app/file_storage/keys.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
"""Object-key construction for stored document files."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from app.file_storage.persistence.enums import DocumentFileKind
|
||||
|
||||
|
||||
def build_document_file_key(
|
||||
*,
|
||||
search_space_id: int,
|
||||
document_id: int,
|
||||
kind: DocumentFileKind,
|
||||
filename: str,
|
||||
) -> str:
|
||||
"""Build the storage key for one document file.
|
||||
|
||||
Shape: ``documents/{search_space_id}/{document_id}/{kind}/{uuid}{ext}``.
|
||||
"""
|
||||
extension = os.path.splitext(filename)[1].lower()
|
||||
unique = uuid.uuid4().hex
|
||||
return (
|
||||
f"documents/{search_space_id}/{document_id}/"
|
||||
f"{kind.value.lower()}/{unique}{extension}"
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue