factor/extra/webapps/imagebin/imagebin.factor

53 lines
1.5 KiB
Factor
Raw Normal View History

! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
2009-06-30 15:56:58 -04:00
USING: accessors db db.tuples db.types furnace.actions
furnace.redirection html.forms http http.server
http.server.dispatchers io.directories io.pathnames kernel
multiline namespaces urls ;
IN: webapps.imagebin
2009-06-30 15:56:58 -04:00
SYMBOL: image-directory
image-directory [ "resource:images" ] initialize
TUPLE: imagebin < dispatcher ;
TUPLE: image id path ;
image "IMAGE" {
{ "id" "ID" INTEGER +db-assigned-id+ }
{ "path" "PATH" { VARCHAR 256 } +not-null+ }
} define-persistent
: <uploaded-image-action> ( -- action )
<page-action>
2009-06-30 15:56:58 -04:00
image-directory get >>temporary-directory
{ imagebin "uploaded-image" } >>template ;
SYMBOL: my-post-data
: <upload-image-action> ( -- action )
<page-action>
{ imagebin "upload-image" } >>template
2009-06-30 15:56:58 -04:00
image-directory get >>temporary-directory
[
2009-06-30 15:56:58 -04:00
"file1" param [
temporary-path>> image-directory get move-file
] when*
! image new
! "file" value
! insert-tuple
2009-01-20 17:34:46 -05:00
"uploaded-image" <redirect>
] >>submit ;
2009-06-30 15:56:58 -04:00
: initialize-image-directory ( -- )
image-directory get make-directories ;
: <imagebin> ( -- responder )
imagebin new-dispatcher
<upload-image-action> "" add-responder
<upload-image-action> "upload-image" add-responder
<uploaded-image-action> "uploaded-image" add-responder ;
2009-06-30 15:56:58 -04:00
initialize-image-directory
<imagebin> main-responder set-global