#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved. @AUTHOR: ASJRD018 @NAME: Ansjer @software: PyCharm @DATE: 2018/6/8 9:10 @Version: python3.6 @MODIFY DECORD:ansjer dev @file: SysManage.py @Contact: chanjunkai@163.com """ from django.views.decorators.csrf import csrf_exempt from Service.CommonService import CommonService from Service.ModelService import ModelService from Ansjer.config import BASE_DIR from Object.ResponseObject import ResponseObject from Object.TokenObject import TokenObject import os @csrf_exempt def updateLog(request): response = ResponseObject() request.encoding = 'utf-8' if request.method == 'GET': request_dict = request.GET if request.method == 'POST': request_dict = request.POST else: response.json(404) token = request_dict.get('token',None) content = request_dict.get('content',None) if not content: return response.json(444,'content') tko = TokenObject(token) response.lang = tko.lang if tko.code != 0: return response.json(tko.code) userID = tko.userID own_permission = ModelService.check_perm(userID=userID, permID=50) if own_permission is not True: return response.json(404) file_path = os.path.join(BASE_DIR, 'static/Help/version.txt') try: with open(file_path, "w", encoding="utf-8") as f: f.write(content) except Exception as e: pass return response.json(0) # 文件流下载 @csrf_exempt def downloadOTAInterface(request, fullPath, *callback_args, **callback_kwargs): res = ResponseObject() print('fullPath:') print(fullPath) if fullPath: if os.path.isfile(fullPath): try: 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'] = res.formal(0) return response except Exception as e: return res.json(906, repr(e)) else: return res.json(907) else: return res.json(444, 'fullPath')