2009-01-20 12:44:14 -05:00
|
|
|
! 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 ;
|
2009-01-20 12:44:14 -05:00
|
|
|
IN: webapps.imagebin
|
|
|
|
|
|
2009-06-30 15:56:58 -04:00
|
|
|
SYMBOL: image-directory
|
|
|
|
|
|
|
|
|
|
image-directory [ "resource:images" ] initialize
|
|
|
|
|
|
2009-01-20 12:44:14 -05:00
|
|
|
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
|
2009-01-20 12:44:14 -05:00
|
|
|
{ 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-01-20 12:44:14 -05:00
|
|
|
[
|
2009-06-30 15:56:58 -04:00
|
|
|
"file1" param [
|
|
|
|
|
temporary-path>> image-directory get move-file
|
|
|
|
|
] when*
|
2009-01-20 12:44:14 -05:00
|
|
|
! image new
|
|
|
|
|
! "file" value
|
|
|
|
|
! insert-tuple
|
2009-01-20 17:34:46 -05:00
|
|
|
"uploaded-image" <redirect>
|
2009-01-20 12:44:14 -05:00
|
|
|
] >>submit ;
|
|
|
|
|
|
2009-06-30 15:56:58 -04:00
|
|
|
: initialize-image-directory ( -- )
|
|
|
|
|
image-directory get make-directories ;
|
|
|
|
|
|
2009-01-20 12:44:14 -05:00
|
|
|
: <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
|