diff --git a/update/urls.py b/update/urls.py index 3573e01..3800806 100644 --- a/update/urls.py +++ b/update/urls.py @@ -31,6 +31,7 @@ urlpatterns = [ path('update_user/', update_user), path('get_git_version/', get_git_version), path('get_client/', get_client), + path('download_client/', download_client), path('get_operation_cmd/', get_operation_cmd), path('update_cine/', update_cine), # re_path(r'^cinema/search/ip/(?P[0-9.]*?)/version/(?P[\S]*?)/$', views.CinemaSearchAPIView.as_view()) diff --git a/update/utils/client_util_custom.py b/update/utils/client_util_custom.py index bf05a5b..31594d8 100644 --- a/update/utils/client_util_custom.py +++ b/update/utils/client_util_custom.py @@ -61,6 +61,20 @@ class ClientUtilCustom: db_conn.close() return self.client_data + def download_client_manual(self, file_name, server_path): + # 启动smb服务 + self.smb_connect() + # 下载文件到本地 + with open(os.path.join(self.local_path, file_name), 'wb') as local_file: + # 接收文件并写入本地文件 + print('从共享下载客户端文件到服务器 共享路径:', rf"{server_path}{file_name}", '服务器路径:', + os.path.join(self.local_path, file_name)) + self.smb_conn.retrieveFile('data1', rf"{server_path}{file_name}", local_file) + # 关闭本地文件 + local_file.close() + # 关闭smb服务 + self.smb_disconnect() + return True def handle_client_data_format(self, client_data_list): print('handle_client_data_format') diff --git a/update/views.py b/update/views.py index 548afc8..2c7ea96 100644 --- a/update/views.py +++ b/update/views.py @@ -117,6 +117,15 @@ async def get_client(request): client_data = await ClientUtilCustom().sync_client_db() return JsonResponse(client_data, safe=False) +def download_client(request): + file_name = request.GET.get('name') + path = request.GET.get('path') + try: + ClientUtilCustom().download_client_manual(file_name, path) + except Exception as e: + return JsonResponse({'result': 'fail', 'detail': e}, status=400) + return JsonResponse({'result': 'success'}, status=200) + def update_cine(request): req = request.GET.dict() cinema_ip = req.get('ip')