diff --git a/api/v1/node.py b/api/v1/node.py index b999240..0890a3a 100644 --- a/api/v1/node.py +++ b/api/v1/node.py @@ -10,6 +10,7 @@ from models.lonlat import LonLat from states.aed_state import AEDStateDep from states.photo_state import PhotoStateDep +from utils import get_wikimedia_commons_url router = APIRouter() @@ -43,12 +44,14 @@ async def _get_image_data(tags: dict[str, str], photo_state: PhotoStateDep) -> d return { '@photo_id': photo_info.id, '@photo_url': f'/api/v1/photos/view/{photo_info.id}.webp', + '@photo_source': None, } if image_url: return { '@photo_id': None, '@photo_url': f'/api/v1/photos/proxy/direct/{quote_plus(image_url)}', + '@photo_source': image_url, } wikimedia_commons: str = tags.get('wikimedia_commons', '') @@ -57,11 +60,13 @@ async def _get_image_data(tags: dict[str, str], photo_state: PhotoStateDep) -> d return { '@photo_id': None, '@photo_url': f'/api/v1/photos/proxy/wikimedia-commons/{quote_plus(wikimedia_commons)}', + '@photo_source': get_wikimedia_commons_url(wikimedia_commons), } return { '@photo_id': None, '@photo_url': None, + '@photo_source': None, } diff --git a/api/v1/photos.py b/api/v1/photos.py index 5c22c6c..8f0885e 100644 --- a/api/v1/photos.py +++ b/api/v1/photos.py @@ -17,7 +17,7 @@ from states.aed_state import AEDStateDep from states.photo_report_state import PhotoReportStateDep from states.photo_state import PhotoStateDep -from utils import get_http_client +from utils import get_http_client, get_wikimedia_commons_url router = APIRouter(prefix='/photos') @@ -65,19 +65,13 @@ async def view(id: str, photo_state: PhotoStateDep) -> FileResponse: async def proxy_direct(url_encoded: str) -> FileResponse: url = unquote_plus(url_encoded) file, content_type = await _fetch_image(url) - return Response( - file, - media_type=content_type, - headers={ - 'X-Image-Source': url, - }, - ) + return Response(file, media_type=content_type) @router.get('/proxy/wikimedia-commons/{path_encoded:path}') @configure_cache(timedelta(days=7), stale=timedelta(days=7)) async def proxy_wikimedia_commons(path_encoded: str) -> FileResponse: - meta_url = f'https://commons.wikimedia.org/wiki/{unquote_plus(path_encoded)}' + meta_url = get_wikimedia_commons_url(unquote_plus(path_encoded)) async with get_http_client() as http: r = await http.get(meta_url) @@ -90,13 +84,7 @@ async def proxy_wikimedia_commons(path_encoded: str) -> FileResponse: image_url = og_image['content'] file, content_type = await _fetch_image(image_url) - return Response( - file, - media_type=content_type, - headers={ - 'X-Image-Source': meta_url, - }, - ) + return Response(file, media_type=content_type) @router.post('/upload') diff --git a/config.py b/config.py index 2a7807b..05a0130 100644 --- a/config.py +++ b/config.py @@ -9,7 +9,7 @@ from pyproj import Transformer NAME = 'openaedmap-backend' -VERSION = '2.6.0' +VERSION = '2.6.1' VERSION_TIMESTAMP = 0 CREATED_BY = f'{NAME} {VERSION}' WEBSITE = 'https://openaedmap.org' diff --git a/poetry.lock b/poetry.lock index 1ad0ba8..1194497 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1769,18 +1769,18 @@ test = ["asv", "gmpy2", "hypothesis", "mpmath", "pooch", "pytest", "pytest-cov", [[package]] name = "setuptools" -version = "69.0.3" +version = "69.1.0" description = "Easily download, build, install, upgrade, and uninstall Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "setuptools-69.0.3-py3-none-any.whl", hash = "sha256:385eb4edd9c9d5c17540511303e39a147ce2fc04bc55289c322b9e5904fe2c05"}, - {file = "setuptools-69.0.3.tar.gz", hash = "sha256:be1af57fc409f93647f2e8e4573a142ed38724b8cdd389706a867bb4efcf1e78"}, + {file = "setuptools-69.1.0-py3-none-any.whl", hash = "sha256:c054629b81b946d63a9c6e732bc8b2513a7c3ea645f11d0139a2191d735c60c6"}, + {file = "setuptools-69.1.0.tar.gz", hash = "sha256:850894c4195f09c4ed30dba56213bf7c3f21d86ed6bdaafb5df5972593bfc401"}, ] [package.extras] docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier"] -testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-home (>=0.5)", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-ruff (>=0.2.1)", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] testing-integration = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "packaging (>=23.1)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] [[package]] diff --git a/shell.nix b/shell.nix index dba6eca..a08f1a6 100644 --- a/shell.nix +++ b/shell.nix @@ -3,7 +3,7 @@ let # Currently using nixpkgs-23.11-darwin # Update with `nixpkgs-update` command - pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/5cd1bc5c4d702f3ccc26fa93f86d05d5684fe5a3.tar.gz") { }; + pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/6716c0e608eed726549fd92704b9a7a7077bdf00.tar.gz") { }; libraries' = with pkgs; [ # Base libraries diff --git a/utils.py b/utils.py index 22909cd..e4f1fd9 100644 --- a/utils.py +++ b/utils.py @@ -83,3 +83,7 @@ def as_dict(data) -> dict: d[k] = mapping(v) return d + + +def get_wikimedia_commons_url(path: str) -> str: + return f'https://commons.wikimedia.org/wiki/{path}'