From d34f80f391d983cede269904e6ac8cd5b1998df3 Mon Sep 17 00:00:00 2001 From: nineven Date: Tue, 31 Mar 2020 17:00:11 +0800 Subject: [PATCH] fix aliyun oss bugs --- .gitignore | 1 + fir_client/{ => fir_client}/.gitignore | 0 fir_client/{ => fir_client}/README.md | 0 fir_client/{ => fir_client}/babel.config.js | 0 fir_client/{ => fir_client}/package-lock.json | 0 fir_client/{ => fir_client}/package.json | 0 fir_client/{ => fir_client}/public/index.html | 0 fir_client/{ => fir_client}/src/App.vue | 0 .../src/assets/download_pattern_left.png | Bin .../src/assets/download_pattern_right.png | Bin fir_client/{ => fir_client}/src/assets/gt.js | 0 .../src/assets/icon/iconfont.css | 0 .../src/assets/icon/iconfont.eot | Bin .../src/assets/icon/iconfont.js | 0 .../src/assets/icon/iconfont.json | 0 .../src/assets/icon/iconfont.svg | 0 .../src/assets/icon/iconfont.ttf | Bin .../src/assets/icon/iconfont.woff | Bin .../src/assets/icon/iconfont.woff2 | Bin .../{ => fir_client}/src/assets/imgs/1.png | Bin .../{ => fir_client}/src/assets/imgs/2.png | Bin .../{ => fir_client}/src/assets/imgs/3.png | Bin .../{ => fir_client}/src/assets/imgs/5.png | Bin .../{ => fir_client}/src/assets/imgs/6.png | Bin .../{ => fir_client}/src/assets/imgs/7.png | Bin .../{ => fir_client}/src/assets/imgs/8.png | Bin .../{ => fir_client}/src/assets/imgs/9.png | Bin .../{ => fir_client}/src/assets/plane.svg | 0 .../{ => fir_client}/src/assets/propeller.svg | 0 .../src/components/FirAppBase.vue | 0 .../src/components/FirAppInfosBase.vue | 0 .../src/components/FirAppInfosbaseinfo.vue | 0 .../src/components/FirAppInfoscombo.vue | 0 .../src/components/FirAppInfostimeline.vue | 0 .../src/components/FirApps.vue | 0 .../src/components/FirDownload.vue | 2 +- .../src/components/FirHeader.vue | 0 .../src/components/FirIndex.vue | 0 .../src/components/FirLogin.vue | 0 .../src/components/FirRegist.vue | 0 .../src/components/FirUserProfileBase.vue | 0 .../components/FirUserProfileChangePwd.vue | 0 .../src/components/FirUserProfileInfo.vue | 0 fir_client/{ => fir_client}/src/main.js | 0 .../{ => fir_client}/src/restful/index.js | 2 +- .../{ => fir_client}/src/router/index.js | 0 .../{ => fir_client}/src/store/index.js | 0 .../{ => fir_client}/src/utils/index.js | 0 fir_client/{ => fir_client}/yarn.lock | 0 fir_client/public/download.html | 17 --- fir_client/src/Download.vue | 77 ------------ fir_client/src/download.js | 16 --- fir_client/src/restful/download.js | 117 ------------------ fir_client/src/router/download.js | 26 ---- fir_client/vue.config.js | 16 --- .../api/migrations/0017_auto_20200331_1543.py | 28 +++++ fir_ser/api/models.py | 6 +- fir_ser/api/utils/storage/aliyunApi.py | 22 ++-- fir_ser/api/utils/storage/localApi.py | 10 +- fir_ser/api/utils/storage/qiniuApi.py | 18 +-- fir_ser/api/utils/storage/storage.py | 15 ++- fir_ser/fir_ser/settings.py | 33 ++++- 62 files changed, 108 insertions(+), 298 deletions(-) rename fir_client/{ => fir_client}/.gitignore (100%) rename fir_client/{ => fir_client}/README.md (100%) rename fir_client/{ => fir_client}/babel.config.js (100%) rename fir_client/{ => fir_client}/package-lock.json (100%) rename fir_client/{ => fir_client}/package.json (100%) rename fir_client/{ => fir_client}/public/index.html (100%) rename fir_client/{ => fir_client}/src/App.vue (100%) rename fir_client/{ => fir_client}/src/assets/download_pattern_left.png (100%) rename fir_client/{ => fir_client}/src/assets/download_pattern_right.png (100%) rename fir_client/{ => fir_client}/src/assets/gt.js (100%) rename fir_client/{ => fir_client}/src/assets/icon/iconfont.css (100%) rename fir_client/{ => fir_client}/src/assets/icon/iconfont.eot (100%) rename fir_client/{ => fir_client}/src/assets/icon/iconfont.js (100%) rename fir_client/{ => fir_client}/src/assets/icon/iconfont.json (100%) rename fir_client/{ => fir_client}/src/assets/icon/iconfont.svg (100%) rename fir_client/{ => fir_client}/src/assets/icon/iconfont.ttf (100%) rename fir_client/{ => fir_client}/src/assets/icon/iconfont.woff (100%) rename fir_client/{ => fir_client}/src/assets/icon/iconfont.woff2 (100%) rename fir_client/{ => fir_client}/src/assets/imgs/1.png (100%) rename fir_client/{ => fir_client}/src/assets/imgs/2.png (100%) rename fir_client/{ => fir_client}/src/assets/imgs/3.png (100%) rename fir_client/{ => fir_client}/src/assets/imgs/5.png (100%) rename fir_client/{ => fir_client}/src/assets/imgs/6.png (100%) rename fir_client/{ => fir_client}/src/assets/imgs/7.png (100%) rename fir_client/{ => fir_client}/src/assets/imgs/8.png (100%) rename fir_client/{ => fir_client}/src/assets/imgs/9.png (100%) rename fir_client/{ => fir_client}/src/assets/plane.svg (100%) rename fir_client/{ => fir_client}/src/assets/propeller.svg (100%) rename fir_client/{ => fir_client}/src/components/FirAppBase.vue (100%) rename fir_client/{ => fir_client}/src/components/FirAppInfosBase.vue (100%) rename fir_client/{ => fir_client}/src/components/FirAppInfosbaseinfo.vue (100%) rename fir_client/{ => fir_client}/src/components/FirAppInfoscombo.vue (100%) rename fir_client/{ => fir_client}/src/components/FirAppInfostimeline.vue (100%) rename fir_client/{ => fir_client}/src/components/FirApps.vue (100%) rename fir_client/{ => fir_client}/src/components/FirDownload.vue (99%) rename fir_client/{ => fir_client}/src/components/FirHeader.vue (100%) rename fir_client/{ => fir_client}/src/components/FirIndex.vue (100%) rename fir_client/{ => fir_client}/src/components/FirLogin.vue (100%) rename fir_client/{ => fir_client}/src/components/FirRegist.vue (100%) rename fir_client/{ => fir_client}/src/components/FirUserProfileBase.vue (100%) rename fir_client/{ => fir_client}/src/components/FirUserProfileChangePwd.vue (100%) rename fir_client/{ => fir_client}/src/components/FirUserProfileInfo.vue (100%) rename fir_client/{ => fir_client}/src/main.js (100%) rename fir_client/{ => fir_client}/src/restful/index.js (99%) rename fir_client/{ => fir_client}/src/router/index.js (100%) rename fir_client/{ => fir_client}/src/store/index.js (100%) rename fir_client/{ => fir_client}/src/utils/index.js (100%) rename fir_client/{ => fir_client}/yarn.lock (100%) delete mode 100644 fir_client/public/download.html delete mode 100644 fir_client/src/Download.vue delete mode 100644 fir_client/src/download.js delete mode 100644 fir_client/src/restful/download.js delete mode 100644 fir_client/src/router/download.js delete mode 100644 fir_client/vue.config.js create mode 100644 fir_ser/api/migrations/0017_auto_20200331_1543.py diff --git a/.gitignore b/.gitignore index ff19320..0dfb38d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ fir_ser/db.sqlite3 *.pyc fir_ser/files/ fir_ser/venv/ +fir_client/.idea diff --git a/fir_client/.gitignore b/fir_client/fir_client/.gitignore similarity index 100% rename from fir_client/.gitignore rename to fir_client/fir_client/.gitignore diff --git a/fir_client/README.md b/fir_client/fir_client/README.md similarity index 100% rename from fir_client/README.md rename to fir_client/fir_client/README.md diff --git a/fir_client/babel.config.js b/fir_client/fir_client/babel.config.js similarity index 100% rename from fir_client/babel.config.js rename to fir_client/fir_client/babel.config.js diff --git a/fir_client/package-lock.json b/fir_client/fir_client/package-lock.json similarity index 100% rename from fir_client/package-lock.json rename to fir_client/fir_client/package-lock.json diff --git a/fir_client/package.json b/fir_client/fir_client/package.json similarity index 100% rename from fir_client/package.json rename to fir_client/fir_client/package.json diff --git a/fir_client/public/index.html b/fir_client/fir_client/public/index.html similarity index 100% rename from fir_client/public/index.html rename to fir_client/fir_client/public/index.html diff --git a/fir_client/src/App.vue b/fir_client/fir_client/src/App.vue similarity index 100% rename from fir_client/src/App.vue rename to fir_client/fir_client/src/App.vue diff --git a/fir_client/src/assets/download_pattern_left.png b/fir_client/fir_client/src/assets/download_pattern_left.png similarity index 100% rename from fir_client/src/assets/download_pattern_left.png rename to fir_client/fir_client/src/assets/download_pattern_left.png diff --git a/fir_client/src/assets/download_pattern_right.png b/fir_client/fir_client/src/assets/download_pattern_right.png similarity index 100% rename from fir_client/src/assets/download_pattern_right.png rename to fir_client/fir_client/src/assets/download_pattern_right.png diff --git a/fir_client/src/assets/gt.js b/fir_client/fir_client/src/assets/gt.js similarity index 100% rename from fir_client/src/assets/gt.js rename to fir_client/fir_client/src/assets/gt.js diff --git a/fir_client/src/assets/icon/iconfont.css b/fir_client/fir_client/src/assets/icon/iconfont.css similarity index 100% rename from fir_client/src/assets/icon/iconfont.css rename to fir_client/fir_client/src/assets/icon/iconfont.css diff --git a/fir_client/src/assets/icon/iconfont.eot b/fir_client/fir_client/src/assets/icon/iconfont.eot similarity index 100% rename from fir_client/src/assets/icon/iconfont.eot rename to fir_client/fir_client/src/assets/icon/iconfont.eot diff --git a/fir_client/src/assets/icon/iconfont.js b/fir_client/fir_client/src/assets/icon/iconfont.js similarity index 100% rename from fir_client/src/assets/icon/iconfont.js rename to fir_client/fir_client/src/assets/icon/iconfont.js diff --git a/fir_client/src/assets/icon/iconfont.json b/fir_client/fir_client/src/assets/icon/iconfont.json similarity index 100% rename from fir_client/src/assets/icon/iconfont.json rename to fir_client/fir_client/src/assets/icon/iconfont.json diff --git a/fir_client/src/assets/icon/iconfont.svg b/fir_client/fir_client/src/assets/icon/iconfont.svg similarity index 100% rename from fir_client/src/assets/icon/iconfont.svg rename to fir_client/fir_client/src/assets/icon/iconfont.svg diff --git a/fir_client/src/assets/icon/iconfont.ttf b/fir_client/fir_client/src/assets/icon/iconfont.ttf similarity index 100% rename from fir_client/src/assets/icon/iconfont.ttf rename to fir_client/fir_client/src/assets/icon/iconfont.ttf diff --git a/fir_client/src/assets/icon/iconfont.woff b/fir_client/fir_client/src/assets/icon/iconfont.woff similarity index 100% rename from fir_client/src/assets/icon/iconfont.woff rename to fir_client/fir_client/src/assets/icon/iconfont.woff diff --git a/fir_client/src/assets/icon/iconfont.woff2 b/fir_client/fir_client/src/assets/icon/iconfont.woff2 similarity index 100% rename from fir_client/src/assets/icon/iconfont.woff2 rename to fir_client/fir_client/src/assets/icon/iconfont.woff2 diff --git a/fir_client/src/assets/imgs/1.png b/fir_client/fir_client/src/assets/imgs/1.png similarity index 100% rename from fir_client/src/assets/imgs/1.png rename to fir_client/fir_client/src/assets/imgs/1.png diff --git a/fir_client/src/assets/imgs/2.png b/fir_client/fir_client/src/assets/imgs/2.png similarity index 100% rename from fir_client/src/assets/imgs/2.png rename to fir_client/fir_client/src/assets/imgs/2.png diff --git a/fir_client/src/assets/imgs/3.png b/fir_client/fir_client/src/assets/imgs/3.png similarity index 100% rename from fir_client/src/assets/imgs/3.png rename to fir_client/fir_client/src/assets/imgs/3.png diff --git a/fir_client/src/assets/imgs/5.png b/fir_client/fir_client/src/assets/imgs/5.png similarity index 100% rename from fir_client/src/assets/imgs/5.png rename to fir_client/fir_client/src/assets/imgs/5.png diff --git a/fir_client/src/assets/imgs/6.png b/fir_client/fir_client/src/assets/imgs/6.png similarity index 100% rename from fir_client/src/assets/imgs/6.png rename to fir_client/fir_client/src/assets/imgs/6.png diff --git a/fir_client/src/assets/imgs/7.png b/fir_client/fir_client/src/assets/imgs/7.png similarity index 100% rename from fir_client/src/assets/imgs/7.png rename to fir_client/fir_client/src/assets/imgs/7.png diff --git a/fir_client/src/assets/imgs/8.png b/fir_client/fir_client/src/assets/imgs/8.png similarity index 100% rename from fir_client/src/assets/imgs/8.png rename to fir_client/fir_client/src/assets/imgs/8.png diff --git a/fir_client/src/assets/imgs/9.png b/fir_client/fir_client/src/assets/imgs/9.png similarity index 100% rename from fir_client/src/assets/imgs/9.png rename to fir_client/fir_client/src/assets/imgs/9.png diff --git a/fir_client/src/assets/plane.svg b/fir_client/fir_client/src/assets/plane.svg similarity index 100% rename from fir_client/src/assets/plane.svg rename to fir_client/fir_client/src/assets/plane.svg diff --git a/fir_client/src/assets/propeller.svg b/fir_client/fir_client/src/assets/propeller.svg similarity index 100% rename from fir_client/src/assets/propeller.svg rename to fir_client/fir_client/src/assets/propeller.svg diff --git a/fir_client/src/components/FirAppBase.vue b/fir_client/fir_client/src/components/FirAppBase.vue similarity index 100% rename from fir_client/src/components/FirAppBase.vue rename to fir_client/fir_client/src/components/FirAppBase.vue diff --git a/fir_client/src/components/FirAppInfosBase.vue b/fir_client/fir_client/src/components/FirAppInfosBase.vue similarity index 100% rename from fir_client/src/components/FirAppInfosBase.vue rename to fir_client/fir_client/src/components/FirAppInfosBase.vue diff --git a/fir_client/src/components/FirAppInfosbaseinfo.vue b/fir_client/fir_client/src/components/FirAppInfosbaseinfo.vue similarity index 100% rename from fir_client/src/components/FirAppInfosbaseinfo.vue rename to fir_client/fir_client/src/components/FirAppInfosbaseinfo.vue diff --git a/fir_client/src/components/FirAppInfoscombo.vue b/fir_client/fir_client/src/components/FirAppInfoscombo.vue similarity index 100% rename from fir_client/src/components/FirAppInfoscombo.vue rename to fir_client/fir_client/src/components/FirAppInfoscombo.vue diff --git a/fir_client/src/components/FirAppInfostimeline.vue b/fir_client/fir_client/src/components/FirAppInfostimeline.vue similarity index 100% rename from fir_client/src/components/FirAppInfostimeline.vue rename to fir_client/fir_client/src/components/FirAppInfostimeline.vue diff --git a/fir_client/src/components/FirApps.vue b/fir_client/fir_client/src/components/FirApps.vue similarity index 100% rename from fir_client/src/components/FirApps.vue rename to fir_client/fir_client/src/components/FirApps.vue diff --git a/fir_client/src/components/FirDownload.vue b/fir_client/fir_client/src/components/FirDownload.vue similarity index 99% rename from fir_client/src/components/FirDownload.vue rename to fir_client/fir_client/src/components/FirDownload.vue index f9bce66..4390b4b 100644 --- a/fir_client/src/components/FirDownload.vue +++ b/fir_client/fir_client/src/components/FirDownload.vue @@ -143,7 +143,7 @@ - - diff --git a/fir_client/src/download.js b/fir_client/src/download.js deleted file mode 100644 index dde0921..0000000 --- a/fir_client/src/download.js +++ /dev/null @@ -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'); diff --git a/fir_client/src/restful/download.js b/fir_client/src/restful/download.js deleted file mode 100644 index ae5073c..0000000 --- a/fir_client/src/restful/download.js +++ /dev/null @@ -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); - }, - ); -} - diff --git a/fir_client/src/router/download.js b/fir_client/src/router/download.js deleted file mode 100644 index c53b03c..0000000 --- a/fir_client/src/router/download.js +++ /dev/null @@ -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; diff --git a/fir_client/vue.config.js b/fir_client/vue.config.js deleted file mode 100644 index 6d479fd..0000000 --- a/fir_client/vue.config.js +++ /dev/null @@ -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'] - - }, - } -}; \ No newline at end of file diff --git a/fir_ser/api/migrations/0017_auto_20200331_1543.py b/fir_ser/api/migrations/0017_auto_20200331_1543.py new file mode 100644 index 0000000..24ae0d7 --- /dev/null +++ b/fir_ser/api/migrations/0017_auto_20200331_1543.py @@ -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='额外参数'), + ), + ] diff --git a/fir_ser/api/models.py b/fir_ser/api/models.py index 9e4cc67..efa1f85 100644 --- a/fir_ser/api/models.py +++ b/fir_ser/api/models.py @@ -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, ) diff --git a/fir_ser/api/utils/storage/aliyunApi.py b/fir_ser/api/utils/storage/aliyunApi.py index 0e26a57..3caa8ec 100644 --- a/fir_ser/api/utils/storage/aliyunApi.py +++ b/fir_ser/api/utils/storage/aliyunApi.py @@ -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) \ No newline at end of file diff --git a/fir_ser/api/utils/storage/localApi.py b/fir_ser/api/utils/storage/localApi.py index fffe36e..ddba4b1 100644 --- a/fir_ser/api/utils/storage/localApi.py +++ b/fir_ser/api/utils/storage/localApi.py @@ -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 diff --git a/fir_ser/api/utils/storage/qiniuApi.py b/fir_ser/api/utils/storage/qiniuApi.py index a6cd85d..a84980d 100644 --- a/fir_ser/api/utils/storage/qiniuApi.py +++ b/fir_ser/api/utils/storage/qiniuApi.py @@ -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 diff --git a/fir_ser/api/utils/storage/storage.py b/fir_ser/api/utils/storage/storage.py index 8cd316b..863fed7 100644 --- a/fir_ser/api/utils/storage/storage.py +++ b/fir_ser/api/utils/storage/storage.py @@ -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) diff --git a/fir_ser/fir_ser/settings.py b/fir_ser/fir_ser/settings.py index a4ac6bb..9531c1a 100644 --- a/fir_ser/fir_ser/settings.py +++ b/fir_ser/fir_ser/settings.py @@ -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 } ]