diff options
author | Christopher Baines <mail@cbaines.net> | 2020-02-29 19:39:20 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2020-02-29 19:39:20 +0000 |
commit | 3016f0548d294deb124c71edd31416521d7bdcae (patch) | |
tree | 9bfb1a2f691aa96cb5e610323a5b076200aace6b /guix-data-service | |
parent | 65f2f21d3acad30caf490e69c46f0c73e74c324c (diff) | |
download | data-service-3016f0548d294deb124c71edd31416521d7bdcae.tar data-service-3016f0548d294deb124c71edd31416521d7bdcae.tar.gz |
Redirect to the latest version of a file
Diffstat (limited to 'guix-data-service')
-rw-r--r-- | guix-data-service/web/dumps/controller.scm | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/guix-data-service/web/dumps/controller.scm b/guix-data-service/web/dumps/controller.scm index 840ee96..8f70837 100644 --- a/guix-data-service/web/dumps/controller.scm +++ b/guix-data-service/web/dumps/controller.scm @@ -20,6 +20,8 @@ #:use-module (ice-9 match) #:use-module (ice-9 ftw) #:use-module (ice-9 regex) + #:use-module (web uri) + #:use-module (web request) #:use-module (web response) #:use-module (guix-data-service config) #:use-module (guix-data-service web render) @@ -35,6 +37,8 @@ (('GET "dumps") (render-dumps request mime-types)) + (('GET "dumps" "latest" file) + (render-latest-dumps request file)) (('GET "dumps" _ ...) (list (build-response #:code 504) "requests for individual files should be handled before the request @@ -82,7 +86,26 @@ reaches the Guix Data Service")) (render-html #:sxml (view-dumps (available-dumps)))) - +(define (render-latest-dumps request file) + (or (any (match-lambda + ((date-string . files) + (if (member file files) + (let ((uri + (build-uri + #f + #:path (string-append + "/" + (encode-and-join-uri-path + (list "dumps" date-string file))) + #:validate? #f))) + (list (build-response + #:code 302 + #:headers `((content-type . (text/html)) + (location . ,uri))) + (format #f "Redirect to ~a" (uri->string uri)))) + #f))) + (available-dumps)) + (not-found (request-uri request)))) |