aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMathieu Othacehe <m.othacehe@gmail.com>2020-06-21 12:56:50 +0200
committerMathieu Othacehe <m.othacehe@gmail.com>2020-06-21 12:56:50 +0200
commit61cc56f6cc9ac4985c0013968af43e4da70aa954 (patch)
treecb5b26d573f4da6afb2c65cc3d6d1df584e218d5 /src
parent3db603c1913fe14d260a44b05575a2ead3866b47 (diff)
downloadcuirass-61cc56f6cc9ac4985c0013968af43e4da70aa954.tar
cuirass-61cc56f6cc9ac4985c0013968af43e4da70aa954.tar.gz
http: Add /search/latest and /search/latest/<product-type> routes.
* src/cuirass/http.scm (url-handler): Add "/search/latest" and "/search/latest/<product-type>" routes.
Diffstat (limited to 'src')
-rw-r--r--src/cuirass/http.scm54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index 4da36bc..ddf63df 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -516,6 +516,60 @@ Hydra format."
query))
(respond-json-with-error 500 "Query parameter not provided!"))))
+ (('GET "search" "latest")
+ (let* ((params (request-parameters request))
+ (query (and=> (assq-ref params 'query) uri-decode)))
+ (if query
+ (match (vector->list
+ (handle-builds-search-request
+ `((query . ,query)
+ (nr . 1)
+ (order . finish-time+build-id))))
+ ((build)
+ (let ((uri (string->uri-reference
+ (string-append "/build/"
+ (number->string
+ (assoc-ref build #:id))
+ "/details"))))
+ (respond (build-response #:code 302
+ #:headers `((location . ,uri)))
+ #:body "")))
+ (_
+ (respond-json-with-error 500 "No build found.")))
+ (respond-json-with-error 500 "Query parameter not provided."))))
+
+ (('GET "search" "latest" product-type)
+ (let* ((params (request-parameters request))
+ (query (and=> (assq-ref params 'query) uri-decode)))
+ (if query
+ (match (vector->list
+ (handle-builds-search-request
+ `((query . ,query)
+ (nr . 1)
+ (order . finish-time+build-id))))
+ ((build)
+ (let* ((build-id (assoc-ref build #:id))
+ (products (db-get-build-products build-id))
+ (product (find (lambda (product)
+ (string=? (assoc-ref product #:type)
+ product-type))
+ products))
+ (product-id (assoc-ref product #:id))
+ (uri (and product-id
+ (string->uri-reference
+ (string-append "/download/"
+ (number->string product-id))))))
+ (if uri
+ (respond (build-response #:code 302
+ #:headers `((location . ,uri)))
+ #:body "")
+ (respond-json-with-error
+ 500
+ "Could not find the request build product."))))
+ (_
+ (respond-json-with-error 500 "No build found.")))
+ (respond-json-with-error 500 "Query parameter not provided."))))
+
(('GET "download" id)
(let ((path (db-get-build-product-path id)))
(respond-file path)))