scan_apis.ps1 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Scan all saasadminui API files and extract URLs
  2. $apiDir = 'd:\ylrz\saasadminui\src\api'
  3. $allUrls = [System.Collections.ArrayList]::new()
  4. Get-ChildItem -Path $apiDir -Recurse -Include '*.js' | ForEach-Object {
  5. $file = $_.FullName
  6. $relPath = $_.FullName.Replace($apiDir + '\', '')
  7. $content = Get-Content $file -Raw -Encoding UTF8
  8. # Match url patterns like: url: '/xxx/yyy/zzz' or url: "/xxx/yyy/zzz"
  9. $matches = [regex]::Matches($content, "url:\s*['""]([^'""]+)['""]")
  10. foreach ($m in $matches) {
  11. $url = $m.Groups[1].Value
  12. # Skip variable interpolation like `${xxx}`
  13. if ($url -notmatch '\$\{') {
  14. [void]$allUrls.Add([PSCustomObject]@{
  15. File = $relPath
  16. URL = $url
  17. })
  18. }
  19. }
  20. }
  21. Write-Host "Total API URLs found: $($allUrls.Count)"
  22. # Group by URL prefix (first 2 path segments)
  23. $grouped = $allUrls | Group-Object { ($_.URL -split '/')[0..2] -join '/' } | Sort-Object Count -Descending
  24. Write-Host "`n=== URL Prefix Groups ==="
  25. $grouped | Select-Object @{N='Prefix';E={$_.Name}}, Count | Format-Table -AutoSize
  26. # Save all URLs
  27. $allUrls | ConvertTo-Json -Depth 3 | Out-File -FilePath 'd:\ylrz\saasadminui\all_api_urls.json' -Encoding UTF8
  28. Write-Host "`nAll URLs saved to all_api_urls.json"
  29. # Extract unique URL prefixes for testing
  30. $uniquePrefixes = $allUrls | ForEach-Object { ($_.URL -split '/')[0..1] -join '/' } | Sort-Object -Unique
  31. Write-Host "`n=== Unique URL Prefixes (top 2 segments) ==="
  32. $uniquePrefixes