增加存储配置

super_signature
nineven 5 years ago
parent 8d18692809
commit 1027110786
  1. 2
      fir_client/src/components/FirAppInfosbaseinfo.vue
  2. 1
      fir_client/src/components/FirAppInfostimeline.vue
  3. 2
      fir_client/src/components/FirApps.vue
  4. 35
      fir_client/src/components/FirUserProfileBase.vue
  5. 2
      fir_client/src/components/FirUserProfileInfo.vue
  6. 66
      fir_client/src/components/FirUserProfileStorage.vue
  7. 291
      fir_client/src/restful/index.js
  8. 5
      fir_client/src/router/index.js
  9. 2
      fir_ser/api/models.py
  10. 2
      fir_ser/api/urls.py
  11. 9
      fir_ser/api/utils/serializer.py
  12. 5
      fir_ser/api/utils/storage/storage.py
  13. 47
      fir_ser/api/views/storage.py

@ -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!');

@ -173,7 +173,6 @@
}, {
"app_id": this.$route.params.id,
"action": "timeline",
"methods": false
})
},
del_release_app(app) {

@ -490,7 +490,7 @@
}
loading.close();
}, {
'methos': true,
'methos': 'POST',
'data': {"bundleid": this.analyseappinfo.bundleid, "type": this.analyseappinfo.type}
})
},

@ -19,7 +19,7 @@
<div class="user_pro_tabs">
<el-row :gutter="12" class="row">
<el-col :span="6" :offset="6">
<el-col :span="6" :offset="3">
<div class="col-4">
<a @click="$router.push({name:'FirUserProfileInfo'})" ref="userinfo" class="">
<span>
@ -39,6 +39,16 @@
</el-col>
<el-col :span="6">
<div class="col-4">
<a ref="storage" class="" @click="$router.push({name:'FirUserProfileStorage'})">
<span><i class="el-icon-coin"></i></span>
存储配置
</a>
</div>
</el-col>
</el-row>
</div>
@ -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();

@ -159,7 +159,7 @@
}
},
getphonecode() {
this.updateUserInfo({"methods":false,'data':{'act':'sms'}});
this.updateUserInfo({"methods":'GET','data':{'act':'sms'}});
}
}, mounted() {

@ -0,0 +1,66 @@
<template>
<div>
<el-select v-model="use_storage_id" clearable filterable placeholder="请选择" @change="select_storage">
<el-option-group
v-for="storage_group in fstorage_lists"
:key="storage_group.group_name"
:label="storage_group.group_name">
<el-option
v-for="storage in storage_group.storage"
:key="storage.id"
:label="storage.name"
:value="storage.id">
</el-option>
</el-option-group>
</el-select>
</div>
</template>
<script>
import {getStorageinfo} from "../restful";
export default {
name: "FirUserProfileStorage",
data() {
return {
fstorage_lists:[[]],
use_storage_id:null
}
}, methods: {
select_storage(a){
// eslint-disable-next-line no-console
console.log(a)
},
format_storage(storage_lists){
for(let key in storage_lists){
let storage = storage_lists[key];
if(storage[0].storage_type_display){
this.fstorage_lists.unshift({'group_name':storage[0].storage_type_display,'storage':storage})
}
}
},
getstorageinfoFun() {
// eslint-disable-next-line no-console
getStorageinfo(data=>{
if(data.code === 1000){
this.format_storage(data.data);
this.use_storage_id = data.data.storage;
}else {
this.$message.error('存储获取失败,'+data);
}
},{"methods":false});
}
}, mounted() {
this.$store.dispatch('douserInfoIndex', 2);
this.getstorageinfoFun();
}
}
</script>
<style scoped>
</style>

@ -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 => {

@ -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
}
]
}

@ -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="创建时间")

@ -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<app_id>\w+)", AppInfoView.as_view()),
re_path("^appinfos/(?P<app_id>\w+)/(?P<act>\w+)", AppReleaseinfoView.as_view()),
re_path("^upload$",UploadView.as_view()),

@ -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")

@ -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:

@ -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)
Loading…
Cancel
Save