mirror of
https://github.com/Eugeny/tabby-web.git
synced 2026-08-18 07:16:03 +01:00
wip
This commit is contained in:
19
terminus/app/api.py
Normal file
19
terminus/app/api.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# from rest_framework import fields
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
|
||||
from .models import Config
|
||||
|
||||
|
||||
class ConfigSerializer(ModelSerializer):
|
||||
class Meta:
|
||||
model = Config
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class ConfigViewSet(ModelViewSet):
|
||||
queryset = Config.objects.all()
|
||||
serializer_class = ConfigSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
return Config.objects.filter(user=self.request.user)
|
||||
@@ -2,6 +2,7 @@ from django.db import models
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.contrib.auth.signals import user_logged_in
|
||||
from django.dispatch import receiver
|
||||
from django.db.models.signals import post_save
|
||||
|
||||
|
||||
class Config(models.Model):
|
||||
@@ -19,4 +20,7 @@ class User(AbstractUser):
|
||||
modified_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
|
||||
# @receiver
|
||||
# @receiver(user_logged_in)
|
||||
# def post_login(sender, user, request, **kwargs):
|
||||
# if not user.active_config:
|
||||
# user.active_config = Config.objects.filter()
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
from django.urls import path, include
|
||||
from rest_framework import routers
|
||||
|
||||
from . import api
|
||||
from . import consumers
|
||||
from . import views
|
||||
|
||||
|
||||
router = routers.DefaultRouter(trailing_slash=False)
|
||||
# router.register('api/2/auth/saml', SAMLProviderViewSet)
|
||||
router.register('api/1/configs', api.ConfigViewSet)
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.IndexView.as_view()),
|
||||
path('terminal', views.TerminalView.as_view()),
|
||||
path('app-dist/<path:path>', views.AppDistView.as_view()),
|
||||
path('dist/<path:path>', views.DistView.as_view()),
|
||||
path('build/<path:path>', views.BuildView.as_view()),
|
||||
path('', include(router.urls)),
|
||||
]
|
||||
|
||||
|
||||
@@ -7,7 +7,14 @@ from django.views import static
|
||||
|
||||
class IndexView(APIView):
|
||||
def get(self, request, format=None):
|
||||
return static.serve(request, 'terminal.html', document_root=str(settings.BASE_DIR / 'dist'))
|
||||
return static.serve(request, 'index.html', document_root=str(settings.BASE_DIR / 'build'))
|
||||
|
||||
|
||||
class TerminalView(APIView):
|
||||
def get(self, request, format=None):
|
||||
response = static.serve(request, 'terminal.html', document_root=str(settings.BASE_DIR / 'build'))
|
||||
response['X-Frame-Options'] = 'SAMEORIGIN'
|
||||
return response
|
||||
|
||||
|
||||
class AppDistView(APIView):
|
||||
@@ -15,6 +22,6 @@ class AppDistView(APIView):
|
||||
return static.serve(request, path, document_root=str(settings.BASE_DIR / 'app-dist'))
|
||||
|
||||
|
||||
class DistView(APIView):
|
||||
class BuildView(APIView):
|
||||
def get(self, request, path=None, format=None):
|
||||
return static.serve(request, path, document_root=str(settings.BASE_DIR / 'dist'))
|
||||
return static.serve(request, path, document_root=str(settings.BASE_DIR / 'build'))
|
||||
|
||||
@@ -128,3 +128,8 @@ STATIC_URL = '/static/'
|
||||
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
CSRF_USE_SESSIONS = False
|
||||
CSRF_COOKIE_HTTPONLY = False
|
||||
CSRF_COOKIE_NAME = 'XSRF-TOKEN'
|
||||
CSRF_HEADER_NAME = 'HTTP_X_XSRF_TOKEN'
|
||||
|
||||
Reference in New Issue
Block a user