From df8baede4398de5abc433206152c63395eac0ef0 Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 13 Jun 2023 18:25:03 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=BD=95=E5=83=8F=E6=92=AD=E6=94=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/api/session/session.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/apps/terminal/api/session/session.py b/apps/terminal/api/session/session.py index c414dd289..47432b60b 100644 --- a/apps/terminal/api/session/session.py +++ b/apps/terminal/api/session/session.py @@ -2,6 +2,7 @@ # import os import tarfile + from django.core.files.storage import default_storage from django.db.models import F from django.http import FileResponse @@ -15,21 +16,22 @@ from rest_framework.decorators import action from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response -from common.drf.filters import BaseFilterSet +from common.api import AsyncApiMixin from common.const.http import GET +from common.drf.filters import BaseFilterSet from common.drf.filters import DatetimeRangeFilter from common.drf.renders import PassthroughRenderer -from common.api import AsyncApiMixin +from common.storage.replay import ReplayStorageHandler from common.utils import data_to_json, is_uuid from common.utils import get_logger, get_object_or_none -from common.storage.replay import ReplayStorageHandler -from rbac.permissions import RBACPermission from orgs.mixins.api import OrgBulkModelViewSet from orgs.utils import tmp_to_root_org, tmp_to_org +from rbac.permissions import RBACPermission from terminal import serializers +from terminal.const import TerminalType from terminal.models import Session -from terminal.utils import is_session_approver from terminal.permissions import IsSessionAssignee +from terminal.utils import is_session_approver from users.models import User __all__ = [ @@ -182,14 +184,20 @@ class SessionReplayViewSet(AsyncApiMixin, viewsets.ViewSet): @staticmethod def get_replay_data(session, url): - tp = 'json' - if session.protocol in ('rdp', 'vnc'): - # 需要考虑录像播放和离线播放器的约定,暂时不处理 - tp = 'guacamole' + all_guacamole_types = ( + TerminalType.lion, TerminalType.guacamole, + TerminalType.razor, TerminalType.xrdp + ) + if url.endswith('.cast.gz'): tp = 'asciicast' - if url.endswith('.replay.mp4'): + elif url.endswith('.replay.mp4'): tp = 'mp4' + elif (getattr(session.terminal, 'type', None) in all_guacamole_types) or \ + (session.protocol in ('rdp', 'vnc')): + tp = 'guacamole' + else: + tp = 'json' download_url = reverse('api-terminal:session-replay-download', kwargs={'pk': session.id}) data = {