stash
This commit is contained in:
parent
17bfb84a94
commit
2fe8d14c2c
35 changed files with 1976 additions and 2134 deletions
|
|
@ -38,6 +38,7 @@ urlpatterns = [
|
|||
path('api/', include('toolshed.api.inventory')),
|
||||
path('api/', include('toolshed.api.info')),
|
||||
path('api/', include('toolshed.api.files')),
|
||||
path('api/', include('toolshed.api.offlinedata')),
|
||||
path('media/', include('files.media_urls')),
|
||||
path('docs/', schema_view.with_ui('swagger', cache_timeout=0), name='api-docs'),
|
||||
]
|
||||
|
|
|
|||
63
backend/toolshed/api/offlinedata.py
Normal file
63
backend/toolshed/api/offlinedata.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
from django.http import HttpResponse
|
||||
from django.urls import path
|
||||
from rest_framework.decorators import api_view, permission_classes, authentication_classes
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
|
||||
from authentication.signature_auth import SignatureAuthentication
|
||||
|
||||
|
||||
def user_data():
|
||||
import io
|
||||
import zipfile
|
||||
|
||||
zip_buffer = io.BytesIO()
|
||||
|
||||
with zipfile.ZipFile(zip_buffer, "a", zipfile.ZIP_DEFLATED, False) as zip_file:
|
||||
for file_name, data in [('1.txt', io.BytesIO(b'111')),
|
||||
('2.txt', io.BytesIO(b'222'))]:
|
||||
zip_file.writestr(file_name, data.getvalue())
|
||||
|
||||
return zip_buffer.getvalue()
|
||||
|
||||
|
||||
def parse_user_data(data):
|
||||
import io
|
||||
import zipfile
|
||||
|
||||
with zipfile.ZipFile(io.BytesIO(data), "r") as zip_file:
|
||||
for file_name in zip_file.namelist():
|
||||
yield file_name, zip_file.read(file_name)
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
@authentication_classes([SignatureAuthentication])
|
||||
def import_data(request, format=None):
|
||||
zip = request.data.get('zip')
|
||||
if not zip:
|
||||
return Response(status=400)
|
||||
for file_name, data in parse_user_data(zip):
|
||||
print(file_name, data)
|
||||
return Response(status=200)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
@authentication_classes([SignatureAuthentication])
|
||||
def export_data(request, format=None):
|
||||
return HttpResponse(user_data(), content_type='application/zip', status=200)
|
||||
|
||||
|
||||
@api_view(['DELETE'])
|
||||
@permission_classes([IsAuthenticated])
|
||||
@authentication_classes([SignatureAuthentication])
|
||||
def delete_account(request, format=None):
|
||||
pass
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('export/', export_data, name='export_data'),
|
||||
path('import/', import_data, name='import_data'),
|
||||
path('account_data/', delete_account, name='delete_account'),
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue