diff options
-rw-r--r-- | guix-web/controller.scm | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/guix-web/controller.scm b/guix-web/controller.scm index b3104fe..fa7dfc3 100644 --- a/guix-web/controller.scm +++ b/guix-web/controller.scm @@ -17,7 +17,9 @@ (define-module (guix-web controller) #:use-module (ice-9 match) + #:use-module (ice-9 regex) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) #:use-module (web request) #:use-module (gnu packages) #:use-module (guix-web render) @@ -26,6 +28,12 @@ #:use-module (guix-web package) #:export (controller)) +(define extract-package-name + (let ((regexp (make-regexp "^(.*)\\.json$"))) + (lambda (path-part) + (and=> (regexp-exec regexp path-part) + (cut match:substring <> 1))))) + (define controller (match-lambda ((GET) @@ -34,15 +42,8 @@ (render-html (all-packages))) ((GET "packages.json") (render-json (all-packages-json))) - ((GET "packages" name) - (match (string-split name #\.) - ((name ext) - (render-json - (if (string=? ext "json") - (view-package-json name) - '()))) - ((name) - (render-html (view-package name))))) + ((GET "package" (= extract-package-name (? string? name))) + (render-json (view-package-json name))) ((POST "packages" name "install") (let ((package (car (find-packages-by-name name)))) (if (package-install package) |