diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..98b8445 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ + +__pycache__/ + +.env +.vs/ +.venv/ +*.tmp +testing/ +tests/ +.vscode/ +.ruff_check/ +.gitea/ + + +# Random files +README.md +LICENSE.txt +NathanWoodburn.bsdesign +Dockerfile \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 2c7a50c..fe74f19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,24 @@ -FROM --platform=$BUILDPLATFORM python:3.13-alpine AS builder +FROM --platform=$BUILDPLATFORM python:3.13-alpine +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ -RUN apk add curl +# Set working directory WORKDIR /app -COPY requirements.txt /app -RUN --mount=type=cache,target=/root/.cache/pip \ - python3 -m pip install -r requirements.txt +# Install dependencies +RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --locked --no-install-project -COPY . /app +# Copy the project into the image +ADD . /app + +# Sync the project +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --locked # Add mount point for data volume # VOLUME /data -ENTRYPOINT ["python3"] +ENTRYPOINT ["uv", "run"] CMD ["main.py"] - -FROM builder AS dev-envs diff --git a/blueprints/spotify.py b/blueprints/spotify.py index d4c402a..8b55252 100644 --- a/blueprints/spotify.py +++ b/blueprints/spotify.py @@ -25,6 +25,10 @@ def refresh_access_token(): """Refresh Spotify access token when expired.""" global ACCESS_TOKEN, TOKEN_EXPIRES + # If no refresh token, cannot proceed + if not REFRESH_TOKEN: + return None + # If still valid, reuse it if ACCESS_TOKEN and time.time() < TOKEN_EXPIRES - 60: return ACCESS_TOKEN @@ -100,7 +104,7 @@ def get_spotify_track(): """Internal function to get current playing track without HTTP context.""" token = refresh_access_token() if not token: - return json_response(request, {"error": "Failed to refresh access token"}, 500) + return {"error": "Failed to refresh access token"} headers = {"Authorization": f"Bearer {token}"} response = requests.get(SPOTIFY_CURRENTLY_PLAYING_URL, headers=headers)