2021-10-31 18:15:23 +01:00
|
|
|
import fsspec
|
|
|
|
|
import os
|
|
|
|
|
from fsspec.implementations.local import LocalFileSystem
|
|
|
|
|
from django.conf import settings
|
2022-11-07 18:56:10 +01:00
|
|
|
from django.http.response import (
|
|
|
|
|
FileResponse,
|
|
|
|
|
HttpResponseNotFound,
|
|
|
|
|
HttpResponseRedirect,
|
|
|
|
|
)
|
2021-10-31 18:15:23 +01:00
|
|
|
from django.views import static
|
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
|
from urllib.parse import urlparse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IndexView(APIView):
|
|
|
|
|
def get(self, request, format=None):
|
|
|
|
|
if settings.FRONTEND_URL:
|
|
|
|
|
return HttpResponseRedirect(settings.FRONTEND_URL)
|
2022-11-07 18:56:10 +01:00
|
|
|
return static.serve(
|
|
|
|
|
request, "index.html", document_root=str(settings.STATIC_ROOT)
|
|
|
|
|
)
|
2021-10-31 18:15:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class TerminalView(APIView):
|
|
|
|
|
def get(self, request, format=None):
|
2022-11-07 18:56:10 +01:00
|
|
|
response = static.serve(
|
|
|
|
|
request, "terminal.html", document_root=str(settings.STATIC_ROOT)
|
|
|
|
|
)
|
2022-11-08 10:50:05 +01:00
|
|
|
response["Content-Security-Policy"] = "frame-ancestors 'self' https://tabby.sh;"
|
2022-11-07 18:56:10 +01:00
|
|
|
response["X-Frame-Options"] = "SAMEORIGIN"
|
2021-10-31 18:15:23 +01:00
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
2022-05-14 23:59:06 -07:00
|
|
|
class DemoView(APIView):
|
|
|
|
|
def get(self, request, format=None):
|
2022-11-07 18:56:10 +01:00
|
|
|
response = static.serve(
|
|
|
|
|
request, "demo.html", document_root=str(settings.STATIC_ROOT)
|
|
|
|
|
)
|
2022-11-08 10:50:05 +01:00
|
|
|
response["Content-Security-Policy"] = "frame-ancestors 'self' https://tabby.sh;"
|
|
|
|
|
response['X-Frame-Options'] = 'ALLOW-FROM https://tabby.sh'
|
2022-05-14 23:59:06 -07:00
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
2021-10-31 18:15:23 +01:00
|
|
|
class AppDistView(APIView):
|
|
|
|
|
def get(self, request, version=None, path=None, format=None):
|
|
|
|
|
fs = fsspec.filesystem(urlparse(settings.APP_DIST_STORAGE).scheme)
|
2022-11-07 18:56:10 +01:00
|
|
|
url = f"{settings.APP_DIST_STORAGE}/{version}/{path}"
|
2021-10-31 18:15:23 +01:00
|
|
|
if isinstance(fs, LocalFileSystem):
|
|
|
|
|
if not fs.exists(url):
|
|
|
|
|
return HttpResponseNotFound()
|
|
|
|
|
return FileResponse(fs.open(url), filename=os.path.basename(url))
|
|
|
|
|
else:
|
|
|
|
|
return HttpResponseRedirect(fs.url(url))
|