|
@@ -0,0 +1,96 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+import json
|
|
|
+import time
|
|
|
+import urllib
|
|
|
+import uuid
|
|
|
+import boto3
|
|
|
+import threading
|
|
|
+import logging
|
|
|
+from boto3.session import Session
|
|
|
+from django.http import JsonResponse, HttpResponseRedirect, HttpResponse
|
|
|
+from django.views.generic.base import View
|
|
|
+from Model.models import Device_Info, Role, MenuModel, VodBucketModel
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
+from Object.UidTokenObject import UidTokenObject
|
|
|
+from Service.CommonService import CommonService
|
|
|
+from django.db.models import Q, F
|
|
|
+from time import strftime
|
|
|
+
|
|
|
+
|
|
|
+class serveManagement(View):
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.GET, request, operation)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.POST, request, operation)
|
|
|
+
|
|
|
+ def validation(self, request_dict, request, operation):
|
|
|
+ language = request_dict.get('language', 'en')
|
|
|
+ response = ResponseObject(language, 'pc')
|
|
|
+ if operation == '??':
|
|
|
+ return 0
|
|
|
+ else:
|
|
|
+ tko = TokenObject(
|
|
|
+ request.META.get('HTTP_AUTHORIZATION'),
|
|
|
+ returntpye='pc')
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ response.lang = tko.lang
|
|
|
+ userID = tko.userID
|
|
|
+ if operation == 'getVodBucketList':
|
|
|
+ return self.getVodBucketList(userID, request_dict, response)
|
|
|
+ elif operation == 'addOrEditVodBucket':
|
|
|
+ return self.addOrEditVodBucket(userID, request_dict, response)
|
|
|
+ else:
|
|
|
+ return response.json(404)
|
|
|
+
|
|
|
+ def getVodBucketList(self, userID, request_dict, response):
|
|
|
+ # 获取存储桶列表
|
|
|
+ pageNo = request_dict.get('pageNo', None)
|
|
|
+ pageSize = request_dict.get('pageSize', None)
|
|
|
+
|
|
|
+ if not all([pageNo, pageSize]):
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ page = int(pageNo)
|
|
|
+ line = int(pageSize)
|
|
|
+ try:
|
|
|
+ vod_bucket_qs = VodBucketModel.objects.filter().all()
|
|
|
+ count = vod_bucket_qs.count()
|
|
|
+ vod_buckets = vod_bucket_qs[(page - 1) * line:page * line]
|
|
|
+ vod_bucket_list = []
|
|
|
+ for vod_bucket in vod_buckets:
|
|
|
+ vod_bucket_list.append({
|
|
|
+ 'bucket': vod_bucket.bucket,
|
|
|
+ 'storeDay': vod_bucket.storeDay,
|
|
|
+ 'content': vod_bucket.content,
|
|
|
+ 'endpoint': vod_bucket.endpoint,
|
|
|
+ 'area': vod_bucket.area,
|
|
|
+ 'region': vod_bucket.region,
|
|
|
+ 'is_free': vod_bucket.is_free,
|
|
|
+ 'mold': vod_bucket.mold,
|
|
|
+ 'region_id': vod_bucket.region_id,
|
|
|
+ 'addTime': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(vod_bucket.addTime)),
|
|
|
+ 'updTime': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(vod_bucket.updTime)),
|
|
|
+ })
|
|
|
+ print('vod_bucket_list: ', vod_bucket_list)
|
|
|
+ return response.json(
|
|
|
+ 0, {'list': vod_bucket_list, 'total': count})
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
+
|
|
|
+ def addOrEditVodBucket(self, userID, request_dict, response):
|
|
|
+ # 添加/编辑存储桶
|
|
|
+ print('request_dict: ', request_dict)
|
|
|
+ try:
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|