switch to hash representation, closes #3; add timestamp
This commit is contained in:
parent
5c1c10c0c6
commit
06b0e4762b
|
@ -1,7 +1,16 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
|
(require racket/date racket/match)
|
||||||
(provide (all-defined-out))
|
(provide (all-defined-out))
|
||||||
|
|
||||||
(define ++ string-append)
|
(define ++ string-append)
|
||||||
|
|
||||||
(define (mk-rand-str)
|
(define (mk-rand-str)
|
||||||
(bytes->string/utf-8 (list->bytes (for/list ([n 4]) (+ 49 (random 9))))))
|
(bytes->string/utf-8 (list->bytes (for/list ([n 4]) (+ 49 (random 9))))))
|
||||||
|
|
||||||
|
(define (get-time/iso8601)
|
||||||
|
(parameterize ([date-display-format 'iso-8601])
|
||||||
|
(match-define (list _ date time)
|
||||||
|
(regexp-match
|
||||||
|
#px"(\\d\\d\\d\\d-\\d\\d-\\d\\d)[MTWFS](\\d\\d:\\d\\d:\\d\\d)"
|
||||||
|
(date->string (current-date) #t)))
|
||||||
|
(++ date " " time)))
|
||||||
|
|
|
@ -31,12 +31,12 @@
|
||||||
(define NUM-RECENT-PASTES 10)
|
(define NUM-RECENT-PASTES 10)
|
||||||
(define recent-pastes (empty-ring-buffer NUM-RECENT-PASTES))
|
(define recent-pastes (empty-ring-buffer NUM-RECENT-PASTES))
|
||||||
;; initialize buffer with some pastes
|
;; initialize buffer with some pastes
|
||||||
(ring-buffer-push! recent-pastes "9842")
|
(ring-buffer-push! recent-pastes "9965")
|
||||||
(ring-buffer-push! recent-pastes "4548")
|
(ring-buffer-push! recent-pastes "3542")
|
||||||
(ring-buffer-push! recent-pastes "9921")
|
(ring-buffer-push! recent-pastes "3414")
|
||||||
(ring-buffer-push! recent-pastes "9937")
|
(ring-buffer-push! recent-pastes "5237")
|
||||||
(ring-buffer-push! recent-pastes "1192")
|
(ring-buffer-push! recent-pastes "9647")
|
||||||
(ring-buffer-push! recent-pastes "9111")
|
(ring-buffer-push! recent-pastes "5434")
|
||||||
|
|
||||||
;; returns output file name (as path), or #f on fail
|
;; returns output file name (as path), or #f on fail
|
||||||
(define (write-codeblock-scrbl-file code)
|
(define (write-codeblock-scrbl-file code)
|
||||||
|
@ -139,7 +139,9 @@
|
||||||
(define eval-html-str (and html-res (generate-eval-html pasted-code)))
|
(define eval-html-str (and html-res (generate-eval-html pasted-code)))
|
||||||
(define paste-url (mk-paste-url paste-num))
|
(define paste-url (mk-paste-url paste-num))
|
||||||
(ring-buffer-push! recent-pastes paste-num)
|
(ring-buffer-push! recent-pastes paste-num)
|
||||||
(SET/list paste-num (list paste-html-str (or eval-html-str "")))
|
(SET/hash paste-num (hash 'code paste-html-str
|
||||||
|
'eval (or eval-html-str "")
|
||||||
|
'time (get-time/iso8601)))
|
||||||
(response/xexpr
|
(response/xexpr
|
||||||
`(html ()
|
`(html ()
|
||||||
(head ()
|
(head ()
|
||||||
|
@ -160,16 +162,18 @@
|
||||||
(with-input-from-bytes html-bytes read-xml))))))))
|
(with-input-from-bytes html-bytes read-xml))))))))
|
||||||
|
|
||||||
(define (serve-paste request pastenum)
|
(define (serve-paste request pastenum)
|
||||||
(define retrieved-paste (GET/list pastenum))
|
(define retrieved-paste-hash (GET/hash pastenum #:map-key bytes->symbol))
|
||||||
(cond
|
(cond
|
||||||
[(null? retrieved-paste)
|
[(equal? (hash) retrieved-paste-hash)
|
||||||
(response/xexpr
|
(response/xexpr
|
||||||
`(html() (head ())
|
`(html() (head ())
|
||||||
(body ()
|
(body ()
|
||||||
,(format "Paste # ~a doesn't exist." pastenum) (br)
|
,(format "Paste # ~a doesn't exist." pastenum) (br)
|
||||||
,(mk-link pastebin-url "Go Back"))))]
|
,(mk-link pastebin-url "Go Back"))))]
|
||||||
[else
|
[else
|
||||||
(match-define (list code-html eval-html) (GET/list pastenum))
|
(match-define (hash-table ('code code-html)
|
||||||
|
('eval eval-html)
|
||||||
|
('time time-str)) retrieved-paste-hash)
|
||||||
(define code-main-div (get-main-div code-html))
|
(define code-main-div (get-main-div code-html))
|
||||||
(define eval-main-div (get-main-div eval-html))
|
(define eval-main-div (get-main-div eval-html))
|
||||||
(define paste-url (string-append paste-url-base pastenum))
|
(define paste-url (string-append paste-url-base pastenum))
|
||||||
|
@ -187,8 +191,9 @@
|
||||||
(title "default") (type "text/css")))
|
(title "default") (type "text/css")))
|
||||||
(script ((src "/scribble-common.js") (type "text/javascript"))))
|
(script ((src "/scribble-common.js") (type "text/javascript"))))
|
||||||
(body ()
|
(body ()
|
||||||
,(mk-link pastebin-url "PasteRack") (br)
|
(div () ,(mk-link pastebin-url "Paste")
|
||||||
" Paste # " (a ((href ,paste-url)) ,pastenum) (br)
|
" # " (a ((href ,paste-url)) ,pastenum) (br)
|
||||||
|
(small ,(bytes->string/utf-8 time-str)) (br))
|
||||||
(div ((class "maincolumn"))
|
(div ((class "maincolumn"))
|
||||||
,(match code-main-div
|
,(match code-main-div
|
||||||
[`(div ((class "main")) ,ver ,body)
|
[`(div ((class "main")) ,ver ,body)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user