瀏覽代碼

新增ota升级接口

locky 4 年之前
父節點
當前提交
b848875161
共有 2 個文件被更改,包括 36 次插入0 次删除
  1. 1 0
      Ansjer/urls.py
  2. 35 0
      Controller/OTAEquipment.py

+ 1 - 0
Ansjer/urls.py

@@ -113,6 +113,7 @@ urlpatterns = [
     url(r'^OTA/uploadsPack$', OTAEquipment.uploadOTAInterfaceView.as_view()),
     url(r'^OTA/downloadsPack/(?P<fullPath>[0-9\w/.\-]+)', OTAEquipment.downloadOTAInterface),
     url(r'^dlotapack/(?P<fullPath>[0-9\w/.\-]+)', OTAEquipment.downloadOTAInterfaceV2),
+    url(r'^OTA/getDownLoadOTApackUrl$', OTAEquipment.getDownLoadOTApackUrl),    # ota升级接口
 
     # h获取验证码    # v2接口
     url(r'^v2/account/authcode$', UserController.v2authCodeView.as_view()),

+ 35 - 0
Controller/OTAEquipment.py

@@ -685,3 +685,38 @@ def downloadOTAInterfaceV2(request, fullPath, *callback_args, **callback_kwargs)
             return res.json(907)
     else:
         return res.json(444, 'fullPath')
+
+
+@csrf_exempt
+def getDownLoadOTApackUrl(request):
+    # 获取升级文件的下载链接
+    response = ResponseObject()
+    request.encoding = 'utf-8'
+    if request.method == "POST":
+        deviceType = request.POST.get('deviceType', None)
+        version = request.POST.get('version', None)
+    elif request.method == "GET":
+        deviceType = request.GET.get('deviceType', None)
+        version = request.GET.get('version', None)
+    else:
+        return response.json(444)
+    if not deviceType or not version:
+        return response.json(444, 'deviceType or version')
+    equipmentVersion = Equipment_Version.objects.filter(mci=deviceType, version=version)
+    # 判断是否有该版本存在
+    if not equipmentVersion.exists():
+        return response.json(907)
+    file_path = equipmentVersion[0].filePath
+    if file_path:
+        if file_path.find('static/otapack') != -1:  # 只下载otapack路径下的文件
+            url = SERVER_DOMAIN + 'OTA/downloadsPack/' + file_path  # 复用以前的文件下载方式
+            # SERVER_DOMAIN = 'https://test.dvema.com/'
+            # url = SERVER_DOMAIN + 'OTA/downloadsPack/' + file_path
+            res = {
+                "url": url,
+            }
+            return response.json(0, res)
+        else:
+            return response.json(901)
+    else:
+        return response.json(901)