@@ -128,6 +128,9 @@ func New(options *Options) *API {
128
128
r .Get ("/publishers/{publisher}/vsextensions/{extension}/{version}/{type}" , api .assetRedirect )
129
129
r .Get ("/api/publishers/{publisher}/vsextensions/{extension}/{version}/{type}" , api .assetRedirect )
130
130
131
+ // Return the specified extension with only the latest version included.
132
+ r .Get ("/api/vscode/{publisher}/{extension}/latest" , api .latestExtension )
133
+
131
134
// This is the URL you get taken to when you click the extension's names,
132
135
// ratings, etc from the extension details page.
133
136
r .Get ("/item" , func (rw http.ResponseWriter , r * http.Request ) {
@@ -256,3 +259,48 @@ func (api *API) assetRedirect(rw http.ResponseWriter, r *http.Request) {
256
259
257
260
http .Redirect (rw , r , url , http .StatusMovedPermanently )
258
261
}
262
+
263
+ func (api * API ) latestExtension (rw http.ResponseWriter , r * http.Request ) {
264
+ baseURL := httpapi .RequestBaseURL (r , "/" )
265
+ filter := database.Filter {
266
+ Criteria : []database.Criteria {
267
+ {
268
+ Type : database .Target ,
269
+ Value : "Microsoft.VisualStudio.Code" ,
270
+ },
271
+ {
272
+ // ExtensionName is the fully qualified name `publisher.extension`.
273
+ Type : database .ExtensionName ,
274
+ Value : storage .ExtensionIDWithoutVersion (chi .URLParam (r , "publisher" ), chi .URLParam (r , "extension" )),
275
+ },
276
+ },
277
+ PageNumber : 1 ,
278
+ PageSize : 1 ,
279
+ }
280
+ flags := database .IncludeVersions |
281
+ database .IncludeFiles |
282
+ database .IncludeCategoryAndTags |
283
+ database .IncludeVersionProperties |
284
+ database .IncludeAssetURI |
285
+ database .IncludeStatistics |
286
+ database .IncludeLatestVersionOnly
287
+ extensions , _ , err := api .Database .GetExtensions (r .Context (), filter , flags , baseURL )
288
+ if err != nil {
289
+ httpapi .Write (rw , http .StatusInternalServerError , httpapi.ErrorResponse {
290
+ Message : "Unable to read extension" ,
291
+ Detail : "Contact an administrator with the request ID" ,
292
+ RequestID : httpmw .RequestID (r ),
293
+ })
294
+ return
295
+ }
296
+ if len (extensions ) == 0 {
297
+ httpapi .Write (rw , http .StatusNotFound , httpapi.ErrorResponse {
298
+ Message : "Extension does not exist" ,
299
+ Detail : "Please check the publisher and extension name" ,
300
+ RequestID : httpmw .RequestID (r ),
301
+ })
302
+ return
303
+ }
304
+
305
+ httpapi .Write (rw , http .StatusOK , extensions [0 ])
306
+ }
0 commit comments