Refactor duplicated code into shared utilities - #4
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
Refactor duplicated code into shared utilities#4devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Deduplicates repeated patterns across the backend routes/services and the frontend components into shared utilities.
New
backend/utils.py:@require_spotify_auth— replaces theif 'access_token' not in session: return 401guard repeated in all 4 playlist routesget_spotify_service()— replaces the 6x repeatedSpotifyService(Config.SPOTIFY_CLIENT_ID, Config.SPOTIFY_CLIENT_SECRET)store_token_session(token_info)— token/expiry session storage previously duplicated incallbackandauth_statusformat_track(track)/format_duration(ms)— the raw-Spotify-track → frontend dict mapping (default image +m:ssduration) previously duplicated ingenerate_previewandSearch_Trackbackend/services/spotify.py:_token_request(data, error_label)— shared Basic-auth token POST used byexchange_code_for_tokenandrefresh_token_search_request(token, query, limit, timeout)— shared search GET used by both the strict and relaxed passes ofsearch_track(aRATE_LIMITEDsentinel preserves the original 429 short-circuit vs. fall-through-on-error behavior)search_tracks()andget_user_playlists()methods soSearch_TrackandGet_Playlistsroutes call the service instead of inlining rawrequestscalls — this also fixes a latentNameError:playlist.pyusedrequestswithout importing it, so both routes would crash at runtimeFrontend (
UI_Front/src/lib/playlist.ts):generatePlaylistNameandcalculateDurationwere duplicated verbatim inSpotifyPlaylistGenerator.tsxandPreferenceInput.tsx; they now live in the shared module (the copies inSpotifyPlaylistGeneratorwere dead code and are simply removed).gitignorefix:lib/→/lib/(andlib64/). The unanchored Python-venv pattern was ignoringUI_Front/src/lib/, which is whysrc/lib/api.ts/src/lib/utils.ts(imported throughout the frontend) were never committed. Note: those files still need to be committed from a machine that has them —tsccurrently fails with TS2307 on@/lib/api/@/lib/utilsonmainand this PR alike.Verification
python -c "from backend.app import create_app"— app builds; all routes register unchangedpyflakes backend/— no new warnings (remaining unused-import warnings are preexisting)eslinton touched frontend files — no new errors;tscerrors are all preexisting TS2307 missing@/lib/api/@/lib/utilsLink to Devin session: https://app.devin.ai/sessions/c11c29e6d62940faa80941b4e3b536bc
Requested by: @praneels2005