]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/web/unlinked.py
webapi: handle format=, remove mutable-type=
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / web / unlinked.py
index 70faab963e07dee02302bfbfd6eaf2629df69f17..94dd0621ca98a94724e55a0a4d81a029ae46721b 100644 (file)
@@ -4,8 +4,9 @@ from twisted.web import http
 from twisted.internet import defer
 from nevow import rend, url, tags as T
 from allmydata.immutable.upload import FileHandle
+from allmydata.mutable.publish import MutableFileHandle
 from allmydata.web.common import getxmlfile, get_arg, boolean_of_arg, \
-     convert_children_json, WebError
+     convert_children_json, WebError, get_format, get_mutable_type
 from allmydata.web import status
 
 def PUTUnlinkedCHK(req, client):
@@ -16,17 +17,24 @@ def PUTUnlinkedCHK(req, client):
     # that fires with the URI of the new file
     return d
 
-def PUTUnlinkedSSK(req, client):
+def PUTUnlinkedSSK(req, client, version):
     # SDMF: files are small, and we can only upload data
     req.content.seek(0)
-    data = req.content.read()
-    d = client.create_mutable_file(data)
+    data = MutableFileHandle(req.content)
+    d = client.create_mutable_file(data, version=version)
     d.addCallback(lambda n: n.get_uri())
     return d
 
 def PUTUnlinkedCreateDirectory(req, client):
     # "PUT /uri?t=mkdir", to create an unlinked directory.
-    d = client.create_dirnode()
+    file_format = get_format(req, None)
+    if file_format == "CHK":
+        raise WebError("format=CHK not currently accepted for PUT /uri?t=mkdir",
+                       http.BAD_REQUEST)
+    mt = None
+    if file_format:
+        mt = get_mutable_type(file_format)
+    d = client.create_dirnode(version=mt)
     d.addCallback(lambda dirnode: dirnode.get_uri())
     # XXX add redirect_to_result
     return d
@@ -79,25 +87,38 @@ class UploadResultsPage(status.UploadResultsRendererMixin, rend.Page):
                       ["/uri/" + res.uri])
         return d
 
-def POSTUnlinkedSSK(req, client):
+def POSTUnlinkedSSK(req, client, version):
     # "POST /uri", to create an unlinked file.
     # SDMF: files are small, and we can only upload data
-    contents = req.fields["file"]
-    contents.file.seek(0)
-    data = contents.file.read()
-    d = client.create_mutable_file(data)
+    contents = req.fields["file"].file
+    data = MutableFileHandle(contents)
+    d = client.create_mutable_file(data, version=version)
     d.addCallback(lambda n: n.get_uri())
     return d
 
 def POSTUnlinkedCreateDirectory(req, client):
     # "POST /uri?t=mkdir", to create an unlinked directory.
-    req.content.seek(0)
-    kids_json = req.content.read()
-    if kids_json:
-        raise WebError("t=mkdir does not accept children=, "
-                       "try t=mkdir-with-children instead",
+    ct = req.getHeader("content-type") or ""
+    if not ct.startswith("multipart/form-data"):
+        # guard against accidental attempts to call t=mkdir as if it were
+        # t=mkdir-with-children, but make sure we tolerate the usual HTML
+        # create-directory form (in which the t=mkdir and redirect_to_result=
+        # and other arguments can be passed encoded as multipath/form-data,
+        # in the request body).
+        req.content.seek(0)
+        kids_json = req.content.read()
+        if kids_json:
+            raise WebError("t=mkdir does not accept children=, "
+                           "try t=mkdir-with-children instead",
+                           http.BAD_REQUEST)
+    file_format = get_format(req, None)
+    if file_format == "CHK":
+        raise WebError("format=CHK not currently accepted for POST /uri?t=mkdir",
                        http.BAD_REQUEST)
-    d = client.create_dirnode()
+    mt = None
+    if file_format:
+        mt = get_mutable_type(file_format)
+    d = client.create_dirnode(version=mt)
     redirect = get_arg(req, "redirect_to_result", "false")
     if boolean_of_arg(redirect):
         def _then_redir(res):