]> gitweb.factorcode.org Git - factor.git/commitdiff
imagebin does the right thing now
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 30 Jun 2009 22:39:36 +0000 (17:39 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 30 Jun 2009 22:39:36 +0000 (17:39 -0500)
extra/webapps/imagebin/imagebin.factor
extra/webapps/imagebin/uploaded-image.xml

index 7c63c51eeec22f3cf745dc4f97434c9708f5b35d..bb8720466caa8f62e368a155f291ac05de1b495d 100755 (executable)
@@ -1,52 +1,45 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-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 ;
+USING: accessors furnace.actions furnace.redirection
+html.forms http http.server http.server.dispatchers
+io.directories io.encodings.utf8 io.files io.pathnames
+kernel math.parser multiline namespaces sequences urls ;
 IN: webapps.imagebin
 
-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
+TUPLE: imagebin < dispatcher path n ;
 
 : <uploaded-image-action> ( -- action )
     <page-action>
-        image-directory get >>temporary-directory
         { 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 )
     <page-action>
         { imagebin "upload-image" } >>template
-        image-directory get >>temporary-directory
         [
-            "file1" param [
-                temporary-path>> image-directory get move-file
-            ] when*
-            ! image new
-            !    "file" value
-                ! insert-tuple
+            "file1" param [ move-image ] when*
+            "file2" param [ move-image ] when*
+            "file3" param [ move-image ] when*
             "uploaded-image" <redirect>
         ] >>submit ;
 
-: initialize-image-directory ( -- )
-    image-directory get make-directories ;
-
-: <imagebin> ( -- responder )
+: <imagebin> ( image-directory -- responder )
     imagebin new-dispatcher
+        swap [ make-directories ] [ >>path ] bi
+        0 >>n
         <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
+"resource:images" <imagebin> main-responder set-global
index 903be5cca44686d9033a131bb11aa9ffd801a680..79dfabc924c27dee43c5232b5cdf49f950b17276 100644 (file)
@@ -2,6 +2,6 @@
 <html>
 <head><title>Uploaded</title></head>
 <body>
-hi from uploaded-image
+You uploaded something!
 </body>
 </html>