SysManage.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
  5. @AUTHOR: ASJRD018
  6. @NAME: Ansjer
  7. @software: PyCharm
  8. @DATE: 2018/6/8 9:10
  9. @Version: python3.6
  10. @MODIFY DECORD:ansjer dev
  11. @file: SysManage.py
  12. @Contact: chanjunkai@163.com
  13. """
  14. from django.views.decorators.csrf import csrf_exempt
  15. from Service.CommonService import CommonService
  16. from Service.ModelService import ModelService
  17. from Ansjer.config import BASE_DIR
  18. from Object.ResponseObject import ResponseObject
  19. from Object.TokenObject import TokenObject
  20. import os
  21. @csrf_exempt
  22. def updateLog(request):
  23. response = ResponseObject()
  24. request.encoding = 'utf-8'
  25. if request.method == 'GET':
  26. request_dict = request.GET
  27. if request.method == 'POST':
  28. request_dict = request.POST
  29. else:
  30. response.json(404)
  31. token = request_dict.get('token',None)
  32. content = request_dict.get('content',None)
  33. if not content:
  34. return response.json(444,'content')
  35. tko = TokenObject(token)
  36. response.lang = tko.lang
  37. if tko.code != 0:
  38. return response.json(tko.code)
  39. userID = tko.userID
  40. own_permission = ModelService.check_perm(userID=userID, permID=50)
  41. if own_permission is not True:
  42. return response.json(404)
  43. file_path = os.path.join(BASE_DIR, 'static/Help/version.txt')
  44. try:
  45. with open(file_path, "w", encoding="utf-8") as f:
  46. f.write(content)
  47. except Exception as e:
  48. pass
  49. return response.json(0)
  50. # 文件流下载
  51. @csrf_exempt
  52. def downloadOTAInterface(request, fullPath, *callback_args, **callback_kwargs):
  53. res = ResponseObject()
  54. print('fullPath:')
  55. print(fullPath)
  56. if fullPath:
  57. if os.path.isfile(fullPath):
  58. try:
  59. wrapper = FileWrapper(open(fullPath, 'rb'))
  60. response = HttpResponse(wrapper, content_type="application/octet-stream")
  61. response['Content-Length'] = os.path.getsize(fullPath)
  62. response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(fullPath)
  63. response['Content-MD5'] = getMD5orSHA265(fullPath)
  64. # 校验文件md5值
  65. response['Content-SHA265'] = getMD5orSHA265(fullPath, 'SHA265')
  66. response['Content-CRC32'] = getMD5orSHA265(fullPath, 'CRC32')
  67. response['Content-Error'] = res.formal(0)
  68. return response
  69. except Exception as e:
  70. return res.json(906, repr(e))
  71. else:
  72. return res.json(907)
  73. else:
  74. return res.json(444, 'fullPath')