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
|
USING: calendar furnace furnace.validator io.files kernel
|
||||||
namespaces sequences store http.server.responders html
|
namespaces sequences http.server.responders html math.parser rss
|
||||||
math.parser rss xml.writer xmode.code2html ;
|
xml.writer xmode.code2html ;
|
||||||
IN: webapps.pastebin
|
IN: webapps.pastebin
|
||||||
|
|
||||||
TUPLE: pastebin pastes ;
|
TUPLE: pastebin pastes ;
|
||||||
|
@ -8,11 +8,7 @@ TUPLE: pastebin pastes ;
|
||||||
: <pastebin> ( -- pastebin )
|
: <pastebin> ( -- pastebin )
|
||||||
V{ } clone pastebin construct-boa ;
|
V{ } clone pastebin construct-boa ;
|
||||||
|
|
||||||
! Persistence
|
<pastebin> pastebin set-global
|
||||||
SYMBOL: store
|
|
||||||
|
|
||||||
"pastebin.store" store define-store
|
|
||||||
<pastebin> pastebin store init-persistent
|
|
||||||
|
|
||||||
TUPLE: paste
|
TUPLE: paste
|
||||||
summary author channel mode contents date
|
summary author channel mode contents date
|
||||||
|
@ -25,11 +21,8 @@ TUPLE: annotation summary author mode contents ;
|
||||||
|
|
||||||
C: <annotation> annotation
|
C: <annotation> annotation
|
||||||
|
|
||||||
: get-pastebin ( -- pastebin )
|
|
||||||
pastebin store get-persistent ;
|
|
||||||
|
|
||||||
: get-paste ( n -- paste )
|
: get-paste ( n -- paste )
|
||||||
get-pastebin pastebin-pastes nth ;
|
pastebin get pastebin-pastes nth ;
|
||||||
|
|
||||||
: show-paste ( n -- )
|
: show-paste ( n -- )
|
||||||
serving-html
|
serving-html
|
||||||
|
@ -49,7 +42,7 @@ C: <annotation> annotation
|
||||||
[
|
[
|
||||||
[ show-paste ] "show-paste-quot" set
|
[ show-paste ] "show-paste-quot" set
|
||||||
[ new-paste ] "new-paste-quot" set
|
[ new-paste ] "new-paste-quot" set
|
||||||
get-pastebin "paste-list" render-component
|
pastebin get "paste-list" render-component
|
||||||
] with-html-stream ;
|
] with-html-stream ;
|
||||||
|
|
||||||
\ paste-list { } define-action
|
\ paste-list { } define-action
|
||||||
|
@ -61,7 +54,7 @@ C: <annotation> annotation
|
||||||
over length min head ;
|
over length min head ;
|
||||||
|
|
||||||
: paste-feed ( -- entries )
|
: paste-feed ( -- entries )
|
||||||
get-pastebin pastebin-pastes <reversed> 20 safe-head [
|
pastebin get pastebin-pastes <reversed> 20 safe-head [
|
||||||
{
|
{
|
||||||
paste-summary
|
paste-summary
|
||||||
paste-link
|
paste-link
|
||||||
|
@ -82,10 +75,8 @@ C: <annotation> annotation
|
||||||
pastebin-pastes 2dup length swap set-paste-n push ;
|
pastebin-pastes 2dup length swap set-paste-n push ;
|
||||||
|
|
||||||
: submit-paste ( summary author channel mode contents -- )
|
: submit-paste ( summary author channel mode contents -- )
|
||||||
<paste> [
|
<paste> [ pastebin get add-paste ] keep
|
||||||
pastebin store get-persistent add-paste
|
paste-link permanent-redirect ;
|
||||||
store save-store
|
|
||||||
] keep paste-link permanent-redirect ;
|
|
||||||
|
|
||||||
\ new-paste
|
\ new-paste
|
||||||
\ submit-paste {
|
\ submit-paste {
|
||||||
|
|
Loading…
Reference in New Issue