From: Brian Warner Date: Wed, 14 May 2008 21:32:21 +0000 (-0700) Subject: webish: add /file links, change directory page to use them. This fixes filenames... X-Git-Tag: allmydata-tahoe-1.1.0~133 X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/cyclelanguage?a=commitdiff_plain;h=304abfee32a06e050009f94529136bc35b39e875;p=tahoe-lafs%2Ftahoe-lafs.git webish: add /file links, change directory page to use them. This fixes filenames in wget. Closes #221. --- diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index ca206692..2bb05809 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -464,6 +464,16 @@ class Web(WebMixin, unittest.TestCase): d.addCallback(self.failUnlessIsBarDotTxt) return d + def test_GET_FILEURL_named(self): + base = "/file/%s" % urllib.quote(self._bar_txt_uri) + d = self.GET(base + "/@@name=/blah.txt") + d.addCallback(self.failUnlessIsBarDotTxt) + d.addCallback(lambda res: self.GET(base + "/blah.txt")) + d.addCallback(self.failUnlessIsBarDotTxt) + d.addCallback(lambda res: self.GET(base + "/ignore/lots/blah.txt")) + d.addCallback(self.failUnlessIsBarDotTxt) + return d + def test_GET_FILEURL_save(self): d = self.GET(self.public_url + "/foo/bar.txt?save=bar.txt") # TODO: look at the headers, expect a Content-Disposition: attachment diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index 92ce7ea1..b1c3c48a 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -252,25 +252,17 @@ class Directory(rend.Page): times.append("m: " + mtime) ctx.fillSlots("times", times) - - # build the base of the uri_link link url - uri_link = "/uri/" + urllib.quote(target.get_uri()) - assert (IFileNode.providedBy(target) or IDirectoryNode.providedBy(target) or IMutableFileNode.providedBy(target)), target - if IMutableFileNode.providedBy(target): - # file - - # add the filename to the uri_link url - uri_link += '?%s' % (urllib.urlencode({'filename': name}),) + quoted_uri = urllib.quote(target.get_uri()) + if IMutableFileNode.providedBy(target): # to prevent javascript in displayed .html files from stealing a # secret directory URI from the URL, send the browser to a URI-based # page that doesn't know about the directory at all - #dlurl = urllib.quote(name) - dlurl = uri_link + dlurl = "/file/%s/@@named=/%s" % (quoted_uri, urllib.quote(name)) ctx.fillSlots("filename", T.a(href=dlurl)[html.escape(name)]) @@ -278,20 +270,11 @@ class Directory(rend.Page): ctx.fillSlots("size", "?") - text_plain_link = uri_link + "?filename=foo.txt" - text_plain_tag = T.a(href=text_plain_link)["text/plain"] + text_plain_url = "/file/%s/@@named=/foo.txt" % quoted_uri + text_plain_tag = T.a(href=text_plain_url)["text/plain"] elif IFileNode.providedBy(target): - # file - - # add the filename to the uri_link url - uri_link += '?%s' % (urllib.urlencode({'filename': name}),) - - # to prevent javascript in displayed .html files from stealing a - # secret directory URI from the URL, send the browser to a URI-based - # page that doesn't know about the directory at all - #dlurl = urllib.quote(name) - dlurl = uri_link + dlurl = "/file/%s/@@named=/%s" % (quoted_uri, urllib.quote(name)) ctx.fillSlots("filename", T.a(href=dlurl)[html.escape(name)]) @@ -299,11 +282,13 @@ class Directory(rend.Page): ctx.fillSlots("size", target.get_size()) - text_plain_link = uri_link + "?filename=foo.txt" - text_plain_tag = T.a(href=text_plain_link)["text/plain"] + text_plain_url = "/file/%s/@@named=/foo.txt" % quoted_uri + text_plain_tag = T.a(href=text_plain_url)["text/plain"] + elif IDirectoryNode.providedBy(target): # directory + uri_link = "/uri/" + urllib.quote(target.get_uri()) ctx.fillSlots("filename", T.a(href=uri_link)[html.escape(name)]) if target.is_readonly(): @@ -491,6 +476,7 @@ class WebDownloadTarget: pass class FileDownloader(resource.Resource): + isLeaf = True def __init__(self, filenode, name): assert (IFileNode.providedBy(filenode) or IMutableFileNode.providedBy(filenode)) @@ -1391,7 +1377,18 @@ class Root(rend.Page): client = IClient(ctx) req = inevow.IRequest(ctx) - if not segments or segments[0] != "uri": + if not segments: + return rend.Page.locateChild(self, ctx, segments) + + if segments[0] == "file": + if len(segments) < 2: + return rend.Page.locateChild(self, ctx, segments) + filecap = segments[1] + node = client.create_node_from_uri(filecap) + name = segments[-1] + return FileDownloader(node, name), () + + if segments[0] != "uri": return rend.Page.locateChild(self, ctx, segments) segments = list(segments)