Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6389071

Browse files
Add correct vspackage endpoint
See #57
1 parent 71f29f1 commit 6389071

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

‎CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Fixed
11+
12+
- The "attempt to download manually" URL in VS Code will now work.
13+
1014
## [2.2.0](https://github.com/coder/code-marketplace/releases/tag/v2.2.0) - 2024年07月17日
1115

1216
### Changed

‎api/api.go

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

122122
// This is the "download manually" URL, which like /assets is hardcoded and
123-
// ignores the VSIX asset URL provided to VS Code in the response.
123+
// ignores the VSIX asset URL provided to VS Code in the response. We provide
124+
// it at /publishers for backwards compatibility since that is where we
125+
// originally had it, but VS Code appends to the service URL which means the
126+
// path VS Code actually uses is /api/publishers.
127+
// https://github.com/microsoft/vscode/blob/c727b5484ebfbeff1e1d29654cae5c17af1c826f/build/lib/extensions.ts#L228
124128
r.Get("/publishers/{publisher}/vsextensions/{extension}/{version}/{type}", api.assetRedirect)
129+
r.Get("/api/publishers/{publisher}/vsextensions/{extension}/{version}/{type}", api.assetRedirect)
125130

126131
// This is the URL you get taken to when you click the extension's names,
127132
// ratings, etc from the extension details page.

‎api/api_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestAPI(t *testing.T) {
3636
Request any
3737
Response any
3838
Status int
39+
Method string
3940
}{
4041
{
4142
Name: "Root",
@@ -216,6 +217,7 @@ func TestAPI(t *testing.T) {
216217
Status: http.StatusMovedPermanently,
217218
Response: "/files/publisher/extension/version@darwin-x64/foo",
218219
},
220+
// Old vspackage path, for backwards compatibility.
219221
{
220222
Name: "DownloadNotExist",
221223
Path: "/publishers/notexist/vsextensions/extension/version/vspackage",
@@ -231,6 +233,24 @@ func TestAPI(t *testing.T) {
231233
Status: http.StatusMovedPermanently,
232234
Response: "/files/publisher/extension/version/extension.vsix",
233235
},
236+
// The vspackage path currently generated by VS Code.
237+
{
238+
Name: "APIDownloadNotExist",
239+
Path: "/api/publishers/notexist/vsextensions/extension/version/vspackage",
240+
Status: http.StatusNotFound,
241+
Response: &httpapi.ErrorResponse{
242+
Message: "Extension asset does not exist",
243+
Detail: "Please check the asset path",
244+
},
245+
Method: http.MethodGet,
246+
},
247+
{
248+
Name: "APIDownloadOK",
249+
Path: "/api/publishers/publisher/vsextensions/extension/version/vspackage",
250+
Status: http.StatusMovedPermanently,
251+
Response: "/files/publisher/extension/version/extension.vsix",
252+
Method: http.MethodGet,
253+
},
234254
{
235255
Name: "Item",
236256
Path: "/item",
@@ -273,9 +293,19 @@ func TestAPI(t *testing.T) {
273293
},
274294
}
275295

296+
// Most /api calls are POSTs, the rest are GETs.
297+
var method = c.Method
298+
if method == "" {
299+
if strings.HasPrefix(c.Path, "/api") {
300+
method = http.MethodPost
301+
} else {
302+
method = http.MethodGet
303+
}
304+
}
305+
276306
var resp *http.Response
277307
var err error
278-
if strings.HasPrefix(c.Path, "/api") {
308+
if method==http.MethodPost {
279309
var body []byte
280310
if str, ok := c.Request.(string); ok {
281311
body = []byte(str)
@@ -284,8 +314,10 @@ func TestAPI(t *testing.T) {
284314
require.NoError(t, err)
285315
}
286316
resp, err = client.Post(url, "application/json", bytes.NewReader(body))
287-
} else {
317+
} else ifmethod==http.MethodGet{
288318
resp, err = client.Get(url)
319+
} else {
320+
t.Fatal(method + " is not handled in the test yet, please add it now")
289321
}
290322
require.NoError(t, err)
291323
require.Equal(t, c.Status, resp.StatusCode)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /