Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getLatest endpoint #1037

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions server/src/main/java/org/eclipse/openvsx/adapter/VSCodeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

import java.util.ArrayList;
import java.util.List;

import static org.eclipse.openvsx.adapter.ExtensionQueryParam.*;
import static org.eclipse.openvsx.adapter.ExtensionQueryResult.ExtensionFile.*;
import static org.eclipse.openvsx.util.TargetPlatform.*;
import static org.eclipse.openvsx.util.TargetPlatform.NAME_UNIVERSAL;
Expand Down Expand Up @@ -304,4 +306,41 @@ public ResponseEntity<StreamingResponseBody> browse(

return ResponseEntity.notFound().build();
}

@GetMapping(
path = "/vscode/gallery/{namespaceName}/{extensionName}/latest",
produces = MediaType.APPLICATION_JSON_VALUE
)
@CrossOrigin
@Operation(summary = "Provides metadata of the extension matching the given parameters")
@ApiResponse(
responseCode = "200",
description = "Returns the extension metadata"
)
@ApiResponse(
responseCode = "404",
description = "The specified extension could not be found",
content = @Content()
)
public ExtensionQueryResult.Extension getLatest(
@PathVariable @Parameter(description = "Extension namespace", example = "malloydata") String namespaceName,
@PathVariable @Parameter(description = "Extension name", example = "malloy-vscode") String extensionName
) {
var extensionId = String.join(".", namespaceName, extensionName);
var criterion = new ExtensionQueryParam.Criterion(ExtensionQueryParam.Criterion.FILTER_EXTENSION_NAME, extensionId);
var filter = new ExtensionQueryParam.Filter(List.of(criterion), 0, 0, 0, 0);
int flags = FLAG_INCLUDE_VERSIONS | FLAG_INCLUDE_ASSET_URI | FLAG_INCLUDE_VERSION_PROPERTIES | FLAG_INCLUDE_FILES | FLAG_INCLUDE_STATISTICS;
var param = new ExtensionQueryParam(List.of(filter), flags);
var result = extensionQueryRequestHandler.getResult(param, 1, DEFAULT_PAGE_SIZE);
if(result.results().isEmpty()) {
throw new NotFoundException();
}

var extensions = result.results().get(0).extensions();
if(extensions.isEmpty()) {
throw new NotFoundException();
}

return extensions.get(0);
}
}