mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-07 11:50:21 +00:00
webish: add PUT /uri?mutable=true
This commit is contained in:
parent
e5dc9a8486
commit
23c2c8d660
@ -178,7 +178,7 @@ f. uploading a file
|
|||||||
|
|
||||||
This action also uploads a file without attaching it to a virtual drive
|
This action also uploads a file without attaching it to a virtual drive
|
||||||
directory, but can be used from an HTML form. The response is the file
|
directory, but can be used from an HTML form. The response is the file
|
||||||
write cap.
|
read cap.
|
||||||
|
|
||||||
POST http://localhost:8123/uri?t=upload&mutable=true
|
POST http://localhost:8123/uri?t=upload&mutable=true
|
||||||
|
|
||||||
@ -186,6 +186,12 @@ f. uploading a file
|
|||||||
directory, but creates a mutable file (SSK) instead of an immutable one.
|
directory, but creates a mutable file (SSK) instead of an immutable one.
|
||||||
The response contains the new URI that was created.
|
The response contains the new URI that was created.
|
||||||
|
|
||||||
|
PUT http://localhost:8123/uri?mutable=true
|
||||||
|
|
||||||
|
This second form also accepts data from the HTTP request body, but creates
|
||||||
|
a mutable file (SSK) instead of an immutable one (CHK). The response
|
||||||
|
contains the new URI that was created.
|
||||||
|
|
||||||
|
|
||||||
g. creating a new directory
|
g. creating a new directory
|
||||||
|
|
||||||
|
@ -1013,6 +1013,7 @@ class Web(WebMixin, unittest.TestCase):
|
|||||||
uri = uri.strip()
|
uri = uri.strip()
|
||||||
u = IURI(uri)
|
u = IURI(uri)
|
||||||
self.failUnless(IMutableFileURI.providedBy(u))
|
self.failUnless(IMutableFileURI.providedBy(u))
|
||||||
|
self.failUnless(u.storage_index in FakeMutableFileNode.all_contents)
|
||||||
n = self.s.create_node_from_uri(uri)
|
n = self.s.create_node_from_uri(uri)
|
||||||
return n.download_to_data()
|
return n.download_to_data()
|
||||||
d.addCallback(_check)
|
d.addCallback(_check)
|
||||||
@ -1541,6 +1542,33 @@ class Web(WebMixin, unittest.TestCase):
|
|||||||
"/uri only accepts PUT and PUT?t=mkdir")
|
"/uri only accepts PUT and PUT?t=mkdir")
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def test_PUT_NEWFILE_URI_mutable(self):
|
||||||
|
file_contents = "New file contents here\n"
|
||||||
|
d = self.PUT("/uri?mutable=true", file_contents)
|
||||||
|
def _check(uri):
|
||||||
|
uri = uri.strip()
|
||||||
|
u = IURI(uri)
|
||||||
|
self.failUnless(IMutableFileURI.providedBy(u))
|
||||||
|
self.failUnless(u.storage_index in FakeMutableFileNode.all_contents)
|
||||||
|
n = self.s.create_node_from_uri(uri)
|
||||||
|
return n.download_to_data()
|
||||||
|
d.addCallback(_check)
|
||||||
|
def _check2(data):
|
||||||
|
self.failUnlessEqual(data, file_contents)
|
||||||
|
d.addCallback(_check2)
|
||||||
|
return d
|
||||||
|
|
||||||
|
def _check(uri):
|
||||||
|
self.failUnless(uri in FakeCHKFileNode.all_contents)
|
||||||
|
self.failUnlessEqual(FakeCHKFileNode.all_contents[uri],
|
||||||
|
file_contents)
|
||||||
|
return self.GET("/uri/%s" % uri)
|
||||||
|
d.addCallback(_check)
|
||||||
|
def _check2(res):
|
||||||
|
self.failUnlessEqual(res, file_contents)
|
||||||
|
d.addCallback(_check2)
|
||||||
|
return d
|
||||||
|
|
||||||
def test_PUT_mkdir(self):
|
def test_PUT_mkdir(self):
|
||||||
d = self.PUT("/uri?t=mkdir", "")
|
d = self.PUT("/uri?t=mkdir", "")
|
||||||
def _check(uri):
|
def _check(uri):
|
||||||
|
@ -1203,6 +1203,15 @@ class URIPUTHandler(rend.Page):
|
|||||||
if t == "":
|
if t == "":
|
||||||
# "PUT /uri", to create an unlinked file. This is like PUT but
|
# "PUT /uri", to create an unlinked file. This is like PUT but
|
||||||
# without the associated set_uri.
|
# without the associated set_uri.
|
||||||
|
mutable = bool(get_arg(req, "mutable", "").strip())
|
||||||
|
if mutable:
|
||||||
|
# SDMF: files are small, and we can only upload data
|
||||||
|
contents = req.content
|
||||||
|
contents.seek(0)
|
||||||
|
data = contents.read()
|
||||||
|
d = IClient(ctx).create_mutable_file(data)
|
||||||
|
d.addCallback(lambda n: n.get_uri())
|
||||||
|
else:
|
||||||
uploadable = FileHandle(req.content)
|
uploadable = FileHandle(req.content)
|
||||||
d = IClient(ctx).upload(uploadable)
|
d = IClient(ctx).upload(uploadable)
|
||||||
d.addCallback(lambda results: results.uri)
|
d.addCallback(lambda results: results.uri)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user