1
0
mirror of https://github.com/GNS3/gns3-server synced 2025-01-22 22:10:57 +00:00

Recursive listing of the images directory & fixes bug when uploading no files.

This commit is contained in:
Jeremy 2015-02-23 15:49:05 -07:00
parent 4d1f08c96e
commit 0e8c184987
2 changed files with 11 additions and 12 deletions

View File

@ -20,9 +20,6 @@ import stat
from ..config import Config from ..config import Config
from ..web.route import Route from ..web.route import Route
from ..schemas.version import VERSION_SCHEMA
from ..version import __version__
from aiohttp.web import HTTPConflict
class UploadHandler: class UploadHandler:
@ -34,15 +31,14 @@ class UploadHandler:
api_version=None api_version=None
) )
def index(request, response): def index(request, response):
files = [] image_files = []
try: try:
for filename in os.listdir(UploadHandler.image_directory()): for root, _, files in os.walk(UploadHandler.image_directory()):
if os.path.isfile(os.path.join(UploadHandler.image_directory(), filename)): for filename in files:
if filename[0] != ".": image_files.append(os.path.join(root, filename))
files.append(filename) except OSError:
except OSError as e:
pass pass
response.template("upload.html", files=files, image_path=UploadHandler.image_directory()) response.template("upload.html", files=image_files)
@classmethod @classmethod
@Route.post( @Route.post(
@ -53,8 +49,11 @@ class UploadHandler:
def upload(request, response): def upload(request, response):
data = yield from request.post() data = yield from request.post()
destination_path = os.path.join(UploadHandler.image_directory(), data["file"].filename) if not data["file"]:
response.redirect("/upload")
return
destination_path = os.path.join(UploadHandler.image_directory(), data["file"].filename)
try: try:
os.makedirs(UploadHandler.image_directory(), exist_ok=True) os.makedirs(UploadHandler.image_directory(), exist_ok=True)
with open(destination_path, "wb+") as f: with open(destination_path, "wb+") as f:

View File

@ -10,7 +10,7 @@
{%if files%} {%if files%}
<h2>Files on {{gns3_host}}</h2> <h2>Files on {{gns3_host}}</h2>
{%for file in files%} {%for file in files%}
<p>{{image_path}}/{{file}}</a></p> <p>{{file}}</a></p>
{%endfor%} {%endfor%}
{%endif%} {%endif%}
{% endblock %} {% endblock %}