Skip to content

Commit 63a26dc

Browse files
authored
Merge pull request flipped-aurora#1104 from aaronwmy/main
将上传目录访问路径和存储路径分开成两个配置
2 parents 4344504 + 4a6aeab commit 63a26dc

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

server/config.docker.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ db-list:
104104

105105
# local configuration
106106
local:
107-
path: 'uploads/file'
107+
path: 'uploads/file' # 访问路径
108+
store-path: 'uploads/file' # 存储路径
108109

109110
# autocode configuration
110111
autocode:

server/config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ db-list:
104104

105105
# local configuration
106106
local:
107-
path: 'uploads/file'
107+
path: 'uploads/file' # 访问路径
108+
store-path: 'uploads/file' # 存储路径
108109

109110
# autocode configuration
110111
autocode:

server/config/oss_local.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package config
22

33
type Local struct {
4-
Path string `mapstructure:"path" json:"path" yaml:"path"` // 本地文件路径
4+
Path string `mapstructure:"path" json:"path" yaml:"path"` // 本地文件访问路径
5+
StorePath string `mapstructure:"store-path" json:"store-path" yaml:"store-path"` // 本地文件存储路径
56
}

server/initialize/router.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func Routers() *gin.Engine {
2727
// Router.Static("/static", "./dist/assets") // dist里面的静态资源
2828
// Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面
2929

30-
Router.StaticFS(global.GVA_CONFIG.Local.Path, http.Dir(global.GVA_CONFIG.Local.Path)) // 为用户头像和文件提供静态地址
30+
Router.StaticFS(global.GVA_CONFIG.Local.Path, http.Dir(global.GVA_CONFIG.Local.StorePath)) // 为用户头像和文件提供静态地址
3131
// Router.Use(middleware.LoadTls()) // 如果需要使用https 请打开此中间件 然后前往 core/server.go 将启动模式 更变为 Router.RunTLS("端口","你的cre/pem文件","你的key文件")
3232
global.GVA_LOG.Info("use middleware logger")
3333
// 跨域,如需跨域可以打开下面的注释
@@ -71,7 +71,7 @@ func Routers() *gin.Engine {
7171
exampleRouter.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由
7272

7373
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
74-
74+
7575
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
7676
}
7777

server/utils/upload/local.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ func (*Local) UploadFile(file *multipart.FileHeader) (string, string, error) {
3434
// 拼接新文件名
3535
filename := name + "_" + time.Now().Format("20060102150405") + ext
3636
// 尝试创建此路径
37-
mkdirErr := os.MkdirAll(global.GVA_CONFIG.Local.Path, os.ModePerm)
37+
mkdirErr := os.MkdirAll(global.GVA_CONFIG.Local.StorePath, os.ModePerm)
3838
if mkdirErr != nil {
3939
global.GVA_LOG.Error("function os.MkdirAll() Filed", zap.Any("err", mkdirErr.Error()))
4040
return "", "", errors.New("function os.MkdirAll() Filed, err:" + mkdirErr.Error())
4141
}
4242
// 拼接路径和文件名
43-
p := global.GVA_CONFIG.Local.Path + "/" + filename
43+
p := global.GVA_CONFIG.Local.StorePath + "/" + filename
44+
filepath := global.GVA_CONFIG.Local.Path + "/" + filename
4445

4546
f, openError := file.Open() // 读取文件
4647
if openError != nil {
@@ -62,7 +63,7 @@ func (*Local) UploadFile(file *multipart.FileHeader) (string, string, error) {
6263
global.GVA_LOG.Error("function io.Copy() Filed", zap.Any("err", copyErr.Error()))
6364
return "", "", errors.New("function io.Copy() Filed, err:" + copyErr.Error())
6465
}
65-
return p, filename, nil
66+
return filepath, filename, nil
6667
}
6768

6869
//@author: [piexlmax](https://github.com/piexlmax)
@@ -75,8 +76,8 @@ func (*Local) UploadFile(file *multipart.FileHeader) (string, string, error) {
7576
//@return: error
7677

7778
func (*Local) DeleteFile(key string) error {
78-
p := global.GVA_CONFIG.Local.Path + "/" + key
79-
if strings.Contains(p, global.GVA_CONFIG.Local.Path) {
79+
p := global.GVA_CONFIG.Local.StorePath + "/" + key
80+
if strings.Contains(p, global.GVA_CONFIG.Local.StorePath) {
8081
if err := os.Remove(p); err != nil {
8182
return errors.New("本地文件删除失败, err:" + err.Error())
8283
}

web/src/view/systemTools/system/system.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,12 @@
189189
<el-collapse-item title="oss配置" name="10">
190190
<template v-if="config.system['oss-type'] === 'local'">
191191
<h2>本地文件配置</h2>
192-
<el-form-item label="本地文件路径">
192+
<el-form-item label="本地文件访问路径">
193193
<el-input v-model="config.local.path" />
194194
</el-form-item>
195+
<el-form-item label="本地文件存储路径">
196+
<el-input v-model="config.local['store-path']" />
197+
</el-form-item>
195198
</template>
196199
<template v-if="config.system['oss-type'] === 'qiniu'">
197200
<h2>qiniu上传配置</h2>

0 commit comments

Comments
 (0)