Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# custom files
db.sqlite
settings.py

.idea

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
5 changes: 3 additions & 2 deletions tileservermapping/slowtiles/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.urls import path
from .views import insert_tile, get_server_list
from .views import insert_tile, get_server_list, upload_tile

urlpatterns = [
path('add/<int:z>/<int:x>/<int:y>', insert_tile, name="insert_tile"),
path('server_list/<int:z>/<int:x>/<int:y>', get_server_list, name="server_list")
path('server_list/<int:z>/<int:x>/<int:y>', get_server_list, name="server_list"),
path('upload_tile/<int:z>/<int:x>/<int:y>.<slug:format>', upload_tile, name='upload_tile'),
]
26 changes: 26 additions & 0 deletions tileservermapping/slowtiles/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from pathlib import Path

from django.conf import settings
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST

from tileservermapping.mapping.models import Server
from tileservermapping.slowtiles.models import SlowTiles
Expand All @@ -18,3 +23,24 @@ def get_server_list(request, z, x, y):
for tile in tiles:
answer += "{}/{}/{}\n".format(tile.z, tile.x, tile.y)
return HttpResponse(answer, content_type='text')


def handle_uploaded_file(path, f):
with open(path, 'wb') as destination:
for chunk in f.chunks():
destination.write(chunk)

@require_POST
@csrf_exempt
def upload_tile(request, z, x, y, format):
# TODO auth oth server
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is auth oth server?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be authenticate the server, because at the moment all servers having access to the api can upload files

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be fixed by using #8 and adding the checks here to

# TODO check if tile in server
if not SlowTiles.objects.filter(x=x, y=y, z=z, count__gte=5).count():
return HttpResponse('Tile should not be static\n', content_type="text", status=403)
path = Path(settings.TILE_WEBSERVER_DIR) / str(z) / str(x)
if not path.exists():
path.mkdir(parents=True)
file = path / "{}.{}".format(y, format)
existed = file.exists()
handle_uploaded_file(file, request.FILES['tile'])
return HttpResponse('Updated\n' if existed else 'OK\n', content_type='text')