Skip to content

Commit

Permalink
api: Provide images even if not marked primary, with full URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanqui committed Jan 8, 2025
1 parent 5c54e21 commit 931089c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ poetry run flask run --debug

## Run rhinventory-api
```bash
fastapi dev rhinventory/api/app.py
poetry run fastapi dev rhinventory/api/app.py
```

## Jak se Alembic?
Expand Down
13 changes: 8 additions & 5 deletions rhinventory/service/asset/services.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from sqlalchemy import select, and_
from sqlalchemy import select, and_, func
from sqlalchemy.orm import Session, Query, aliased

from rhinventory.api.asset.schemas import AssetSchema
from rhinventory.models.asset import Asset
from rhinventory.models.asset_attributes import AssetTag, asset_tag_table
from rhinventory.models.enums import HIDDEN_PRIVACIES, PUBLIC_PRIVACIES
from rhinventory.models.file import File, FileCategory
from rhinventory.models.file import File, FileCategory, IMAGE_CATEGORIES
from rhinventory.util import print_sql_query

FILE_URL_PREFIX="https://inventory.herniarchiv.cz/files/"

class InvalidAssetTag(Exception):
"""Tag doesn't exist or is otherwise invalid."""
Expand Down Expand Up @@ -42,13 +43,15 @@ def _get_asset_files(query: Query, private: bool) -> Query:
# Outer join for image
.outerjoin(image_file, and_(
image_file.asset_id == Asset.id,
image_file.category == FileCategory.photo,
image_file.primary == True,
image_file.category.in_(IMAGE_CATEGORIES),
image_file.privacy.in_(file_privacies)
))
.add_columns(image_file.filepath.label("primary_image_path"))
.order_by(image_file.primary.desc(), image_file.has_thumbnail.desc(), image_file.filepath.asc())
.limit(1)
.add_columns(func.concat(FILE_URL_PREFIX, image_file.id, '/', func.regexp_replace(image_file.filepath, '.*/', '')).label("primary_image_path"))

# Outer join for document
# TODO replicate behavior for image above
.outerjoin(document_file, and_(
document_file.asset_id == Asset.id,
document_file.category == FileCategory.document,
Expand Down

0 comments on commit 931089c

Please sign in to comment.