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

feat: add json api end-point with versions list #70

Merged
merged 1 commit into from
May 16, 2022
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions unpub/lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,26 @@ class App {
return _okWithJson({'data': data.toJson()});
}

@Route.get('/packages/<name>.json')
Future<shelf.Response> getPackageVersions(
shelf.Request req, String name) async {
var package = await metaStore.queryPackage(name);
if (package == null) {
return _badRequest('package not exists', status: HttpStatus.notFound);
}

var versions = package.versions.map((v) => v.version).toList();
versions.sort((a, b) {
return semver.Version.prioritize(
semver.Version.parse(b), semver.Version.parse(a));
});

return _okWithJson({
'name': name,
'versions': versions,
});
}

@Route.get('/webapi/package/<name>/<version>')
Future<shelf.Response> getPackageDetail(
shelf.Request req, String name, String version) async {
Expand Down
1 change: 1 addition & 0 deletions unpub/lib/src/app.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.