File tree Expand file tree Collapse file tree
CmdPalWebSearchShortcut/WebSearchShortcut/SuggestionsProviders Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ public async Task<IReadOnlyList<Suggestion>> GetSuggestionsAsync(string query, C
2020 {
2121 try
2222 {
23- const string api = "https://www.npmjs.com/search/suggestions?q=" ;
23+ // Use the public registry API instead of the website internal API to avoid bot protection issues
24+ const string api = "https://registry.npmjs.org/-/v1/search?text=" ;
2425
2526 await using var resultStream = await Http
2627 . GetStreamAsync ( api + Uri . EscapeDataString ( query ) , cancellationToken )
@@ -30,14 +31,15 @@ public async Task<IReadOnlyList<Suggestion>> GetSuggestionsAsync(string query, C
3031 . ParseAsync ( resultStream , cancellationToken : cancellationToken )
3132 . ConfigureAwait ( false ) ;
3233
33- var results = json . RootElement . EnumerateArray ( ) ;
34+ var results = json . RootElement . GetProperty ( "objects" ) . EnumerateArray ( ) ;
3435
3536 Suggestion [ ] items = [
3637 .. results
3738 . Select ( o =>
3839 {
39- var title = o . GetProperty ( "name" ) . GetString ( ) ;
40- var description = o . GetProperty ( "description" ) . GetString ( ) ;
40+ var pkg = o . GetProperty ( "package" ) ;
41+ var title = pkg . GetProperty ( "name" ) . GetString ( ) ;
42+ var description = pkg . TryGetProperty ( "description" , out var desc ) ? desc . GetString ( ) : "" ;
4143 return title is null ? null : new Suggestion ( title , description ?? "" ) ;
4244 } )
4345 . Where ( s => s is not null )
You can’t perform that action at this time.
0 commit comments