$ show hanximeng/LanzouAPI
LanzouAPI is a single-file PHP script that acts as a parsing proxy for Lanzou (θε₯δΊ) cloud storage share links. It accepts a share URL and optional password, scrapes the Lanzou page, handles anti-scraping challenges (including ESA and acw_sc__v2 cookie generation), and returns a JSON response containing the file name, size, and a direct download URL. Optionally, it can redirect directly to the download. The script includes a local file-based cache with configurable TTL to reduce requests and avoid rate limiting. It also provides a custom suffix replacement feature for download URLs. The codebase is a monolith with no framework, no tests, and no dependency management; all logic resides in a single index.php file. While functional and actively used (as evidenced by the health-check workflow), the architecture is tightly coupled and would require significant refactoring for reuse beyond this specific Lanzou API use case.
The LLM identified 2 files worth highlighting for reuse:
The `acw_sc_v2_simple` function implements the algorithm to compute the `acw_sc__v2` cookie value from a 40-character hex challenge string (`arg1`) returned by the Lanzou CDN. It performs a positional permutation based on a fixed index list, then XORs the result with a static mask. This is a self-contained, non-obvious cryptographic-like transform that could be extracted and reused for any project needing to bypass similar ESA challenges.
The `CacheGet`, `CacheSet`, and `CacheClean` functions implement a simple file-based caching system with configurable time-to-live (TTL) and periodic cleanup. They store serialized JSON data in a designated directory, keyed by an MD5 hash of the request parameters combined with a salt. This pattern is reusable in any PHP application needing lightweight, self-clearing caching without external dependencies.