fix aliyun oss bugs

storage_cloud
nineven 5 years ago
parent 4b236bc289
commit d34f80f391
  1. 1
      .gitignore
  2. 0
      fir_client/fir_client/.gitignore
  3. 0
      fir_client/fir_client/README.md
  4. 0
      fir_client/fir_client/babel.config.js
  5. 0
      fir_client/fir_client/package-lock.json
  6. 0
      fir_client/fir_client/package.json
  7. 0
      fir_client/fir_client/public/index.html
  8. 0
      fir_client/fir_client/src/App.vue
  9. 0
      fir_client/fir_client/src/assets/download_pattern_left.png
  10. 0
      fir_client/fir_client/src/assets/download_pattern_right.png
  11. 0
      fir_client/fir_client/src/assets/gt.js
  12. 0
      fir_client/fir_client/src/assets/icon/iconfont.css
  13. 0
      fir_client/fir_client/src/assets/icon/iconfont.eot
  14. 0
      fir_client/fir_client/src/assets/icon/iconfont.js
  15. 0
      fir_client/fir_client/src/assets/icon/iconfont.json
  16. 0
      fir_client/fir_client/src/assets/icon/iconfont.svg
  17. 0
      fir_client/fir_client/src/assets/icon/iconfont.ttf
  18. 0
      fir_client/fir_client/src/assets/icon/iconfont.woff
  19. 0
      fir_client/fir_client/src/assets/icon/iconfont.woff2
  20. 0
      fir_client/fir_client/src/assets/imgs/1.png
  21. 0
      fir_client/fir_client/src/assets/imgs/2.png
  22. 0
      fir_client/fir_client/src/assets/imgs/3.png
  23. 0
      fir_client/fir_client/src/assets/imgs/5.png
  24. 0
      fir_client/fir_client/src/assets/imgs/6.png
  25. 0
      fir_client/fir_client/src/assets/imgs/7.png
  26. 0
      fir_client/fir_client/src/assets/imgs/8.png
  27. 0
      fir_client/fir_client/src/assets/imgs/9.png
  28. 0
      fir_client/fir_client/src/assets/plane.svg
  29. 0
      fir_client/fir_client/src/assets/propeller.svg
  30. 0
      fir_client/fir_client/src/components/FirAppBase.vue
  31. 0
      fir_client/fir_client/src/components/FirAppInfosBase.vue
  32. 0
      fir_client/fir_client/src/components/FirAppInfosbaseinfo.vue
  33. 0
      fir_client/fir_client/src/components/FirAppInfoscombo.vue
  34. 0
      fir_client/fir_client/src/components/FirAppInfostimeline.vue
  35. 0
      fir_client/fir_client/src/components/FirApps.vue
  36. 2
      fir_client/fir_client/src/components/FirDownload.vue
  37. 0
      fir_client/fir_client/src/components/FirHeader.vue
  38. 0
      fir_client/fir_client/src/components/FirIndex.vue
  39. 0
      fir_client/fir_client/src/components/FirLogin.vue
  40. 0
      fir_client/fir_client/src/components/FirRegist.vue
  41. 0
      fir_client/fir_client/src/components/FirUserProfileBase.vue
  42. 0
      fir_client/fir_client/src/components/FirUserProfileChangePwd.vue
  43. 0
      fir_client/fir_client/src/components/FirUserProfileInfo.vue
  44. 0
      fir_client/fir_client/src/main.js
  45. 2
      fir_client/fir_client/src/restful/index.js
  46. 0
      fir_client/fir_client/src/router/index.js
  47. 0
      fir_client/fir_client/src/store/index.js
  48. 0
      fir_client/fir_client/src/utils/index.js
  49. 0
      fir_client/fir_client/yarn.lock
  50. 17
      fir_client/public/download.html
  51. 77
      fir_client/src/Download.vue
  52. 16
      fir_client/src/download.js
  53. 117
      fir_client/src/restful/download.js
  54. 26
      fir_client/src/router/download.js
  55. 16
      fir_client/vue.config.js
  56. 28
      fir_ser/api/migrations/0017_auto_20200331_1543.py
  57. 6
      fir_ser/api/models.py
  58. 22
      fir_ser/api/utils/storage/aliyunApi.py
  59. 10
      fir_ser/api/utils/storage/localApi.py
  60. 18
      fir_ser/api/utils/storage/qiniuApi.py
  61. 15
      fir_ser/api/utils/storage/storage.py
  62. 33
      fir_ser/fir_ser/settings.py

1
.gitignore vendored

@ -3,3 +3,4 @@ fir_ser/db.sqlite3
*.pyc
fir_ser/files/
fir_ser/venv/
fir_client/.idea

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 118 KiB

Before

Width:  |  Height:  |  Size: 280 KiB

After

Width:  |  Height:  |  Size: 280 KiB

Before

Width:  |  Height:  |  Size: 213 KiB

After

Width:  |  Height:  |  Size: 213 KiB

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 86 KiB

Before

Width:  |  Height:  |  Size: 128 KiB

After

Width:  |  Height:  |  Size: 128 KiB

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 122 KiB

Before

Width:  |  Height:  |  Size: 168 KiB

After

Width:  |  Height:  |  Size: 168 KiB

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 80 KiB

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

@ -143,7 +143,7 @@
<script>
import QRCode from 'qrcodejs2'
import {getShortAppinfo,getdownloadurl} from '../restful/download'
import {getShortAppinfo,getdownloadurl} from '../restful'
export default {
name: "FirDownload",

@ -12,7 +12,7 @@ Axios.defaults.httpsAgent = new https.Agent({
});
// Axios.defaults.baseURL='';
const USERSEVER = 'https://fir.dvcloud.xin/api/v1/fir/server';
const USERSEVER = 'https://fly.dvcloud.xin/api/v1/fir/server';
// const USERSEVER = 'http://192.168.1.112:8000/api/v1/fir/server';

@ -1,17 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>App下载</title>
</head>
<body>
<noscript>
<strong>We're sorry but fly doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="download"></div>
<!-- built files will be auto injected -->
</body>
</html>

@ -1,77 +0,0 @@
<template>
<div id="download" ref="download">
<router-view></router-view>
</div>
</template>
<script>
export default {
name: 'download',
data() {
return {
}
},
}
</script>
<style>
body {
background-color: rgba(0, 166, 224, 0.18)
}
@font-face {font-family: "iconfont";
src: url('./assets/icon/iconfont.eot?t=1583637102320'); /* IE9 */
src: url('./assets/icon/iconfont.eot?t=1583637102320#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAAAnUAAsAAAAAEXwAAAmIAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEIGVgCEIAqUYJBKATYCJAMoCxYABCAFhG0HdhuGDlGUL1aT7CuMW3giIDU2lBZVYzMmA6BYbBoB4AIAvsWyNCR1ZYRAPDyt/e/cmdn1b4KYdG+eSCaJRMWjWPVE6ZTyQkZL4P/W2j938EFdZvf2bG4F1UgXqyQeKfBIqpGQb4i2eQ/W/4P6Ek9oYwayNWYT2liwtS7KBWzNL+pBXQarNpcN/6uINB8EdIMjCcASCSSx4cAb7oGJPvjzf6maMe0OLEmbbAtQ1TLH+t2bjwpcoLGH1RZY9/OCWElqEp69Ctt/lUoZgKMJ9DZKJTpb39oLSoVQBWoeMPQUKGtmZQQOra7u2bKID6DSppeMC3hP7x//HA0lSZWJNS/fr5uFyp+QiaT/uZpYwYv1OWFuR8Z+oBDfe93f5Fy5n9R9H1g8BBYZNWVZ128wWubBX4gsc00C/+npXSCHRbkuqBVJ6GSNo/zjETVVPQL/ONPxMyIeNT9HHoWfyzwSPzeo8DQ7IF5OsxdGGZpzMGqgeQOjCpoJxHejmz7ZYhE4AvIjgLIWhPY8ORu1xKf7mSXfEqJWz1lFqu4IsUVclojNFtvZeZZJWCxfTwc225MLw+IOJVu9jIhlZydks0WD2YzVCGJDzZv3bRWtVSPgFM6ZTJDKjCPGrSIdax2dlWgymUleOEnitJKXpPyEKz9ri1IZTMalepIwQ/od1OvB5hq3QpDBcnCLkASgX+Ot37xvI9/Ep9QGC7EF1DMQNJgws3VoBmqIDgCbNXYuVd01lKFvR5CqnITxPpi1Z23gbKCzVCYzT3meaFLvhr5kmfWJDrV+iz8KDo/ogiAUbGoo8SKbLBDTGVnfLmB0BpiGzuEVMxCPpJitnaqi7QPc/I2nEGN6Yb7eUj2voN2qcKHuJxEIVUb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F9TO4GBThIR9FjJtiZ8xg/ChkAXq1tt3w2hzPKZwI736/P0wDo+ZPZIlXSYD3aD2sXrdF5A3j5ZNUJ0UFHXkEF5IverEPDJNIP7+xVywGYJ0ziWSfsUy1NEorjp9+1rvrS37se5DXLePFDlKVFFHE2100cegueWb5QgzqyRdljFPtoQhvCSjo0cKVVaMkK2o4rlyAAA=') format('woff2'),
url('./assets/icon/iconfont.woff?t=1583637102320') format('woff'),
url('./assets/icon/iconfont.ttf?t=1583637102320') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+ */
url('./assets/icon/iconfont.svg?t=1583637102320#iconfont') format('svg'); /* iOS 4.1- */
}
.iconfont {
font-family: "iconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-android:before {
content: "\e61d";
}
.icon-android1:before {
content: "\e616";
}
.icon-android2:before {
content: "\e62a";
}
.icon-ios:before {
content: "\e60c";
}
.icon-IOS:before {
content: "\e68c";
}
.icon-ios1:before {
content: "\e601";
}
.icon-ios2:before {
content: "\e64b";
}
.icon-Android:before {
content: "\e6d4";
}
.icon-android3:before {
content: "\e625";
}
</style>

@ -1,16 +0,0 @@
import Vue from 'vue'
import Download from "@/Download.vue";
import router from "@/router/download.js";
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.config.productionTip = false;
Vue.use(ElementUI);
new Vue({
render: h => h(Download),
router,
}).$mount('#download');

@ -1,117 +0,0 @@
import Axios from 'axios'
const https = require('https');
Axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
Axios.defaults.withCredentials = true;
Axios.defaults.httpsAgent = new https.Agent({
keepAlive: true
});
// Axios.defaults.baseURL='';
const USERSEVER = 'https://fir.dvcloud.xin/api/v1/fir/server';
// const USERSEVER = 'http://192.168.1.112:8000/api/v1/fir/server';
function getData(url, params = {}, callBack) {
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;
Axios
.get(url, params)
.then(function (response) {
callBack(response.data);
let x = '';
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('网络连接失败')
}
callBack(null);
});
}
/**根据短链接获取应用信息 */
export function getShortAppinfo(callBack, params) {
getData(
USERSEVER + '/short/' + params.short ,
params,
data => {
callBack(data);
},
);
}
/**获取下载的url */
export function getdownloadurl(callBack, params) {
getData(
USERSEVER + '/install/'+params.app_id ,
params.data,
data => {
callBack(data);
},
);
}

@ -1,26 +0,0 @@
import Vue from 'vue'
//1.先导入
import VueRouter from 'vue-router'
//2.一定先use 一下
Vue.use(VueRouter);
// 解决push 同一个路由的错误
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
};
import FirDownload from "@/components/FirDownload.vue";
const router = new VueRouter({
mode:'history',
routes: [
{
path: '/:short',
name: 'FirDownload',
component: FirDownload
}
]
});
export default router;

@ -1,16 +0,0 @@
module.exports = {
pages: {
index: {
entry: 'src/main.js',
template: 'public/index.html',
chunks:['chunk-vendors','chunk-common','index']
},
download: {
entry: 'src/download.js',
template: 'public/download.html',
chunks:['chunk-vendors','chunk-common','download']
},
}
};

@ -0,0 +1,28 @@
# Generated by Django 3.0.3 on 2020-03-31 07:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0016_auto_20200327_1121'),
]
operations = [
migrations.AddField(
model_name='appstorage',
name='domain_name',
field=models.CharField(blank=True, help_text='fly-storage.dvcloud.xin,可以自定义端口', max_length=128, null=True, verbose_name='下载域名'),
),
migrations.AddField(
model_name='appstorage',
name='is_https',
field=models.BooleanField(blank=True, default=True, null=True, verbose_name='是否支持https'),
),
migrations.AlterField(
model_name='appstorage',
name='additionalparameters',
field=models.TextField(blank=True, help_text='阿里云:{"sts_role_arn":"arn信息","endpoint":""} ', max_length=256, null=True, verbose_name='额外参数'),
),
]

@ -147,10 +147,10 @@ class AppStorage(models.Model):
access_key =models.CharField(max_length=128,blank=True, null=True, verbose_name="存储访问key")
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")
additionalparameters = models.TextField(max_length=256,blank=True, null=True,verbose_name="额外参数",
help_text='阿里云:{"sts_role_arn":"arn信息","endpoint":""} '
' 七牛云:{"domain_name":""} '
'本地存储:{"domain_name":""}')
help_text='阿里云:{"sts_role_arn":"arn信息","endpoint":""} ')
created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
description = models.TextField('备注', blank=True, null=True, default=None, )

@ -51,7 +51,7 @@ class StsToken(object):
class AliYunOss(object):
def __init__(self,access_key,secret_key,bucket_name,endpoint,sts_role_arn):
def __init__(self,access_key,secret_key,bucket_name,endpoint,sts_role_arn,is_https,domain_name=None):
self.access_key_id = access_key or os.getenv('OSS_TEST_STS_ID', 'LTAI4FeTyvz74CHKCbYuTDGc')
self.access_key_secret = secret_key or os.getenv('OSS_TEST_STS_KEY', 'uineAEE7tp1d1w4Mv0yLqxvV0IVNTy')
self.bucket_name = bucket_name or os.getenv('OSS_TEST_BUCKET', 'fir-storage')
@ -59,7 +59,9 @@ class AliYunOss(object):
self.sts_role_arn = sts_role_arn or os.getenv('OSS_TEST_STS_ARN', 'acs:ram::1622120977387033:role/appstorage')
self.region_id = '-'.join( self.endpoint.split('.')[0].split("-")[1:3])
self.token = StsToken()
self.get_auth_bucket('init', 1800)
self.is_https = is_https
self.domain_name = domain_name
self.get_auth_bucket('init', 900)
def fetch_sts_token(self,name,expires):
@ -95,19 +97,25 @@ class AliYunOss(object):
def get_auth_bucket(self,name,expires):
self.fetch_sts_token(name,expires)
uri = 'http://'
if self.is_https:
uri = 'https://'
url = self.endpoint
is_cname=False
if self.domain_name:
url = self.domain_name
is_cname=True
auth = oss2.StsAuth(self.token.access_key_id, self.token.access_key_secret, self.token.security_token)
self.bucket = oss2.Bucket(auth, self.endpoint,self.bucket_name)
self.bucket = oss2.Bucket(auth,uri+url,self.bucket_name,is_cname=is_cname)
def get_download_url(self,name,expires=1800,ftype=None):
# self.get_auth_bucket(name,expires)
private_url=self.bucket.sign_url('GET',name,expires)
print(private_url)
return private_url
def del_file(self,name):
# self.fetch_sts_token(name,expires=300)
# auth = oss2.StsAuth(self.token.access_key_id, self.token.access_key_secret, self.token.security_token)
# bucket = oss2.Bucket(auth, self.endpoint,self.bucket_name)
return self.bucket.delete_object(name)
return self.bucket.delete_object(name)

@ -11,8 +11,9 @@ from fir_ser import settings
import os
class LocalStorage(object):
def __init__(self,**kwargs):
self.domain_name = kwargs.get('domain_name')
def __init__(self,domain_name,is_https):
self.domain_name = domain_name
self.is_https = is_https
def get_upload_token(self,name,expires):
dtoken = DownloadToken()
@ -21,7 +22,10 @@ class LocalStorage(object):
def get_download_url(self,name,expires=1800,ftype=None):
dtoken = DownloadToken()
base_url = '/'.join([self.domain_name,'download', name])
download_url = base_url + "?token=" + dtoken.make_token(name,expires)
uri='http://'
if self.is_https:
uri='https://'
download_url = uri+ base_url + "?token=" + dtoken.make_token(name,expires)
if ftype:
download_url = download_url + '&ftype=' + ftype
return download_url

@ -10,11 +10,12 @@ from qiniu import Auth
from qiniu import BucketManager
class QiNiuOss(object):
def __init__(self,access_key,secret_key,bucket_name,domain_name):
access_key=access_key or "mTqfvkLVSTVb2_1ERjDlFS_WAHLSkpDxYr4e4fiJ"
secret_key=secret_key or "0G9fXfgmi8h1-bmEsABYkE6apf8IuwKpj3hYLynv"
self.bucket_name = bucket_name or 'fir-storage'
self.domain_name = domain_name or 'fly-cdn.dvcloud.xin'
def __init__(self,access_key,secret_key,bucket_name,domain_name,is_https):
access_key=access_key
secret_key=secret_key
self.bucket_name = bucket_name
self.domain_name = domain_name
self.is_https = is_https
self.qiniu_obj = Auth(access_key,secret_key)
def get_upload_token(self,name,expires=1800):
@ -33,11 +34,13 @@ class QiNiuOss(object):
def get_download_url(self,name,expires=1800,ftype=None):
#有两种方式构造base_url的形式
base_url = '%s/%s' % (self.domain_name, name)
uri = 'http://'
if self.is_https:
uri = 'https://'
base_url = '%s%s/%s' % (uri,self.domain_name, name)
#或者直接输入url的方式下载
#可以设置token过期时间
private_url = self.qiniu_obj.private_download_url(base_url, expires=expires)
print(private_url)
return private_url
def del_file(self,name):
@ -45,6 +48,5 @@ class QiNiuOss(object):
bucket = BucketManager(self.qiniu_obj)
# 删除bucket_name 中的文件 key
ret, info = bucket.delete(self.bucket_name, name)
print(info)
return ret

@ -16,11 +16,11 @@ class Storage(object):
def __init__(self, user):
self.storage = self.get_storage(user)
def get_upload_token(self, filename, expires=600):
def get_upload_token(self, filename, expires=900):
if self.storage:
return self.storage.get_upload_token(filename, expires)
def get_download_url(self, filename, expires=600,ftype=None):
def get_download_url(self, filename, expires=900,ftype=None):
if self.storage:
return self.storage.get_download_url(filename, expires,ftype)
@ -44,6 +44,7 @@ class Storage(object):
new_storage_obj = AliYunOss(**auth)
else:
new_storage_obj = LocalStorage(**auth)
new_storage_obj.storage_type = storage_type
return new_storage_obj
else:
return self.get_default_storage()
@ -60,10 +61,14 @@ class Storage(object):
auth = storage.get('auth',{})
if storage_type == 1:
new_storage_obj = QiNiuOss(**auth)
new_storage_obj.storage_type=1
elif storage_type == 2:
new_storage_obj = AliYunOss(**auth)
new_storage_obj.storage_type=2
else:
new_storage_obj = LocalStorage(**auth)
new_storage_obj.storage_type=3
return new_storage_obj
return None
@ -71,14 +76,16 @@ class Storage(object):
def get_storage_type(self):
if self.storage_obj:
return self.storage_obj.storage_type
if self.storage:
return self.storage.storage_type
def get_storage_auth(self, storage_obj):
auth_dict = {
'access_key': storage_obj.access_key,
'secret_key': storage_obj.secret_key,
'bucket_name': storage_obj.bucket_name,
'domain_name': storage_obj.domain_name,
'is_https':storage_obj.is_https
}
try:
additionalparameters = json.loads(storage_obj.additionalparameters)

@ -152,7 +152,7 @@ GEE_TEST = {
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://192.168.137.130:6379",
"LOCATION": "redis://127.0.0.1:6379",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"CONNECTION_POOL_KWARGS": {"max_connections": 100},
@ -176,8 +176,37 @@ THIRD_PART_CONFIG = {
{
'name': 'local',
'type': 0,
'auth': {'domain_name': 'http://127.0.0.1:8000'}, # 正式环境需要填写正式的访问域名
'auth': {
'domain_name': 'fly.dvcloud.xin', # 正式环境需要填写正式的访问域名
'is_https':False,
},
'active': True
},
{
'name': 'aliyun',
'type': 2,
'auth': {
'access_key': 'LTAI4FkbTRqejBAzB1yQZpjR',
'secret_key': '2WzCsKjYXxOvU4wPtTmrrXnxiLIxy9',
'bucket_name': 'fly-app-storage',
'sts_role_arn':'acs:ram::1886562303345632:role/fly-app-storage',
'endpoint':'oss-cn-beijing.aliyuncs.com',
'is_https':True,
'domain_name':'ali.storage.dvcloud.xin'
},
'active': False
},
{
'name': 'qiniuyun',
'type': 1,
'auth': {
'access_key': 'mTqfvkLVSTVb2_1ERjDlFS_WAHLSkpDxYr4e4fiJ',
'secret_key': '0G9fXfgmi8h1-bmEsABYkE6apf8IuwKpj3hYLynv',
'bucket_name': 'fir-storage',
'is_https': False,
'domain_name': 'fly-cdn.dvcloud.xin'
},
'active': False
}
]

Loading…
Cancel
Save