Skip to content

Commit

Permalink
refactor: rename generate function to generate_uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
pk5ls20 committed Apr 28, 2024
1 parent 7890ab3 commit 8c632c6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/Controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from app.Services.provider import db_context, storage_service, index_service
from app.Services.vector_db_context import PointNotFoundError
from app.config import config
from app.util.generate_uuid import generate
from app.util.generate_uuid import generate_uuid

admin_router = APIRouter(dependencies=[Depends(force_admin_token_verify)], tags=["Admin"])

Expand Down Expand Up @@ -125,7 +125,7 @@ async def upload_image(image_file: Annotated[UploadFile, File(description="The i
if not img_type:
raise HTTPException(415, "Unsupported image format.")
img_bytes = await image_file.read()
img_id = generate(img_bytes)
img_id = generate_uuid(img_bytes)
if len(await db_context.validate_ids([str(img_id)])) != 0: # check for duplicate points
raise HTTPException(409, f"The uploaded point is already contained in the database! entity id: {img_id}")

Expand Down
2 changes: 1 addition & 1 deletion app/util/generate_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace_uuid = uuid5(NAMESPACE_DNS, NAMESPACE_STR)


def generate(file_input: pathlib.Path | io.BytesIO | bytes) -> UUID:
def generate_uuid(file_input: pathlib.Path | io.BytesIO | bytes) -> UUID:
if isinstance(file_input, pathlib.Path):
with open(file_input, 'rb') as f:
file_content = f.read()
Expand Down
4 changes: 2 additions & 2 deletions scripts/local_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from app.Models.img_data import ImageData
from app.Services.provider import index_service, db_context
from app.Services.provider import storage_service
from app.util import generate_uuid
from app.util.generate_uuid import generate_uuid
from .local_utility import fetch_path_uuid_list

overall_count = 0
Expand All @@ -24,7 +24,7 @@ async def copy_and_index(file_path: Path, uuid_str: str = None):
except PIL.UnidentifiedImageError as e:
logger.error("Error when opening image {}: {}", file_path, e)
return
image_id = uuid.UUID(uuid_str) if uuid_str else generate_uuid.generate(file_path)
image_id = uuid.UUID(uuid_str) if uuid_str else generate_uuid(file_path)
img_ext = file_path.suffix
imgdata = ImageData(id=image_id,
url=await storage_service.active_storage.url(f'{image_id}{img_ext}'),
Expand Down
4 changes: 2 additions & 2 deletions scripts/local_utility.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pathlib import Path
from app.util import generate_uuid
from app.util.generate_uuid import generate_uuid


def calculate_uuid(file_path: Path) -> str:
return str(generate_uuid.generate(file_path))
return str(generate_uuid(file_path))


def fetch_path_uuid_list(file_path: Path | list[Path]) -> list[tuple[Path, str]]:
Expand Down

0 comments on commit 8c632c6

Please sign in to comment.