Merge branch 'imagebin'

db4
Doug Coleman 2009-06-30 17:39:53 -05:00
commit 4d12592d34
2 changed files with 25 additions and 19 deletions

View File

@ -1,39 +1,45 @@
! 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 furnace.actions furnace.redirection
http.server.dispatchers db db.tuples db.types urls html.forms http http.server http.server.dispatchers
furnace.redirection multiline http namespaces ; io.directories io.encodings.utf8 io.files io.pathnames
kernel math.parser multiline namespaces sequences urls ;
IN: webapps.imagebin IN: webapps.imagebin
TUPLE: imagebin < dispatcher ; TUPLE: imagebin < dispatcher path n ;
TUPLE: image id path ;
image "IMAGE" {
{ "id" "ID" INTEGER +db-assigned-id+ }
{ "path" "PATH" { VARCHAR 256 } +not-null+ }
} define-persistent
: <uploaded-image-action> ( -- action ) : <uploaded-image-action> ( -- action )
<page-action> <page-action>
{ imagebin "uploaded-image" } >>template ; { imagebin "uploaded-image" } >>template ;
SYMBOL: my-post-data : next-image-path ( -- path )
imagebin get
[ path>> ] [ n>> number>string ] bi append-path ;
M: imagebin call-responder*
[ imagebin set ] [ call-next-method ] bi ;
: move-image ( mime-file -- )
next-image-path
[ [ temporary-path>> ] dip move-file ]
[ [ filename>> ] dip ".txt" append utf8 set-file-contents ] 2bi ;
: <upload-image-action> ( -- action ) : <upload-image-action> ( -- action )
<page-action> <page-action>
{ imagebin "upload-image" } >>template { imagebin "upload-image" } >>template
[ [
"file1" param [ move-image ] when*
! request get post-data>> my-post-data set-global "file2" param [ move-image ] when*
! image new "file3" param [ move-image ] when*
! "file" value
! insert-tuple
"uploaded-image" <redirect> "uploaded-image" <redirect>
] >>submit ; ] >>submit ;
: <imagebin> ( -- responder ) : <imagebin> ( image-directory -- responder )
imagebin new-dispatcher imagebin new-dispatcher
swap [ make-directories ] [ >>path ] bi
0 >>n
<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 ;
"resource:images" <imagebin> main-responder set-global

View File

@ -2,6 +2,6 @@
<html> <html>
<head><title>Uploaded</title></head> <head><title>Uploaded</title></head>
<body> <body>
hi from uploaded-image You uploaded something!
</body> </body>
</html> </html>