breadcrumps, todos, etc.

This commit is contained in:
2026-08-15 01:46:15 +02:00
parent b3afd64769
commit ea7cd45eed
11 changed files with 635 additions and 27 deletions
+46
View File
@@ -192,6 +192,44 @@ CSS
(λ (_session)
(json-response (hash 'items (list-todos config))))))
(define (recent-list-handler config req)
(require-role
config req 'reader
(λ (_session)
(json-response (hash 'pages (list-recent-pages config))))))
(define (bookmark-list-handler config req)
(require-role
config req 'reader
(λ (session)
(define user-id (wiki-user-id (wiki-session-user session)))
(json-response (hash 'bookmarks (list-bookmarks config user-id))))))
(define (bookmark-save-handler config req)
(require-write-role
config req 'reader
(λ (session)
(with-handlers ((exn:fail? (λ (e) (json-error 400 (exn-message e)))))
(define body (request-json req))
(define slug (hash-ref body 'slug ""))
(define section (hash-ref body 'section ""))
(unless (string? slug)
(raise-argument-error 'bookmark-save-handler "string?" slug))
(unless (string? section)
(raise-argument-error 'bookmark-save-handler "string?" section))
(define user-id (wiki-user-id (wiki-session-user session)))
(set-bookmark! config user-id slug section)
(json-response (hash 'ok #t))))))
(define (bookmark-delete-handler config req slug)
(require-write-role
config req 'reader
(λ (session)
(define user-id (wiki-user-id (wiki-session-user session)))
(delete-bookmark! config user-id slug)
(json-response (hash 'ok #t)))))
(define (translations-handler config req)
(require-role
config req 'reader
@@ -471,6 +509,14 @@ CSS
(λ (req) (translations-handler config req))]
[("api" "todos") #:method "get"
(λ (req) (todo-list-handler config req))]
[("api" "recent") #:method "get"
(λ (req) (recent-list-handler config req))]
[("api" "bookmarks") #:method "get"
(λ (req) (bookmark-list-handler config req))]
[("api" "bookmarks") #:method "post"
(λ (req) (bookmark-save-handler config req))]
[("api" "bookmarks" (string-arg)) #:method "delete"
(λ (req slug) (bookmark-delete-handler config req slug))]
[("api" "search") #:method "get"
(λ (req) (search-handler config req))]
[("api" "pages") #:method "get"