Skip to content

Commit

Permalink
Working browser version
Browse files Browse the repository at this point in the history
  • Loading branch information
GerbenAaltink committed Feb 21, 2021
1 parent 2c17897 commit 1faec5d
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 54 deletions.
19 changes: 2 additions & 17 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aiodav/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from aiodav.user import User
from aiodav.user import User
4 changes: 2 additions & 2 deletions aiodav/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

from aiodav.app import create_app

if __name__ == '__main__':
run_app(create_app(()))
if __name__ == "__main__":
run_app(create_app(()))
9 changes: 5 additions & 4 deletions aiodav/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ def create_app(users: Iterable[User] = None) -> web.Application:
aiohttp_jinja2.setup(
app,
loader=jinja2.FileSystemLoader(
pathlib.Path(__file__).parent.joinpath('templates')
))
app.router.add_view('/browser{tail:.+}', BrowserView)
pathlib.Path(__file__).parent.joinpath("templates")
),
)
app.router.add_view("/browser{tail:.+}", BrowserView)
if not users:
users = [User('admin', 'admin', '/')]
users = [User("admin", "admin", "/")]
app["users"] = users
return app
2 changes: 1 addition & 1 deletion aiodav/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ def joinpath(self, glob="*"):
def glob(self, prefix=None):
if prefix is None:
prefix = "*"
return [Entry(entry) for entry in super().glob(prefix)]
return [Entry(entry) for entry in super().glob(prefix)]
4 changes: 2 additions & 2 deletions aiodav/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

def safe_url(prefix: str, path: pathlib.Path) -> str:
uri = path.name
#parts = '/' + prefix + uri
return uri
# parts = '/' + prefix + uri
return uri
51 changes: 24 additions & 27 deletions aiodav/views/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,41 @@


class BrowserView(View):

async def resolve_user(self) -> User:
return User(username='admin', password='admin', root='/')
return User(username="admin", password="admin", root="/")

async def get(self):

user = await self.resolve_user()
root = user.joinpath(self.request.match_info.get('tail'))

root = user.joinpath(self.request.match_info.get("tail"))

files = []
for file_ in root.joinpath(self.request.match_info.get('tail')).glob('*'):
files.append(dict(
name= file_.name,
parent= file_.name,
uri= safe_url('browser', file_),
root=root
))
for file_ in root.joinpath(self.request.match_info.get("tail")).glob("*"):
files.append(
dict(
name=file_.name,
parent=file_.name,
uri=safe_url("browser", file_),
root=root,
)
)

location = root

print(dict(
a=self.request.raw_path,
b=self.request.path,
c=self.request.match_info,
d=self.request.path_qs,
e=self.request.host,
location=location
))
print(
dict(
a=self.request.raw_path,
b=self.request.path,
c=self.request.match_info,
d=self.request.path_qs,
e=self.request.host,
location=location,
)
)
context = dict(
tail=self.request.match_info.get('tail'),
tail=self.request.match_info.get("tail"),
request=self.request,
files=files,
path=root

path=root,
)
return aiohttp_jinja2.render_template(
'browser.html',
self.request,
context
)
return aiohttp_jinja2.render_template("browser.html", self.request, context)

0 comments on commit 1faec5d

Please sign in to comment.