use of org.eclipse.openvsx.util.NotFoundException in project openvsx by eclipse.
the class LocalRegistryService method getNamespace.
@Override
public NamespaceJson getNamespace(String namespaceName) {
var namespace = repositories.findNamespace(namespaceName);
if (namespace == null)
throw new NotFoundException();
var json = new NamespaceJson();
json.name = namespace.getName();
json.extensions = new LinkedHashMap<>();
var serverUrl = UrlUtil.getBaseUrl();
for (var ext : repositories.findActiveExtensions(namespace)) {
String url = createApiUrl(serverUrl, "api", namespace.getName(), ext.getName());
json.extensions.put(ext.getName(), url);
}
json.verified = repositories.countMemberships(namespace, NamespaceMembership.ROLE_OWNER) > 0;
json.access = "restricted";
return json;
}
use of org.eclipse.openvsx.util.NotFoundException in project openvsx by eclipse.
the class VSCodeAdapter method download.
@GetMapping("/vscode/gallery/publishers/{namespace}/vsextensions/{extension}/{version}/vspackage")
@CrossOrigin
public ModelAndView download(@PathVariable String namespace, @PathVariable String extension, @PathVariable String version, ModelMap model) {
if (googleStorage.isEnabled()) {
var extVersion = repositories.findVersion(version, extension, namespace);
if (extVersion == null || !extVersion.isActive())
throw new NotFoundException();
var resource = repositories.findFileByType(extVersion, FileResource.DOWNLOAD);
if (resource == null)
throw new NotFoundException();
if (resource.getStorageType().equals(FileResource.STORAGE_GOOGLE)) {
storageUtil.increaseDownloadCount(extVersion, resource);
return new ModelAndView("redirect:" + storageUtil.getLocation(resource), model);
}
}
var serverUrl = UrlUtil.getBaseUrl();
return new ModelAndView("redirect:" + UrlUtil.createApiUrl(serverUrl, "vscode", "asset", namespace, extension, version, FILE_VSIX), model);
}
use of org.eclipse.openvsx.util.NotFoundException in project openvsx by eclipse.
the class LocalRegistryService method getFile.
@Override
public ResponseEntity<byte[]> getFile(String namespace, String extensionName, String version, String fileName) {
var extVersion = findVersion(namespace, extensionName, version);
if (extVersion == null || !extVersion.isActive())
throw new NotFoundException();
var resource = repositories.findFileByName(extVersion, fileName);
if (resource == null)
throw new NotFoundException();
if (resource.getType().equals(DOWNLOAD))
storageUtil.increaseDownloadCount(extVersion, resource);
if (resource.getStorageType().equals(FileResource.STORAGE_DB)) {
var headers = storageUtil.getFileResponseHeaders(fileName);
return new ResponseEntity<>(resource.getContent(), headers, HttpStatus.OK);
} else {
return ResponseEntity.status(HttpStatus.FOUND).location(storageUtil.getLocation(resource)).cacheControl(CacheControl.maxAge(7, TimeUnit.DAYS).cachePublic()).build();
}
}
use of org.eclipse.openvsx.util.NotFoundException in project openvsx by eclipse.
the class LocalRegistryService method getReviews.
@Override
public ReviewListJson getReviews(String namespace, String extensionName) {
var extension = repositories.findExtension(extensionName, namespace);
if (extension == null || !extension.isActive())
throw new NotFoundException();
var list = new ReviewListJson();
var serverUrl = UrlUtil.getBaseUrl();
list.postUrl = createApiUrl(serverUrl, "api", extension.getNamespace().getName(), extension.getName(), "review");
list.deleteUrl = createApiUrl(serverUrl, "api", extension.getNamespace().getName(), extension.getName(), "review", "delete");
list.reviews = repositories.findActiveReviews(extension).map(extReview -> extReview.toReviewJson()).toList();
return list;
}
use of org.eclipse.openvsx.util.NotFoundException in project openvsx by eclipse.
the class VSCodeAdapter method getAsset.
@GetMapping("/vscode/asset/{namespace}/{extensionName}/{version}/{assetType}/**")
@CrossOrigin
public ResponseEntity<byte[]> getAsset(HttpServletRequest request, @PathVariable String namespace, @PathVariable String extensionName, @PathVariable String version, @PathVariable String assetType) {
var restOfTheUrl = UrlUtil.extractWildcardPath(request);
var asset = (restOfTheUrl != null && restOfTheUrl.length() > 0) ? (assetType + "/" + restOfTheUrl) : assetType;
var extVersion = repositories.findVersion(version, extensionName, namespace);
if (extVersion == null || !extVersion.isActive())
throw new NotFoundException();
var resource = getFileFromDB(extVersion, asset);
if (resource == null)
throw new NotFoundException();
if (resource.getType().equals(FileResource.DOWNLOAD))
storageUtil.increaseDownloadCount(extVersion, resource);
if (resource.getStorageType().equals(FileResource.STORAGE_DB)) {
var headers = storageUtil.getFileResponseHeaders(resource.getName());
return new ResponseEntity<>(resource.getContent(), headers, HttpStatus.OK);
} else {
return ResponseEntity.status(HttpStatus.FOUND).location(storageUtil.getLocation(resource)).cacheControl(CacheControl.maxAge(7, TimeUnit.DAYS).cachePublic()).build();
}
}
Aggregations