Browse Source

pc端软件安装包上传下载查询删除操作2

lhq 4 years ago
parent
commit
c62f82f256
1 changed files with 10 additions and 9 deletions
  1. 10 9
      Controller/PcInfo.py

+ 10 - 9
Controller/PcInfo.py

@@ -3,7 +3,7 @@ import shutil
 import time
 import traceback
 import os
-from urllib import request
+from urllib import request, parse
 
 from django.http import HttpResponse
 
@@ -79,15 +79,16 @@ class PcInfo(View):
             return response.json(444)
         else:
             file = Pc_Info.objects.filter(pc_name=pc_name, bundle_version=bundle_version,
-                                          pc_version=pc_version)
+                                          pc_version=pc_version, pc_test=pc_test)
             if file:
                 return response.json(174)
             try:
                 # 安装包上传到服务器本地
-                file_path = 'static/pc/' + pc_name + '/' + bundle_version + '_' + pc_version + '_' + pc_test
+                file_path = 'static/pc/' + pc_name
                 if not os.path.exists(file_path):
                     os.makedirs(os.path.join(BASE_DIR, file_path))
-                file_path = file_path + '/' + str(file_name)
+                name = pc_version + '_' + bundle_version + '_' + pc_test + '_' + str(file_name)
+                file_path = file_path + '/' + str(name)
                 upload_path = os.path.join(BASE_DIR, file_path)
                 print('upload_path:', upload_path)
                 with open(upload_path, 'wb+') as destination:
@@ -186,7 +187,7 @@ class PcInfo(View):
                     wrapper = FileWrapper(open(fullPath, 'rb'))
                     response = HttpResponse(wrapper, content_type="application/octet-stream")
                     response['Content-Length'] = os.path.getsize(fullPath)
-                    response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(fullPath)
+                    response['Content-Disposition'] = 'attachment; filename={}'.format(parse.quote_plus(os.path.basename(fullPath), encoding="utf-8"))
                     response['Content-MD5'] = getMD5orSHA265(fullPath)
                     # 校验文件md5值
                     response['Content-SHA265'] = getMD5orSHA265(fullPath, 'SHA265')
@@ -221,10 +222,10 @@ class PcInfo(View):
             file_path = file[0].download_link
             file_path = os.path.join(BASE_DIR, file_path).replace('\\', '/')
             os.remove(file_path)
-            file_path = file_path.split("/")
-            file_path = [str(i) for i in file_path][:-1]
-            file_path = "/".join(file_path)
-            shutil.rmtree(file_path)
+            # file_path = file_path.split("/")
+            # file_path = [str(i) for i in file_path][:-1]
+            # file_path = "/".join(file_path)
+            # shutil.rmtree(file_path)
             file.delete()
         except Exception as e:
             return response.json(176, repr(e))