]> gitweb.factorcode.org Git - factor.git/commitdiff
working on imagebin
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 30 Jun 2009 19:56:58 +0000 (14:56 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 30 Jun 2009 19:56:58 +0000 (14:56 -0500)
extra/webapps/imagebin/imagebin.factor

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