working on imagebin

db4
Doug Coleman 2009-06-30 14:56:58 -05:00
parent 1fab8efeee
commit fefea85514
1 changed files with 18 additions and 5 deletions

View File

@ -1,10 +1,15 @@
! Copyright (C) 2008 Doug Coleman. ! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel furnace.actions html.forms USING: accessors db db.tuples db.types furnace.actions
http.server.dispatchers db db.tuples db.types urls furnace.redirection html.forms http http.server
furnace.redirection multiline http namespaces ; http.server.dispatchers io.directories io.pathnames kernel
multiline namespaces urls ;
IN: webapps.imagebin IN: webapps.imagebin
SYMBOL: image-directory
image-directory [ "resource:images" ] initialize
TUPLE: imagebin < dispatcher ; TUPLE: imagebin < dispatcher ;
TUPLE: image id path ; TUPLE: image id path ;
@ -16,24 +21,32 @@ image "IMAGE" {
: <uploaded-image-action> ( -- action ) : <uploaded-image-action> ( -- action )
<page-action> <page-action>
image-directory get >>temporary-directory
{ imagebin "uploaded-image" } >>template ; { imagebin "uploaded-image" } >>template ;
SYMBOL: my-post-data SYMBOL: my-post-data
: <upload-image-action> ( -- action ) : <upload-image-action> ( -- action )
<page-action> <page-action>
{ imagebin "upload-image" } >>template { imagebin "upload-image" } >>template
image-directory get >>temporary-directory
[ [
"file1" param [
! request get post-data>> my-post-data set-global temporary-path>> image-directory get move-file
] when*
! image new ! image new
! "file" value ! "file" value
! insert-tuple ! insert-tuple
"uploaded-image" <redirect> "uploaded-image" <redirect>
] >>submit ; ] >>submit ;
: initialize-image-directory ( -- )
image-directory get make-directories ;
: <imagebin> ( -- responder ) : <imagebin> ( -- responder )
imagebin new-dispatcher imagebin new-dispatcher
<upload-image-action> "" add-responder <upload-image-action> "" add-responder
<upload-image-action> "upload-image" add-responder <upload-image-action> "upload-image" add-responder
<uploaded-image-action> "uploaded-image" add-responder ; <uploaded-image-action> "uploaded-image" add-responder ;
initialize-image-directory
<imagebin> main-responder set-global