From 57df7f8dfe2b1ea4f3d0cb542d5d6d258be54f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Mon, 8 Nov 2021 14:36:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20OSS=20=E4=B8=83?= =?UTF-8?q?=E7=89=9B=E4=BA=91=20token=20=E8=BF=87=E6=9C=9F=E6=9C=AA?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oss/service/impl/QiniuCloudStorageStrategy.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java index e9b8dc096..0c23e7612 100644 --- a/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java +++ b/ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java @@ -24,7 +24,7 @@ public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy { private UploadManager uploadManager; private BucketManager bucketManager; - private String token; + private Auth auth; @Override public void init(CloudStorageProperties cloudStorageProperties) { @@ -35,9 +35,8 @@ public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy { config.useHttpsDomains = false; config.useHttpsDomains = "Y".equals(properties.getIsHttps()); uploadManager = new UploadManager(config); - Auth auth = Auth.create(properties.getAccessKey(), properties.getSecretKey()); + auth = Auth.create(properties.getAccessKey(), properties.getSecretKey()); String bucketName = properties.getBucketName(); - token = auth.uploadToken(bucketName); bucketManager = new BucketManager(auth, config); if (!ArrayUtil.contains(bucketManager.buckets(), bucketName)) { @@ -69,9 +68,10 @@ public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy { @Override public UploadResult upload(byte[] data, String path, String contentType) { try { - Response res = uploadManager.put(data, path, token, null, contentType, false); + String token = auth.uploadToken(properties.getBucketName()); + Response res = uploadManager.put(data, path, token, null, contentType, false); if (!res.isOK()) { - throw new RuntimeException("上传七牛出错:" + res.toString()); + throw new RuntimeException("上传七牛出错:" + res.error); } } catch (Exception e) { throw new OssException("上传文件失败,请核对七牛配置信息:[" + e.getMessage() + "]"); @@ -85,7 +85,7 @@ public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy { path = path.replace(getEndpointLink() + "/", ""); Response res = bucketManager.delete(properties.getBucketName(), path); if (!res.isOK()) { - throw new RuntimeException("删除七牛文件出错:" + res.toString()); + throw new RuntimeException("删除七牛文件出错:" + res.error); } } catch (Exception e) { throw new OssException(e.getMessage()); From 4d5048435c5c48dad64cfbc086b1a59576bc6454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Mon, 8 Nov 2021 18:17:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20ruoyi=20?= =?UTF-8?q?=E5=85=B3=E4=BA=8E=20=E9=85=8D=E7=BD=AE=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=89=8D=E7=BC=80=E8=B7=AF=E5=BE=84=E7=9A=84bug=20=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/.env.development | 3 +++ ruoyi-ui/.env.production | 3 +++ ruoyi-ui/.env.staging | 3 +++ ruoyi-ui/src/layout/components/Navbar.vue | 2 +- ruoyi-ui/src/router/index.js | 1 - ruoyi-ui/src/utils/request.js | 2 +- ruoyi-ui/vue.config.js | 3 +-- 7 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ruoyi-ui/.env.development b/ruoyi-ui/.env.development index 3b003aa38..4addbcd8d 100644 --- a/ruoyi-ui/.env.development +++ b/ruoyi-ui/.env.development @@ -7,6 +7,9 @@ ENV = 'development' # 若依管理系统/开发环境 VUE_APP_BASE_API = '/dev-api' +# 应用访问路径 例如使用前缀 /admin/index +VUE_APP_CONTEXT_PATH = '/index' + # 监控地址 VUE_APP_MONITRO_ADMIN = 'http://localhost:9090/admin/login' diff --git a/ruoyi-ui/.env.production b/ruoyi-ui/.env.production index 2d0bb6184..45f4ad1ef 100644 --- a/ruoyi-ui/.env.production +++ b/ruoyi-ui/.env.production @@ -4,6 +4,9 @@ VUE_APP_TITLE = RuoYi-Vue-Plus后台管理系统 # 生产环境配置 ENV = 'production' +# 应用访问路径 例如使用前缀 /admin/index +VUE_APP_CONTEXT_PATH = '/index' + # 监控地址 VUE_APP_MONITRO_ADMIN = '/admin/login' diff --git a/ruoyi-ui/.env.staging b/ruoyi-ui/.env.staging index 49ce55c95..ed147ca48 100644 --- a/ruoyi-ui/.env.staging +++ b/ruoyi-ui/.env.staging @@ -6,6 +6,9 @@ NODE_ENV = production # 测试环境配置 ENV = 'staging' +# 应用访问路径 例如使用前缀 /admin/index +VUE_APP_CONTEXT_PATH = '/index' + # 监控地址 VUE_APP_MONITRO_ADMIN = '/admin/login' diff --git a/ruoyi-ui/src/layout/components/Navbar.vue b/ruoyi-ui/src/layout/components/Navbar.vue index e6721b70e..8f73e7cab 100644 --- a/ruoyi-ui/src/layout/components/Navbar.vue +++ b/ruoyi-ui/src/layout/components/Navbar.vue @@ -102,7 +102,7 @@ export default { type: 'warning' }).then(() => { this.$store.dispatch('LogOut').then(() => { - location.href = this.$router.options.base + '/index'; + location.href = process.env.VUE_APP_CONTEXT_PATH; }) }).catch(() => {}); } diff --git a/ruoyi-ui/src/router/index.js b/ruoyi-ui/src/router/index.js index cedf0b3aa..96f557b34 100644 --- a/ruoyi-ui/src/router/index.js +++ b/ruoyi-ui/src/router/index.js @@ -167,7 +167,6 @@ export const constantRoutes = [ ] export default new Router({ - base: "", // 项目前缀 与 publicPath 同步 例如 /api mode: 'history', // 去掉url中的# scrollBehavior: () => ({ y: 0 }), routes: constantRoutes diff --git a/ruoyi-ui/src/utils/request.js b/ruoyi-ui/src/utils/request.js index e8b3b5f16..5ce0d0063 100644 --- a/ruoyi-ui/src/utils/request.js +++ b/ruoyi-ui/src/utils/request.js @@ -65,7 +65,7 @@ service.interceptors.response.use(res => { } ).then(() => { store.dispatch('LogOut').then(() => { - location.href = this.$router.options.base + '/index'; + location.href = process.env.VUE_APP_CONTEXT_PATH; }) }).catch(() => {}); return Promise.reject('无效的会话,或者会话已过期,请重新登录。') diff --git a/ruoyi-ui/vue.config.js b/ruoyi-ui/vue.config.js index 4d6967bda..73c217777 100644 --- a/ruoyi-ui/vue.config.js +++ b/ruoyi-ui/vue.config.js @@ -16,8 +16,7 @@ module.exports = { // 部署生产环境和开发环境下的URL。 // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上 // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。 - // 设置基路径参考文档: http://doc.ruoyi.vip/ruoyi-vue/document/qdsc.html#应用路径 - publicPath: process.env.NODE_ENV === "production" ? "/" : "/", + publicPath: process.env.VUE_APP_CONTEXT_PATH, // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist) outputDir: 'dist', // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)