diff --git a/fir_client/src/components/FirAppInfosbaseinfo.vue b/fir_client/src/components/FirAppInfosbaseinfo.vue index 96b3e5b..16d76e0 100644 --- a/fir_client/src/components/FirAppInfosbaseinfo.vue +++ b/fir_client/src/components/FirAppInfosbaseinfo.vue @@ -191,7 +191,7 @@ let certinfo=data.data; this.uploadtostorage(file,certinfo); } - },{'methods':false,'data':{'app_id':this.currentapp.app_id,'upload_key':file.name,'ftype':'app'}}); + },{'methods':'GET','data':{'app_id':this.currentapp.app_id,'upload_key':file.name,'ftype':'app'}}); } else{ this.$message.error('上传应用图片大小不能超过 2MB!'); diff --git a/fir_client/src/components/FirAppInfostimeline.vue b/fir_client/src/components/FirAppInfostimeline.vue index f95af8b..c836b71 100644 --- a/fir_client/src/components/FirAppInfostimeline.vue +++ b/fir_client/src/components/FirAppInfostimeline.vue @@ -173,7 +173,6 @@ }, { "app_id": this.$route.params.id, "action": "timeline", - "methods": false }) }, del_release_app(app) { diff --git a/fir_client/src/components/FirApps.vue b/fir_client/src/components/FirApps.vue index 3286f6e..5864add 100644 --- a/fir_client/src/components/FirApps.vue +++ b/fir_client/src/components/FirApps.vue @@ -490,7 +490,7 @@ } loading.close(); }, { - 'methos': true, + 'methos': 'POST', 'data': {"bundleid": this.analyseappinfo.bundleid, "type": this.analyseappinfo.type} }) }, diff --git a/fir_client/src/components/FirUserProfileBase.vue b/fir_client/src/components/FirUserProfileBase.vue index add5843..feafb89 100644 --- a/fir_client/src/components/FirUserProfileBase.vue +++ b/fir_client/src/components/FirUserProfileBase.vue @@ -19,7 +19,7 @@
- + @@ -71,7 +81,7 @@ // eslint-disable-next-line no-console console.log(data.data); this.$message.success('上传成功'); - this.updateUserInfo({"methods":false}); + this.updateUserInfo({"methods":'GET'}); }else { this.$message.error('更新失败'); @@ -138,7 +148,7 @@ let certinfo=data.data; this.uploadtostorage(file,certinfo); } - },{'methods':false,'data':{'app_id':this.userinfo.uid,'upload_key':file.name,'ftype':'head'}}); + },{'methods':'GET','data':{'app_id':this.userinfo.uid,'upload_key':file.name,'ftype':'head'}}); return false; } @@ -153,18 +163,27 @@ return false; }, + setfunactive(item){ + for (let key in this.$refs) { + if(key === item){ + this.$refs[key].classList.add('active'); + }else { + this.$refs[key].classList.remove('active'); + } + } + }, autoSetInfoIndex() { if (this.$store.state.userInfoIndex === 0) { - this.$refs.userinfo.classList.add('active'); - this.$refs.changepwd.classList.remove('active'); + this.setfunactive('userinfo'); } else if (this.$store.state.userInfoIndex === 1) { - this.$refs.changepwd.classList.add('active'); - this.$refs.userinfo.classList.remove('active'); + this.setfunactive('changepwd'); + }else if (this.$store.state.userInfoIndex === 2) { + this.setfunactive('storage'); } } }, mounted() { this.autoSetInfoIndex(); - this.updateUserInfo({"methods":false}); + this.updateUserInfo({"methods":'GET'}); }, watch: { '$store.state.userInfoIndex': function () { this.autoSetInfoIndex(); diff --git a/fir_client/src/components/FirUserProfileInfo.vue b/fir_client/src/components/FirUserProfileInfo.vue index 637cc2e..99437cd 100644 --- a/fir_client/src/components/FirUserProfileInfo.vue +++ b/fir_client/src/components/FirUserProfileInfo.vue @@ -159,7 +159,7 @@ } }, getphonecode() { - this.updateUserInfo({"methods":false,'data':{'act':'sms'}}); + this.updateUserInfo({"methods":'GET','data':{'act':'sms'}}); } }, mounted() { diff --git a/fir_client/src/components/FirUserProfileStorage.vue b/fir_client/src/components/FirUserProfileStorage.vue new file mode 100644 index 0000000..54318ca --- /dev/null +++ b/fir_client/src/components/FirUserProfileStorage.vue @@ -0,0 +1,66 @@ + + + + + diff --git a/fir_client/src/restful/index.js b/fir_client/src/restful/index.js index 82a0662..d019b32 100644 --- a/fir_client/src/restful/index.js +++ b/fir_client/src/restful/index.js @@ -1,8 +1,6 @@ import Axios from 'axios' import VueCookies from 'vue-cookies' -import router from "../router"; - const https = require('https'); const Base64 = require('js-base64').Base64; Axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; @@ -43,9 +41,8 @@ export function set_auth_token() { set_auth_token(); -function getData(PostType = true, url, params = {}, callBack, load, isCode = false) { +function getData(methods = true, url, params = {}, callBack, load, isCode = false) { - let methods = PostType; if (methods === "DELETE") { Axios .delete(url, params) @@ -57,8 +54,7 @@ function getData(PostType = true, url, params = {}, callBack, load, isCode = fal } }) .catch(function (error) { - // eslint-disable-next-line no-console - console.log(error, error.response); + if (error && error.response) { switch (error.response.status) { case 400: @@ -122,280 +118,38 @@ function getData(PostType = true, url, params = {}, callBack, load, isCode = fal .catch(function (error) { // eslint-disable-next-line no-console console.log(error, error.response); - if (error && error.response) { - switch (error.response.status) { - case 400: - error.message = '请求错误(400)'; - break; - case 401: - error.message = '未授权,请重新登录(401)'; - break; - case 403: - error.message = '拒绝访问(403)'; - break; - case 404: - error.message = '请求出错(404)'; - break; - case 408: - error.message = '请求超时(408)'; - break; - case 500: - error.message = '服务器错误(500)'; - break; - case 501: - error.message = '服务未实现(501)'; - break; - case 502: - error.message = '网络错误(502)'; - break; - case 503: - error.message = '服务不可用(503)'; - break; - case 504: - error.message = '网络超时(504)'; - break; - case 505: - error.message = 'HTTP版本不受支持(505)'; - break; - default: - error.message = `连接出错(${error.response.status})!`; - } - } else { - error.message = '连接服务器失败!'; - } - if (error.message === 'Network Error') { - alert('网络连接失败'); - } else { - alert(error) - } + callBack(null); }); } - else if (PostType===true) { + else if (methods === 'POST') { Axios .post(url, params) .then(function (response) { - let type = response.data.type; if (isCode) { callBack(response.data); } else { callBack(response.data.data); } - let x = ''; - switch (type) { - case 8001: - x = "服务器内部错误"; - break; - case 8002: - x = "错误密码"; - break; - case 8004: - x = "验证码错误"; - break; - case 8005: - x = "没有这个玩家信息"; - break; - case 8006: - x = "请重新登录账号"; - break; - case 8009: - x = "没有权限"; - break; - case 8011: - x = "账号被冻结"; - break; - case 8013: - x = "用户名已存在"; - break; - case 9001: - x = "系统繁忙"; - break; - case 9007: - x = "错误的参数"; - break; - - case 20009: - x = "上传文件失败"; - break; - } - if (x !== '') { - alert(x) - } + }) .catch(function (error) { // eslint-disable-next-line no-console console.log(error, error.response); - if (error && error.response) { - switch (error.response.status) { - case 400: - error.message = '请求错误(400)'; - break; - case 401: - error.message = '未授权,请重新登录(401)'; - break; - case 403: - error.message = '拒绝访问(403)'; - break; - case 404: - error.message = '请求出错(404)'; - break; - case 408: - error.message = '请求超时(408)'; - break; - case 500: - error.message = '服务器错误(500)'; - break; - case 501: - error.message = '服务未实现(501)'; - break; - case 502: - error.message = '网络错误(502)'; - break; - case 503: - error.message = '服务不可用(503)'; - break; - case 504: - error.message = '网络超时(504)'; - break; - case 505: - error.message = 'HTTP版本不受支持(505)'; - break; - default: - error.message = `连接出错(${error.response.status})!`; - } - } else { - error.message = '连接服务器失败!'; - } - if (error.message === 'Network Error') { - alert('网络连接失败'); - } else { - alert(error) - } callBack(null); }); - } else { - // console.log(JSON.stringify(params) + "参数") - var uri = ''; - var keys = Object.keys(params); - var values = Object.values(params); - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - var value = values[i]; - uri = uri + key + "=" + value; - if (i < keys.length - 1) { - uri = uri + "&" - } - } - if (uri !== "") { - uri = "?" + uri - } - url = url + uri; + } else { Axios - .get(url, params) + .get(url, {params: params}) .then(function (response) { - let type = response.data.type; callBack(response.data); - let x = ''; - switch (type) { - case 8001: - x = "服务器内部错误"; - break; - case 8002: - x = "错误密码"; - break; - case 8004: - x = "验证码错误"; - break; - case 8005: - x = "没有这个玩家信息"; - break; - case 8006: - x = "请重新登录账号"; - break; - case 8009: - x = "没有权限"; - break; - case 8011: - x = "账号被冻结"; - break; - case 8013: - x = "用户名已存在"; - break; - case 9001: - x = "系统繁忙"; - break; - case 9007: - x = "错误的参数"; - break; - - case 20009: - x = "上传文件失败"; - break; - } - if (x !== '') { - alert(x) - } }) .catch(function (error) { - - - if (error && error.response) { - switch (error.response.status) { - case 400: - error.message = '请求错误(400)'; - break; - case 401: - error.message = '未授权,请重新登录(401)'; - break; - case 403: - error.message = '拒绝访问(403)'; - break; - case 404: - error.message = '请求出错(404)'; - break; - case 408: - error.message = '请求超时(408)'; - break; - case 500: - error.message = '服务器错误(500)'; - break; - case 501: - error.message = '服务未实现(501)'; - break; - case 502: - error.message = '网络错误(502)'; - break; - case 503: - error.message = '服务不可用(503)'; - break; - case 504: - error.message = '网络超时(504)'; - break; - case 505: - error.message = 'HTTP版本不受支持(505)'; - break; - default: - error.message = `连接出错(${error.response.status})!`; - } - } else { - error.message = '连接服务器失败!'; - } - if (error.message === 'Network Error') { - alert('网络连接失败') - } else { - - - if (error.response.status === 403) { - - router.push({name: 'FirLogin'}) - } else { - alert(error.message); - } - - } + // eslint-disable-next-line no-console + console.log(error, error.response); callBack(null); }); } @@ -404,7 +158,7 @@ function getData(PostType = true, url, params = {}, callBack, load, isCode = fal /**用户登录 */ export function loginFun(callBack, params, load = true) { getData( - true, + 'POST', USERSEVER + '/login', params, data => { @@ -435,7 +189,7 @@ export function logout(callBack, params, load = true) { /**用户应用列表 */ export function getapps(callBack, params, load = true) { getData( - false, + 'GET', USERSEVER + '/apps', params, data => { @@ -450,7 +204,7 @@ export function getapps(callBack, params, load = true) { /**用户应用详情 */ export function getappinfos(callBack, params, load = true) { getData( - false, + 'GET', USERSEVER + '/apps/' + params.app_id, {}, data => { @@ -530,7 +284,7 @@ export function updatereleaseapp(callBack, params, load = true) { /**用户应用详情 */ export function getapptimeline(callBack, params, load = true) { getData( - params.methods, + 'GET', USERSEVER + '/appinfos/' + params.app_id + '/' + params.action, {}, data => { @@ -546,7 +300,7 @@ export function getapptimeline(callBack, params, load = true) { /**根据短链接获取应用信息 */ export function getShortAppinfo(callBack, params, load = true) { getData( - false, + 'GET', USERSEVER + '/short/' + params.short , params, data => { @@ -558,6 +312,21 @@ export function getShortAppinfo(callBack, params, load = true) { ); } +/**用户app存储配置 */ +export function getStorageinfo(callBack, params, load = true) { + getData( + params.methods, + USERSEVER + '/storage' , + params.data, + data => { + callBack(data); + }, + load, + true, + true + ); +} + /**用户个人信息 */ export function userinfos(callBack, params, load = true) { @@ -608,7 +377,7 @@ export function analyseApps(callBack, params, load = true) { /**获取下载的url */ export function getdownloadurl(callBack, params, load = true) { getData( - false, + 'GET', USERSEVER + '/install/'+params.app_id , params.data, data => { diff --git a/fir_client/src/router/index.js b/fir_client/src/router/index.js index c48bad5..0bc90b1 100644 --- a/fir_client/src/router/index.js +++ b/fir_client/src/router/index.js @@ -26,6 +26,7 @@ import FirAppInfoscombo from "@/components/FirAppInfoscombo"; import FirUserProfile from "@/components/FirUserProfileBase"; import FirUserProfileInfo from "@/components/FirUserProfileInfo"; import FirUserProfileChangePwd from "@/components/FirUserProfileChangePwd"; +import FirUserProfileStorage from "@/components/FirUserProfileStorage"; const router = new VueRouter({ mode:'history', @@ -100,6 +101,10 @@ const router = new VueRouter({ path: 'setpasswd', name: 'FirUserProfileChangePwd', component: FirUserProfileChangePwd + }, { + path: 'storage', + name: 'FirUserProfileStorage', + component: FirUserProfileStorage } ] } diff --git a/fir_ser/api/models.py b/fir_ser/api/models.py index 1695fa1..ae30924 100644 --- a/fir_ser/api/models.py +++ b/fir_ser/api/models.py @@ -151,7 +151,7 @@ class AppStorage(models.Model): secret_key =models.CharField(max_length=128,blank=True, null=True, verbose_name="存储访问secret") bucket_name=models.CharField(max_length=128,blank=True, null=True, verbose_name="存储空间bucket_name") domain_name=models.CharField(max_length=128,blank=True, null=True, verbose_name="下载域名",help_text='fly-storage.dvcloud.xin,可以自定义端口') - is_https = models.BooleanField(default=True,blank=True, null=True, verbose_name="是否支持https") + is_https = models.BooleanField(default=True, verbose_name="是否支持https") additionalparameters = models.TextField(max_length=256,blank=True, null=True,verbose_name="额外参数", help_text='阿里云:{"sts_role_arn":"arn信息","endpoint":""} ') created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间") diff --git a/fir_ser/api/urls.py b/fir_ser/api/urls.py index dcf0185..2f082ba 100644 --- a/fir_ser/api/urls.py +++ b/fir_ser/api/urls.py @@ -22,6 +22,7 @@ from api.views.captcha import CaptchaView from api.views.apps import AppsView,AppInfoView,AppReleaseinfoView from api.views.download import ShortDownloadView from api.views.uploads import AppAnalyseView,UploadView +from api.views.storage import StorageView # router=DefaultRouter() @@ -33,6 +34,7 @@ urlpatterns = [ re_path("^logout",LogoutView.as_view()), re_path("^captcha_check/",CaptchaView.as_view()), re_path("^apps$", AppsView.as_view()), + re_path("^storage$", StorageView.as_view()), re_path("^apps/(?P\w+)", AppInfoView.as_view()), re_path("^appinfos/(?P\w+)/(?P\w+)", AppReleaseinfoView.as_view()), re_path("^upload$",UploadView.as_view()), diff --git a/fir_ser/api/utils/serializer.py b/fir_ser/api/utils/serializer.py index 23880f1..8c32a45 100644 --- a/fir_ser/api/utils/serializer.py +++ b/fir_ser/api/utils/serializer.py @@ -187,3 +187,12 @@ class AppReleaseSerializer(serializers.ModelSerializer): def get_editing(self, obj): return {"changelog":False,"binary_url":False} + + +class StorageSerializer(serializers.ModelSerializer): + class Meta: + model = models.AppStorage + # depth = 1 + exclude = ["user_id"] + + storage_type_display= serializers.CharField(source="get_storage_type_display") diff --git a/fir_ser/api/utils/storage/storage.py b/fir_ser/api/utils/storage/storage.py index 95c295f..2300ddd 100644 --- a/fir_ser/api/utils/storage/storage.py +++ b/fir_ser/api/utils/storage/storage.py @@ -15,7 +15,10 @@ from django.core.cache import cache class Storage(object): def __init__(self, user): - self.storage = self.get_storage(user) + try: + self.storage = self.get_storage(user) + except Exception as e: + self.storage=None def get_upload_token(self, filename, expires=900): if self.storage: diff --git a/fir_ser/api/views/storage.py b/fir_ser/api/views/storage.py new file mode 100644 index 0000000..038dd33 --- /dev/null +++ b/fir_ser/api/views/storage.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# project: 3月 +# author: liuyu +# date: 2020/3/4 + +from rest_framework.views import APIView +from api.utils.response import BaseResponse +from api.utils.auth import ExpiringTokenAuthentication +from rest_framework.response import Response +from django.db.models import Sum +import os +from fir_ser import settings +from api.utils.app.randomstrings import make_from_user_uuid +from api.utils.storage.storage import Storage +from api.utils.storage.caches import del_cache_response_by_short,get_app_today_download_times +from api.models import Apps, AppReleaseInfo,AppStorage +from api.utils.serializer import StorageSerializer + + + + + +class StorageView(APIView): + authentication_classes = [ExpiringTokenAuthentication, ] + def get(self, request): + res = BaseResponse() + # [1,2] 表示七牛存储和阿里云存储 + storage_obj = AppStorage.objects.filter(user_id=request.user,storage_type__in=[1,2]) + if storage_obj: + storage_serializer = StorageSerializer(storage_obj,many=True) + storage_data_lists = storage_serializer.data + storage_lists={} + for storage_data in storage_data_lists: + storage_type = storage_data.get("storage_type") + if not storage_lists.get(storage_type): + storage_lists[storage_type]=[] + storage_lists[storage_type].append(storage_data) + res.data=storage_lists + + use_storage_obj = request.user.storage + if use_storage_obj: + res.storage=use_storage_obj.id + else: + res.storage = None + + return Response(res.dict)