Pastebin now uses in-memory persistence as store is broken. Will use db soon
parent
39e4253292
commit
5f2655747a
|
@ -1 +0,0 @@
|
|||
Doug Coleman
|
|
@ -1 +0,0 @@
|
|||
Doug Coleman
|
|
@ -1,22 +0,0 @@
|
|||
! Copyright (C) 2006 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: assocs kernel io io.files namespaces serialize ;
|
||||
IN: store.blob
|
||||
|
||||
: (save-blob) serialize ;
|
||||
|
||||
: save-blob ( obj path -- )
|
||||
<file-appender> [ (save-blob) ] with-stream ;
|
||||
|
||||
: (load-blob) ( path -- seq/f )
|
||||
dup exists? [
|
||||
<file-reader> [
|
||||
deserialize-sequence
|
||||
] with-stream
|
||||
] [
|
||||
drop f
|
||||
] if ;
|
||||
|
||||
: load-blob ( path -- seq/f )
|
||||
resource-path (load-blob) ;
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
USING: assocs continuations debugger io.files kernel
|
||||
namespaces store tools.test ;
|
||||
IN: temporary
|
||||
|
||||
SYMBOL: store
|
||||
SYMBOL: foo
|
||||
|
||||
: the-store ( -- path )
|
||||
"store-test.store" resource-path ;
|
||||
|
||||
: delete-the-store ( -- )
|
||||
[ the-store delete-file ] catch drop ;
|
||||
|
||||
: load-the-store ( -- )
|
||||
the-store load-store store set-global ;
|
||||
|
||||
: save-the-store ( -- )
|
||||
store save-store ;
|
||||
|
||||
delete-the-store
|
||||
load-the-store
|
||||
|
||||
[ f ] [ foo store get-persistent ] unit-test
|
||||
|
||||
USE: prettyprint
|
||||
store get-global store-data .
|
||||
|
||||
[ ] [ 100 foo store set-persistent ] unit-test
|
||||
|
||||
[ ] [ save-the-store ] unit-test
|
||||
|
||||
[ 100 ] [ foo store get-persistent ] unit-test
|
||||
|
||||
delete-the-store
|
||||
f store set-global
|
|
@ -1,33 +0,0 @@
|
|||
! Copyright (C) 2006, 2007 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: assocs io io.files kernel namespaces serialize init ;
|
||||
IN: store
|
||||
|
||||
TUPLE: store path data ;
|
||||
|
||||
C: <store> store
|
||||
|
||||
: save-store ( store -- )
|
||||
get-global dup store-data swap store-path
|
||||
<file-writer> [ serialize ] with-stream ;
|
||||
|
||||
: load-store ( path -- store )
|
||||
dup exists? [
|
||||
dup <file-reader> [ deserialize ] with-stream
|
||||
] [
|
||||
H{ } clone
|
||||
] if <store> ;
|
||||
|
||||
: define-store ( path id -- )
|
||||
over >r
|
||||
[ >r resource-path load-store r> set-global ] 2curry
|
||||
r> add-init-hook ;
|
||||
|
||||
: get-persistent ( key store -- value )
|
||||
get-global store-data at ;
|
||||
|
||||
: set-persistent ( value key store -- )
|
||||
[ get-global store-data set-at ] keep save-store ;
|
||||
|
||||
: init-persistent ( value key store -- )
|
||||
2dup get-persistent [ 3drop ] [ set-persistent ] if ;
|
|
@ -1,6 +1,6 @@
|
|||
USING: calendar furnace furnace.validator io.files kernel
|
||||
namespaces sequences store http.server.responders html
|
||||
math.parser rss xml.writer xmode.code2html ;
|
||||
namespaces sequences http.server.responders html math.parser rss
|
||||
xml.writer xmode.code2html ;
|
||||
IN: webapps.pastebin
|
||||
|
||||
TUPLE: pastebin pastes ;
|
||||
|
@ -8,11 +8,7 @@ TUPLE: pastebin pastes ;
|
|||
: <pastebin> ( -- pastebin )
|
||||
V{ } clone pastebin construct-boa ;
|
||||
|
||||
! Persistence
|
||||
SYMBOL: store
|
||||
|
||||
"pastebin.store" store define-store
|
||||
<pastebin> pastebin store init-persistent
|
||||
<pastebin> pastebin set-global
|
||||
|
||||
TUPLE: paste
|
||||
summary author channel mode contents date
|
||||
|
@ -25,11 +21,8 @@ TUPLE: annotation summary author mode contents ;
|
|||
|
||||
C: <annotation> annotation
|
||||
|
||||
: get-pastebin ( -- pastebin )
|
||||
pastebin store get-persistent ;
|
||||
|
||||
: get-paste ( n -- paste )
|
||||
get-pastebin pastebin-pastes nth ;
|
||||
pastebin get pastebin-pastes nth ;
|
||||
|
||||
: show-paste ( n -- )
|
||||
serving-html
|
||||
|
@ -49,7 +42,7 @@ C: <annotation> annotation
|
|||
[
|
||||
[ show-paste ] "show-paste-quot" set
|
||||
[ new-paste ] "new-paste-quot" set
|
||||
get-pastebin "paste-list" render-component
|
||||
pastebin get "paste-list" render-component
|
||||
] with-html-stream ;
|
||||
|
||||
\ paste-list { } define-action
|
||||
|
@ -61,7 +54,7 @@ C: <annotation> annotation
|
|||
over length min head ;
|
||||
|
||||
: paste-feed ( -- entries )
|
||||
get-pastebin pastebin-pastes <reversed> 20 safe-head [
|
||||
pastebin get pastebin-pastes <reversed> 20 safe-head [
|
||||
{
|
||||
paste-summary
|
||||
paste-link
|
||||
|
@ -82,10 +75,8 @@ C: <annotation> annotation
|
|||
pastebin-pastes 2dup length swap set-paste-n push ;
|
||||
|
||||
: submit-paste ( summary author channel mode contents -- )
|
||||
<paste> [
|
||||
pastebin store get-persistent add-paste
|
||||
store save-store
|
||||
] keep paste-link permanent-redirect ;
|
||||
<paste> [ pastebin get add-paste ] keep
|
||||
paste-link permanent-redirect ;
|
||||
|
||||
\ new-paste
|
||||
\ submit-paste {
|
||||
|
|
Loading…
Reference in New Issue