def post(self, request, *args, **kwargs): ID = request.data["id"] if ID is None: return ErosResponse(status=ErosResponseStatus.PARAMS_ERROR, detail="param [id] is missing...") try: instance = Record.objects.get(id=ID) partial = kwargs.pop('partial', False) serializer = self.get_serializer(instance, data=request.data, partial=partial) if serializer.is_valid(): serializer.save() return ErosResponse(data=serializer.data) else: return ErosResponse( status=ErosResponseStatus.SERIALIZED_FAILED, detail=serializer.errors) if getattr(instance, '_prefetched_objects_cache', None): # If 'prefetch_related' has been applied to a queryset, we need to # forcibly invalidate the prefetch cache on the instance. instance._prefetched_objects_cache = {} except Record.DoesNotExist: return ErosResponse(status=ErosResponseStatus.NOT_FOUND, detail="Record not found")
def post(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) if serializer.is_valid(): serializer.save() return ErosResponse(data=serializer.data) return ErosResponse(status=ErosResponseStatus.SERIALIZED_FAILED, detail=serializer.errors)
def post(self, request, *args, **kwargs): file = request.FILES['file'] if default_storage.exists(file.name): default_storage.delete(file.name) default_storage.save(file.name, ContentFile(file.read())) zfile = zipfile.ZipFile(MEDIA_ROOT+file.name) md5File = zfile.open('md5.json') jsonObj = json.loads(md5File.read().decode('utf-8')) try: responseData = { "appName": jsonObj['appName'], "jsMD5": jsonObj['jsVersion'], "android": jsonObj['android'], "ios": jsonObj['iOS'], "timestamp": jsonObj['timestamp'], "jsPath": 'https://'+request.get_host()+MEDIA_URL+file.name } zfile.close() return ErosResponse(data=responseData) except Exception as e: return ErosResponse(status=ErosResponseStatus.UPLOAD_FAILED,detail=str(e))
def get(self, request, *args, **kwargs): jsMD5 = request.query_params.get('jsMD5') if not jsMD5: return ErosResponse(status=ErosResponseStatus.PARAMS_ERROR, detail='missing jsMD5') try: queryset = Package.objects.get(jsMD5=jsMD5) serializer = self.get_serializer(queryset) return ErosResponse(data=serializer.data) except Package.DoesNotExist: return ErosResponse(status=ErosResponseStatus.NOT_FOUND, detail='Package [%s] Not Found' % (jsMD5))
def post(self, request, *args, **kwargs): ID = request.data.get("id") if ID is None: return ErosResponse(data=None, status=ErosResponseStatus.PARAMS_ERROR) else: try: release = Release.objects.get(id=ID) release.delete() return ErosResponse() except Release.DoesNotExist: return ErosResponse(status=ErosResponseStatus.NOT_FOUND)
def post(self, request, *args, **kwargs): jsMD5 = request.data.get("jsMD5") if jsMD5 is None: return ErosResponse(data=None, status=ErosResponseStatus.PARAMS_ERROR) else: try: releases = Release.objects.filter(jsMD5=jsMD5) for release in releases: release.delete() return ErosResponse() except Release.DoesNotExist: return ErosResponse(status=ErosResponseStatus.NOT_FOUND)
def post(self, request, *args, **kwargs): package_id = request.data.get("package_id") if package_id == None: return ErosResponse(data=None, status=ErosResponseStatus.PARAMS_ERROR) else: try: package = Package.objects.get(id=package_id) jsVersion = package.jsVersion releases = Release.objects.filter(jsVersion=jsVersion) package.delete() for release in releases: release.delete() if default_storage.exists(package.jsMD5+'.zip'): default_storage.delete(package.jsMD5+'.zip') return ErosResponse() except Package.DoesNotExist: return ErosResponse(status=ErosResponseStatus.NOT_FOUND)
def post(self, request, *args, **kwargs): appName = request.data.get('appName') iOS = request.data.get('iOS') android = request.data.get('android') jsVersion = request.data.get('jsVersion') if appName is None or iOS is None or android is None or jsVersion is None: return ErosResponse( status=ErosResponseStatus.PARAMS_ERROR, detail="params is missing, maybe is appName,iOS or android") iOS_Records = Record.objects.filter(appName=appName, appPlatform='iOS', appVersion=iOS) android_Records = Record.objects.filter(appName=appName, appPlatform='Android', appVersion=android) iOS_Updated_Records = Record.objects.filter(appName=appName, appPlatform='iOS', appVersion=iOS, jsVersion=jsVersion) android_Updated_Records = Record.objects.filter(appName=appName, appPlatform='Android', appVersion=android, jsVersion=jsVersion) resData = { 'total': len(iOS_Records) + len(android_Records), 'totalUpdated': len(iOS_Updated_Records) + len(android_Updated_Records), 'iOS': len(iOS_Records), 'iOSUpdated': len(iOS_Updated_Records), 'Android': len(android_Records), "AndroidUpdate": len(android_Updated_Records) } return ErosResponse(data=resData)
def get(self, request, *args, **kwargs): records = Record.objects.order_by('jsVersion').distinct( 'jsVersion').values_list('jsVersion') serializer = self.get_serializer(records, many=True) return ErosResponse(data=serializer.data)
def handleRequest(self, requset): method = requset.method ip = requset.META.get('HTTP_X_FORWARDED_FOR') if ip is None: ip = requset.META.get('REMOTE_ADDR') requestData = None if method == 'GET': requestData = requset.query_params if method == 'POST': requestData = requset.data (validate, data) = self.validateData(requestData) if not validate: return ErosResponse(status=ErosResponseStatus.PARAMS_ERROR) else: if data['deviceToken'] is None: data['deviceToken'] = ip data['ip'] = ip ##TODO: 暂时安卓版本热更新遇到问题,暂时安卓不会受到更新提示 # if (data['appPlatform'] == 'Android'): # return ErosResponse(status=ErosResponseStatus.IS_LASTEST_PACKAGE) appName = data['appName'] jsMD5 = data['jsMD5'] oldPackages = Package.objects.filter(jsMD5=jsMD5) if len(oldPackages) > 0: data['jsVersion'] = oldPackages[0].jsVersion release = Release.gotHit(data) #获取命中的更新包 if not release: self.updateRecord(data) #更新记录 return ErosResponse(status=ErosResponseStatus.IS_LASTEST_PACKAGE) data['updateJSVersion'] = release.jsVersion self.updateRecord(data) #更新记录 try: package = Package.objects.get(appName=appName, jsVersion=release.jsVersion) newMD5 = package.jsMD5 oldMD5 = data['jsMD5'] isDiff = data['isDiff'] jsPath = DOWNLOAD_HOST + MEDIA_URL + newMD5 + '.zip' if newMD5 == oldMD5: return ErosResponse( status=ErosResponseStatus.IS_LASTEST_PACKAGE) if isDiff: # (isDiff, jsPath) = self.diffPackage(oldMD5,newMD5,'http://'+requset.get_host()+MEDIA_URL) (isDiff, jsPath) = self.diffPackage(oldMD5, newMD5, DOWNLOAD_HOST + MEDIA_URL) resData = { "diff": isDiff, # "path":'http://'+requset.get_host()+MEDIA_URL+oldMD5+'.zip', "path": jsPath, "showUpdateAlert": release.showUpdateAlert, "isForceUpdate": release.isForceUpdate, "changelog": release.changelog, } return ErosResponse(data=resData) except Package.DoesNotExist: return ErosResponse(status=ErosResponseStatus.PACKAGE_NOT_FOUND, detail="jsVersion[%s] not found" % (jsVersion))