chenjunkai 6 жил өмнө
parent
commit
12e4765bd8

+ 1 - 1
Ansjer/urls.py

@@ -119,7 +119,7 @@ urlpatterns = [
     # 新需求ota接口
     url(r'^OTA/getNewVer', OTAEquipment.getNewVerInterface),
     url(r'^OTA/uploadsPack$', OTAEquipment.uploadOTAInterfaceView.as_view()),
-
+    url(r'^OTA/downloadsPack/(?P<fullPath>[0-9\w/.]+)', OTAEquipment.downloadOTAInterface),
 
     # 测试专用api
     path('Test', Test.Test.as_view()),

+ 34 - 4
Controller/OTAEquipment.py

@@ -506,8 +506,9 @@ def getNewVerInterface(request):
                     ver = equipmentValid[0].softwareVersion
                     equipment = equipmentValid[0]
                     file_path = equipment.filePath
-                    path = file_path.replace('static/Upgrade/', '').replace('\\', '/')
-                    url = SERVER_DOMAIN + '/OTA/downloads/' + path + '?time=' + str(time.time())
+                    # path = file_path.replace('static/Upgrade/', '').replace('\\', '/')
+                    # url = SERVER_DOMAIN + '/OTA/downloads/' + path + '?time=' + str(time.time())
+                    url = SERVER_DOMAIN + '/OTA/downloadsPack/' + file_path + '?time=' + str(time.time())
                     return response.json(0, {
                         'ver': ver,
                         'url': url,
@@ -564,7 +565,7 @@ class uploadOTAInterfaceView(TemplateView):
 
     def upload_ota_file(self,fileName,response):
         try:
-            path = '/'.join((BASE_DIR, 'static/Upgrade', str(time.time()))).replace('\\', '/') + '/'
+            path = '/'.join((BASE_DIR, 'static/otapack', str(int(time.time())))).replace('\\', '/') + '/'
             if not os.path.exists(path):
                 os.makedirs(path)
                 file_name = path + str(fileName)
@@ -590,4 +591,33 @@ class uploadOTAInterfaceView(TemplateView):
         else:
             index = file_name.find('static/')
             filePath = file_name[index:]
-            return response.json(0, {'filePath': filePath})
+            return response.json(0, {'filePath': filePath})
+
+# ota包下载
+# class downloadOTAInterfaceView(TemplateView):
+
+@csrf_exempt
+def downloadOTAInterface(request, fullPath, *callback_args, **callback_kwargs):
+    res = ResponseObject()
+    print('fullPath:')
+    print(fullPath)
+    if fullPath:
+        if os.path.isfile(fullPath):
+            try:
+                JSON = res.formal(0)
+                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-MD5'] = getMD5orSHA265(fullPath)
+                # 校验文件md5值
+                response['Content-SHA265'] = getMD5orSHA265(fullPath, 'SHA265')
+                response['Content-CRC32'] = getMD5orSHA265(fullPath, 'CRC32')
+                response['Content-Error'] = JSON
+                return response
+            except Exception as e:
+                return res.json(906,repr(e))
+        else:
+            return res.json(907)
+    else:
+        return res.json(800)