mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-18 18:56:28 +00:00
webapi: normalized API: use t=upload or t=download when providing localdir= or localfile=
This commit is contained in:
parent
ad038497db
commit
13e84526a1
@ -98,7 +98,7 @@ for files and directories which do not yet exist.
|
||||
[ 'filenode', { 'mutable': bool, 'uri': file_uri, 'size': bytes } ]
|
||||
|
||||
|
||||
GET FILEURL?localfile=$FILENAME
|
||||
GET FILEURL?t=download&localfile=$FILENAME
|
||||
|
||||
This instructs the client to download the given file and write its contents
|
||||
into the local filesystem at $FILENAME. This request will only be accepted
|
||||
@ -109,7 +109,7 @@ for files and directories which do not yet exist.
|
||||
(thoughts: we could use either the response headers or the response body
|
||||
to indicate download progress)
|
||||
|
||||
PUT NEWFILEURL?localfile=$FILENAME
|
||||
PUT NEWFILEURL?t=upload&localfile=$FILENAME
|
||||
|
||||
This uploads file to the vdrive and gets the contents from a file in the
|
||||
client's local filesystem. As with GET, this request will only be accepted
|
||||
@ -191,7 +191,7 @@ for files and directories which do not yet exist.
|
||||
vdrive to its original state (it may leave some intermediate directory
|
||||
nodes).
|
||||
|
||||
GET DIRURL?localdir=$DIRNAME
|
||||
GET DIRURL?t=download&localdir=$DIRNAME
|
||||
|
||||
This instructs the client to perform a recursive download of the given
|
||||
directory and all its descendant files and directories, writing the results
|
||||
@ -200,7 +200,7 @@ for files and directories which do not yet exist.
|
||||
(thoughts: we could use the response headers or the response body to
|
||||
indicate download progress)
|
||||
|
||||
PUT NEWDIRURL?localdir=$DIRNAME
|
||||
PUT NEWDIRURL?t=upload&localdir=$DIRNAME
|
||||
|
||||
This instructs the client to perform a recursive upload of a directory on
|
||||
the local filesystem into the vdrive at the given location. NEWDIRURL will
|
||||
@ -213,7 +213,7 @@ for files and directories which do not yet exist.
|
||||
Note that the "curl" utility can be used to provoke this sort of recursive
|
||||
upload, since the -T option will make it use an HTTP 'PUT':
|
||||
|
||||
curl -T /dev/null http://localhost:8011/vdrive/global/newdir?localdir=/home/user/directory-to-upload'
|
||||
curl -T /dev/null 'http://localhost:8011/vdrive/global/newdir?t=upload&localdir=/home/user/directory-to-upload'
|
||||
|
||||
|
||||
== POST Forms ==
|
||||
|
@ -407,7 +407,8 @@ class Web(unittest.TestCase):
|
||||
def test_GET_FILEURL_localfile(self): # YES
|
||||
localfile = os.path.abspath("web/GET_FILEURL_localfile")
|
||||
fileutil.make_dirs("web")
|
||||
d = self.GET("/vdrive/global/foo/bar.txt?localfile=%s" % localfile)
|
||||
d = self.GET("/vdrive/global/foo/bar.txt?t=download&localfile=%s"
|
||||
% localfile)
|
||||
def _done(res):
|
||||
self.failUnless(os.path.exists(localfile))
|
||||
data = open(localfile, "rb").read()
|
||||
@ -423,7 +424,8 @@ class Web(unittest.TestCase):
|
||||
webish.LOCALHOST = "127.0.0.2"
|
||||
localfile = os.path.abspath("web/GET_FILEURL_localfile_nonlocal")
|
||||
fileutil.make_dirs("web")
|
||||
d = self.GET("/vdrive/global/foo/bar.txt?localfile=%s" % localfile)
|
||||
d = self.GET("/vdrive/global/foo/bar.txt?t=download&localfile=%s"
|
||||
% localfile)
|
||||
d.addBoth(self.shouldFail, error.Error, "localfile non-local",
|
||||
"403 Forbidden")
|
||||
def _check(res):
|
||||
@ -438,7 +440,8 @@ class Web(unittest.TestCase):
|
||||
def test_GET_FILEURL_localfile_nonabsolute(self): # YES
|
||||
localfile = "web/nonabsolute/path"
|
||||
fileutil.make_dirs("web/nonabsolute")
|
||||
d = self.GET("/vdrive/global/foo/bar.txt?localfile=%s" % localfile)
|
||||
d = self.GET("/vdrive/global/foo/bar.txt?t=download&localfile=%s"
|
||||
% localfile)
|
||||
d.addBoth(self.shouldFail, error.Error, "localfile non-absolute",
|
||||
"403 Forbidden")
|
||||
def _check(res):
|
||||
@ -452,7 +455,8 @@ class Web(unittest.TestCase):
|
||||
f = open(localfile, "wb")
|
||||
f.write(self.NEWFILE_CONTENTS)
|
||||
f.close()
|
||||
d = self.PUT("/vdrive/global/foo/new.txt?localfile=%s" % localfile, "")
|
||||
d = self.PUT("/vdrive/global/foo/new.txt?t=upload&localfile=%s" %
|
||||
localfile, "")
|
||||
def _check(res):
|
||||
self.failUnless("new.txt" in self._foo_node.children)
|
||||
new_uri = self._foo_node.children["new.txt"]
|
||||
@ -468,8 +472,8 @@ class Web(unittest.TestCase):
|
||||
f = open(localfile, "wb")
|
||||
f.write(self.NEWFILE_CONTENTS)
|
||||
f.close()
|
||||
d = self.PUT("/vdrive/global/foo/newdir/new.txt?localfile=%s" %
|
||||
localfile, "")
|
||||
d = self.PUT("/vdrive/global/foo/newdir/new.txt?t=upload&localfile=%s"
|
||||
% localfile, "")
|
||||
def _check(res):
|
||||
self.failIf("new.txt" in self._foo_node.children)
|
||||
self.failUnless("newdir" in self._foo_node.children)
|
||||
@ -639,7 +643,7 @@ class Web(unittest.TestCase):
|
||||
def test_GET_DIRURL_localdir(self): # YES
|
||||
localdir = os.path.abspath("web/GET_DIRURL_localdir")
|
||||
fileutil.make_dirs("web")
|
||||
d = self.GET("/vdrive/global/foo?localdir=%s" % localdir)
|
||||
d = self.GET("/vdrive/global/foo?t=download&localdir=%s" % localdir)
|
||||
def _check(res):
|
||||
barfile = os.path.join(localdir, "bar.txt")
|
||||
self.failUnless(os.path.exists(barfile))
|
||||
@ -684,7 +688,8 @@ class Web(unittest.TestCase):
|
||||
self.touch(localdir, "three/bar.txt")
|
||||
self.touch(localdir, "zap.zip")
|
||||
|
||||
d = self.PUT("/vdrive/global/foo/newdir?localdir=%s" % localdir, "")
|
||||
d = self.PUT("/vdrive/global/foo/newdir?t=upload&localdir=%s"
|
||||
% localdir, "")
|
||||
def _check(res):
|
||||
self.failUnless("newdir" in self._foo_node.children)
|
||||
newnode = self.nodes[self._foo_node.children["newdir"]]
|
||||
@ -713,7 +718,8 @@ class Web(unittest.TestCase):
|
||||
self.touch(localdir, "three/bar.txt")
|
||||
self.touch(localdir, "zap.zip")
|
||||
|
||||
d = self.PUT("/vdrive/global/foo/subdir/newdir?localdir=%s" % localdir,
|
||||
d = self.PUT("/vdrive/global/foo/subdir/newdir?t=upload&localdir=%s"
|
||||
% localdir,
|
||||
"")
|
||||
def _check(res):
|
||||
self.failUnless("subdir" in self._foo_node.children)
|
||||
|
@ -525,11 +525,14 @@ class PUTHandler(rend.Page):
|
||||
# we must traverse the path, creating new directories as necessary
|
||||
d = self._get_or_create_directories(self._node, self._path[:-1])
|
||||
name = self._path[-1]
|
||||
if localfile:
|
||||
d.addCallback(self._upload_localfile, localfile, name)
|
||||
elif localdir:
|
||||
d.addCallback(self._get_or_create_directories, self._path[-1:])
|
||||
d.addCallback(self._upload_localdir, localdir)
|
||||
if t == "upload":
|
||||
if localfile:
|
||||
d.addCallback(self._upload_localfile, localfile, name)
|
||||
elif localdir:
|
||||
d.addCallback(self._get_or_create_directories, self._path[-1:])
|
||||
d.addCallback(self._upload_localdir, localdir)
|
||||
else:
|
||||
raise RuntimeError("t=upload requires localfile= or localdir=")
|
||||
elif t == "uri":
|
||||
d.addCallback(self._attach_uri, req.content, name)
|
||||
elif t == "mkdir":
|
||||
@ -702,9 +705,12 @@ class VDrive(rend.Page):
|
||||
filename = path[-1]
|
||||
if "filename" in req.args:
|
||||
filename = req.args["filename"][0]
|
||||
if localfile:
|
||||
# write contents to a local file
|
||||
return LocalFileDownloader(node, localfile), ()
|
||||
if t == "download":
|
||||
if localfile:
|
||||
# write contents to a local file
|
||||
return LocalFileDownloader(node, localfile), ()
|
||||
# send contents as the result
|
||||
return FileDownloader(node, filename), ()
|
||||
elif t == "":
|
||||
# send contents as the result
|
||||
return FileDownloader(node, filename), ()
|
||||
@ -717,9 +723,11 @@ class VDrive(rend.Page):
|
||||
else:
|
||||
raise RuntimeError("bad t=%s" % t)
|
||||
elif IDirectoryNode.providedBy(node):
|
||||
if localdir:
|
||||
# recursive download to a local directory
|
||||
return LocalDirectoryDownloader(node, localdir), ()
|
||||
if t == "download":
|
||||
if localdir:
|
||||
# recursive download to a local directory
|
||||
return LocalDirectoryDownloader(node, localdir), ()
|
||||
raise RuntimeError("t=download requires localdir=")
|
||||
elif t == "":
|
||||
# send an HTML representation of the directory
|
||||
return Directory(self.name, node, path), ()
|
||||
|
Loading…
Reference in New Issue
Block a user