Skip to content

Commit 4b5f654

Browse files
committed
Add /publishers route
1 parent 82b3b38 commit 4b5f654

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

api/api.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ func New(options *Options) *API {
120120
// types to get files.
121121
r.Get("/assets/{publisher}/{extension}/{version}/{type}", api.assetRedirect)
122122

123+
// This is the "download manually" URL, which like /assets is hardcoded and
124+
// ignores the VSIX asset URL provided to VS Code in the response.
125+
r.Get("/publishers/{publisher}/vsextensions/{extension}/{version}/{type}", api.assetRedirect)
126+
123127
return api
124128
}
125129

@@ -200,10 +204,14 @@ func (api *API) extensionQuery(rw http.ResponseWriter, r *http.Request) {
200204
func (api *API) assetRedirect(rw http.ResponseWriter, r *http.Request) {
201205
// TODO: Asset URIs can contain a targetPlatform query variable.
202206
baseURL := httpapi.RequestBaseURL(r, "/")
207+
assetType := chi.URLParam(r, "type")
208+
if assetType == "vspackage" {
209+
assetType = database.ExtensionAssetType
210+
}
203211
url, err := api.Database.GetExtensionAssetPath(r.Context(), &database.Asset{
204212
Extension: chi.URLParam(r, "extension"),
205213
Publisher: chi.URLParam(r, "publisher"),
206-
Type: chi.URLParam(r, "type"),
214+
Type: assetType,
207215
Version: chi.URLParam(r, "version"),
208216
}, baseURL)
209217
if err != nil && os.IsNotExist(err) {

api/api_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,21 @@ func TestAPI(t *testing.T) {
230230
Status: http.StatusMovedPermanently,
231231
Response: "/files/publisher/extension/version/foo",
232232
},
233+
{
234+
Name: "DownloadNotExist",
235+
Path: "/publishers/notexist/vsextensions/extension/version/vspackage",
236+
Status: http.StatusNotFound,
237+
Response: &httpapi.ErrorResponse{
238+
Message: "Extension asset does not exist",
239+
Detail: "Please check the asset path",
240+
},
241+
},
242+
{
243+
Name: "DownloadOK",
244+
Path: "/publishers/publisher/vsextensions/extension/version/vspackage",
245+
Status: http.StatusMovedPermanently,
246+
Response: "/files/publisher/extension/version/extension.vsix",
247+
},
233248
}
234249

235250
extdir := filepath.Join(t.TempDir(), "extensions")

0 commit comments

Comments
 (0)