Support downloading of attachments.
[software/mumi.git] / mumi / web / controller.scm
index 5d9ea17b404c01a4381dcb4494a71112c8db71bb..ad6c63af6dfb787f7c8c10d4e2ee3e0333765723 100644 (file)
@@ -24,6 +24,7 @@
   #:use-module (web uri)
   #:use-module (mumi messages)
   #:use-module (mumi web render)
+  #:use-module (mumi web download)
   #:use-module (mumi web util)
   #:use-module (mumi web view html)
   #:export (controller))
           (lambda ()
             (list-of-matching-bugs query
                                    (match (process-query query)
+                                     ((#:terms terms
+                                       #:attributes attrs
+                                       #:filters '())
+                                      (search-bugs (string-join terms)
+                                                   #:attributes attrs))
+                                     ;; Fetch more messages if there
+                                     ;; are local filters to increase
+                                     ;; the chance of finding some
+                                     ;; that pass the filter.
                                      ((#:terms terms
                                        #:attributes attrs
                                        #:filters fs)
-                                      (filter (lambda (bug)
-                                                (every (lambda (f) (f bug)) fs))
-                                              (search-bugs (string-join terms)
-                                                           #:attributes attrs))))))
+                                      (let ((str (string-join terms)))
+                                        (filter (lambda (bug)
+                                                  (every (lambda (f) (f bug)) fs))
+                                                (search-bugs (string-join terms)
+                                                             #:attributes attrs
+                                                             #:max 800)))))))
           `(p "Could not search for " (strong ,query) "."))))))
     ((GET "issue" (? string->number id))
      (render-with-error-handling
       (lambda () (or (and=> (fetch-bug id) issue-page)
                 (unknown id)))
       `(p "Could not access issue #" (strong ,id) ".")))
+    ((GET "issue" (? string->number id)
+          "attachment" (? string->number msg-num)
+          (? string->number path) ...)
+     (handle-download (string->number id)
+                      (string->number msg-num)
+                      (map string->number path)))
     ((GET "issue" not-an-id)
      (apply render-html (unknown not-an-id)))
+    ((GET "help")
+     (apply render-html (help)))
     ((GET path ...)
      (render-static-asset request))))