07f05e52b56a337ecce59fc361bf820c1028609e — Vincent Lee a month ago 0d20b12
Expose attachment-data to sandbox, move db save error handling so that we can distinguish nothing to save vs error saving
2 files changed, 9 insertions(+), 3 deletions(-)

M main.rkt
M trick-db.rkt
M main.rkt => main.rkt +8 -1
@@ 274,6 274,7 @@
(define/contract (make-attachment data name type)
  (-> bytes? (or/c string? bytes?) (or/c symbol? string? bytes?) http:attachment?)
  (http:attachment data (~a type) name))

(define/contract ((call-subtrick client db context-id message parent-ctx) name arguments)
  (-> rc:client? db:trickdb? string? jsexpr? any/c (-> (or/c symbol? string?) any/c any))
  (let ([trick (db:get-trick db context-id (~a name))])

@@ 378,6 379,7 @@
            (emote-image      . ,emote-image)
            (delete-caller    . ,(thunk (thread-send deleter-thread (cons client message))))
            (make-attachment  . ,make-attachment)
            (attachment-data  . ,http:attachment-data)
            (call-trick       . ,(call-subtrick client db context-id message placeholder))
            (message-author   . ,(message-author-id message))
            (read-storage     . ,(curry read-storage trick message))

@@ 409,7 411,12 @@
    ("help"     . ,(const help))
    ("popular"  . ,popular-tricks)
    ("register" . ,register-trick)
    ("save"     . ,(lambda (client db msg text) (if (db:commit-db! db trick->json) "Saved" "Nothing to save or error saving")))
    ("save"     . ,(lambda (_client db _msg _text)
                     (with-handlers ([exn:fail? (lambda (e)
                                                  (~a "Error saving tricks: " e))])
                       (if (db:commit-db! db trick->json)
                           "Nothing to save"))))
    ("show"     . ,show-trick)
    ("update"   . ,update-trick)
    ("stats"   . ,stats)))

M trick-db.rkt => trick-db.rkt +1 -2
@@ 130,8 130,7 @@
(define (commit-db! db trick->json)
  (with-db-lock db
    (and (trickdb-dirty db)
         (with-handlers ((exn:fail? (lambda (e)
                                      (log-r16-error (~a "Error saving tricks: " e)) #f)))
           (save (trickdb-data db) trick->json (trickdb-filename db))
           (set-trickdb-dirty! db #f)