2121import org .eclipse .openvsx .util .NotFoundException ;
2222import org .eclipse .openvsx .util .TargetPlatform ;
2323import org .eclipse .openvsx .util .UrlUtil ;
24+ import org .springframework .http .CacheControl ;
2425import org .springframework .http .HttpStatus ;
2526import org .springframework .http .MediaType ;
2627import org .springframework .http .ResponseEntity ;
3233
3334import java .util .ArrayList ;
3435import java .util .List ;
36+ import java .util .Optional ;
37+ import java .util .concurrent .TimeUnit ;
3538
3639import static org .eclipse .openvsx .adapter .ExtensionQueryParam .*;
3740import static org .eclipse .openvsx .adapter .ExtensionQueryResult .ExtensionFile .*;
3841import static org .eclipse .openvsx .util .TargetPlatform .*;
39- import static org .eclipse .openvsx .util .TargetPlatform .NAME_UNIVERSAL ;
4042
4143@ RestController
4244public class VSCodeAPI {
@@ -325,7 +327,7 @@ public ResponseEntity<StreamingResponseBody> browse(
325327 description = "The specified extension could not be found" ,
326328 content = @ Content ()
327329 )
328- public ExtensionQueryResult .Extension getLatest (
330+ public ResponseEntity < ExtensionQueryResult .Extension > getLatest (
329331 @ PathVariable @ Parameter (description = "Extension namespace" , example = "malloydata" ) String namespaceName ,
330332 @ PathVariable @ Parameter (description = "Extension name" , example = "malloy-vscode" ) String extensionName
331333 ) {
@@ -335,15 +337,17 @@ public ExtensionQueryResult.Extension getLatest(
335337 int flags = FLAG_INCLUDE_VERSIONS | FLAG_INCLUDE_ASSET_URI | FLAG_INCLUDE_VERSION_PROPERTIES | FLAG_INCLUDE_FILES | FLAG_INCLUDE_STATISTICS ;
336338 var param = new ExtensionQueryParam (List .of (filter ), flags );
337339 var result = extensionQueryRequestHandler .getResult (param , 1 , DEFAULT_PAGE_SIZE );
338- if (result .results ().isEmpty ()) {
339- throw new NotFoundException ();
340- }
341-
342- var extensions = result .results ().get (0 ).extensions ();
343- if (extensions .isEmpty ()) {
344- throw new NotFoundException ();
345- }
340+ var extension = Optional .of (result )
341+ .filter (r -> !r .results ().isEmpty ())
342+ .map (r -> r .results ().get (0 ).extensions ())
343+ .filter (e -> !e .isEmpty ())
344+ .map (e -> e .get (0 ))
345+ .orElse (null );
346346
347- return extensions .get (0 );
347+ return extension != null
348+ ? ResponseEntity .ok ()
349+ .cacheControl (CacheControl .maxAge (10 , TimeUnit .MINUTES ).cachePublic ())
350+ .body (extension )
351+ : ResponseEntity .notFound ().build ();
348352 }
349353}
0 commit comments