Browse Source

Add required params to actions

master
Christian Fischer 9 months ago
parent
commit
b9bb8ec7f4
2 changed files with 16 additions and 36 deletions
  1. +2
    -1
      server/privileges.rkt
  2. +14
    -35
      server/resource.rkt

+ 2
- 1
server/privileges.rkt View File

@@ -11,7 +11,8 @@
(struct
action
(id
fun)
fun
req-params)
#:transparent)




+ 14
- 35
server/resource.rkt View File

@@ -115,65 +115,44 @@
#f)))




;; (define (no-access-action)
;; 'nothing)

(define no-access-action
(action "no-access"
(lambda ()
(lambda (_)
'no-access)))

;; (define (view-file data)
;; (file->string (hash-ref data 'path)
;; #:mode 'text))

;; (define (edit-file path contents)
;; (write-to-file contents
;; path
;; #:exists 'replace))

(define view-file
(action "view"
(lambda (data)
(lambda (data params)
(file->string (hash-ref data 'path) #:mode 'text))))

(define edit-file
(action "edit"
(lambda (data
#:contents c)
(write-to-file c
params)
(write-to-file (dict-ref params 'contents)
(hash-ref data 'path)
#:exists 'replace))))
#:exists 'replace))
'(contents)))


;; TODO the dbc should be passed as a Racket parameter rather than an action param


;; params should be provided as keyword arguments
(define view-metadata
(action "view"
(lambda (data
#:redis dbc)
(redis-bytes-get dbc
(hash-ref data 'key)))))
params)
(redis-bytes-get (dict-ref params 'dbc)
(hash-ref data 'key)))
'(dbc)))

(define edit-metadata
(action "edit"
(lambda (data
#:redis dbc
#:value value)
(redis-bytes-set! dbc
params)
(redis-bytes-set! (dict-ref params 'dbc)
(hash-ref data 'key)
value))))

;; (define (view-metadata dbc key)
;; (redis-bytes-get dbc key))

;; (define (edit-metadata dbc key value)
;; (redis-bytes-set! dbc key value))
(dict-ref params 'value)))
'(dbc value)))

(define dataset-file-data
(list (cons "no-access" no-access-action)


Loading…
Cancel
Save