Refactor: Extract URL parsing logic and improve code organization - #1
Merged
Merged
Conversation
…moved) - Centralize INSPECT_BASE constant: defined once in url-parser.ts, imported elsewhere - Eliminate URL parsing duplication: UrlAnalyzer class delegates to pure functions in url-parser.ts instead of duplicating ~200 lines of identical parsing/formatting logic - Consolidate URL dispatch logic: extract decodeMaskedFromAnalyzed() helper in index.ts, collapse two inspectItem() code paths into one by normalizing args - Extract waitForReady() helper in steam-client.ts to deduplicate promise timeout pattern - Fix cleanExpiredItems() O(n^2) algorithm: use single reverse-iteration pass - Fix redundant hex validation: remove unreachable >2000 check (>4096 is correct) - Fix deprecated substr() usage: replace with slice() in protobuf-reader.ts All existing tests pass. No public API changes. https://claude.ai/code/session_01Ur7bfZrcaiPGhM6N8AQehW
…sRarity - Cache CRC32 lookup table as module-level constant instead of regenerating the 256-entry table on every createInspectUrl() call - Replace all bare console.log/error/warn calls in steam-client.ts and steam-client-manager.ts with debugLog() that respects enableLogging config - Fix processRarity() to throw EncodingError on unknown string values instead of silently returning STOCK (0), and remove unreachable final return - Remove no-op ternary `typeof item.defindex === 'number' ? item.defindex : item.defindex` https://claude.ai/code/session_01Ur7bfZrcaiPGhM6N8AQehW
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
This PR refactors the codebase to improve maintainability and code organization by extracting shared URL parsing logic into reusable helper functions, consolidating duplicate code, and improving error handling consistency.
Key Changes
Code Extraction & Deduplication
decodeMaskedFromAnalyzed(): Extracted common masked URL decoding logic that was duplicated acrossCS2Inspect.decodeMaskedUrl()and the standalonedecodeMaskedUrl()function. This eliminates code duplication and ensures consistent error handling.UrlAnalyzernow delegates to pure functions inutils/url-parser.ts(parseInspectUrl()andformatInspectUrl()), removing ~200 lines of duplicated parsing logic from the class.Improved Error Handling & Logging
console.log()calls inSteamClientandSteamClientManagerwith a centralizeddebugLog()method that respects theenableLoggingconfiguration flag.waitForReady()method inSteamClientto reduce code duplication in connection logic.Performance Optimizations
ProtobufWriter, eliminating redundant table generation on everycrc32()call.cleanExpiredItems()inSteamClientto iterate backwards when removing items, avoiding index shifting issues.Code Quality Improvements
inspectItem()function: Refactored argument parsing logic to be more straightforward and maintainable, with clearer separation between options format and config-only format.substr()withslice()inProtobufReaderfor better compatibility.processRarity()to throw descriptive errors for invalid rarity values instead of silently defaulting.Documentation Cleanup
Implementation Details
decodeMaskedFromAnalyzed()helper maintains the same error handling behavior as the original implementations, ensuring backward compatibilityhttps://claude.ai/code/session_01Ur7bfZrcaiPGhM6N8AQehW