|
@@ -520,3 +520,74 @@ def getNewVerInterface(request):
|
|
|
return response.json(tko.code)
|
|
|
else:
|
|
|
return response.json(444,'token,code')
|
|
|
+
|
|
|
+# ota包上传
|
|
|
+class uploadOTAInterfaceView(TemplateView):
|
|
|
+ @method_decorator(csrf_exempt)
|
|
|
+ def dispatch(self, *args, **kwargs):
|
|
|
+ return super(uploadOTAInterfaceView, self).dispatch(*args, **kwargs)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ token = request.POST.get('token', None)
|
|
|
+ fileName = request.FILES.get('fileName', None)
|
|
|
+ return self.validate(token,fileName)
|
|
|
+
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'gb2312'
|
|
|
+ token = request.GET.get('token', None)
|
|
|
+ fileName = request.FILES.get('fileName', None)
|
|
|
+ return self.validate(token,fileName)
|
|
|
+
|
|
|
+ def validate(self, token,fileName):
|
|
|
+ response = ResponseObject()
|
|
|
+ print(token)
|
|
|
+ print(fileName)
|
|
|
+ if fileName != None and token != None:
|
|
|
+ tko = TokenObject(token)
|
|
|
+ tko.valid()
|
|
|
+ response.lang = tko.lang
|
|
|
+ if tko.code == 0:
|
|
|
+ userID = tko.userID
|
|
|
+ if userID is not None:
|
|
|
+ own_permission = ModelService.check_permission(userID=userID, permID=210)
|
|
|
+ if own_permission is True:
|
|
|
+ return self.upload_ota_file(fileName,response)
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
+ else:
|
|
|
+ return response.json(310)
|
|
|
+ else:
|
|
|
+ return response.json(tko.code)
|
|
|
+ else:
|
|
|
+ return response.json(800)
|
|
|
+
|
|
|
+ def upload_ota_file(self,fileName,response):
|
|
|
+ try:
|
|
|
+ path = '/'.join((BASE_DIR, 'static/Upgrade', str(time.time()))).replace('\\', '/') + '/'
|
|
|
+ if not os.path.exists(path):
|
|
|
+ os.makedirs(path)
|
|
|
+ file_name = path + str(fileName)
|
|
|
+ if os.path.exists(file_name):
|
|
|
+ os.remove(file_name)
|
|
|
+ destination = open(file_name, 'wb+')
|
|
|
+ for chunk in fileName.chunks():
|
|
|
+ destination.write(chunk)
|
|
|
+ destination.close()
|
|
|
+ else:
|
|
|
+ file_name = path + str(fileName)
|
|
|
+ if os.path.exists(file_name):
|
|
|
+ os.remove(file_name)
|
|
|
+
|
|
|
+ destination = open(file_name, 'wb+')
|
|
|
+ for chunk in fileName.chunks():
|
|
|
+ destination.write(chunk)
|
|
|
+ destination.close()
|
|
|
+ except Exception as e:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print('上传文件错误: %s' % errorInfo)
|
|
|
+ return response.json(700, {'details': repr(e)})
|
|
|
+ else:
|
|
|
+ index = file_name.find('static/')
|
|
|
+ filePath = file_name[index:]
|
|
|
+ return response.json(0, {'filePath': filePath})
|