Skip to content

Commit 177b3b0

Browse files
committed
image resize support max size
1 parent f199722 commit 177b3b0

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

fileserver.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ const (
143143
"是否合并小文件": "默认不合并,合并可以解决inode不够用的情况(当前对于小于1M文件)进行合并",
144144
"enable_merge_small_file": false,
145145
"允许后缀名": "允许可以上传的文件后缀名,如jpg,jpeg,png等。留空允许所有。",
146+
"图片是否缩放": "默认是",
147+
"enable_image_resize": true,
148+
"图片最大宽度": "默认值2000",
149+
"image_max_width": 2000,
150+
"图片最大高度": "默认值1000",
151+
"image_max_height": 1000,
146152
"extensions": [],
147153
"重试同步失败文件的时间": "单位秒",
148154
"refresh_interval": 1800,
@@ -152,7 +158,7 @@ const (
152158
"enable_web_upload": true,
153159
"是否支持非日期路径": "默认支持非日期路径,也即支持自定义路径,需要上传文件时指定path",
154160
"enable_custom_path": true,
155-
"下载域名": "用于外网下载文件的域名,不包含http://",
161+
"下载域名": "用于外网下载文件的域名",
156162
"download_domain": "",
157163
"场景列表": "当设定后,用户指的场景必项在列表中,默认不做限制(注意:如果想开启场景认功能,格式如下:'场景名:googleauth_secret' 如 default:N7IET373HB2C5M6D ",
158164
"scenes": [],
@@ -178,7 +184,7 @@ const (
178184
"auto_repair": true,
179185
"文件去重算法md5可能存在冲突,默认md5": "sha1|md5",
180186
"file_sum_arithmetic": "md5",
181-
"管理ip列表": "用于管理集的ip白名单,",
187+
"管理ip列表": "用于管理集的ip白名单,如果放开所有内网则可以用 0.0.0.0 ,注意为了安全,不对外网开放",
182188
"admin_ips": ["127.0.0.1"],
183189
"是否启用迁移": "默认不启用",
184190
"enable_migrate": false,
@@ -322,6 +328,8 @@ type GloablConfig struct {
322328
RetryCount int `json:"retry_count"`
323329
SyncDelay int64 `json:"sync_delay"`
324330
WatchChanSize int `json:"watch_chan_size"`
331+
ImageMaxWidth int `json:"image_max_width"`
332+
ImageMaxHeight int `json:"image_max_height"`
325333
}
326334
type FileInfoResult struct {
327335
Name string `json:"name"`
@@ -1175,12 +1183,18 @@ func (this *Server) DownloadSmallFileByURI(w http.ResponseWriter, r *http.Reques
11751183
if err != nil {
11761184
log.Error(err)
11771185
}
1186+
if imgWidth > Config().ImageMaxWidth {
1187+
imgWidth = Config().ImageMaxWidth
1188+
}
11781189
}
11791190
if height != "" {
11801191
imgHeight, err = strconv.Atoi(height)
11811192
if err != nil {
11821193
log.Error(err)
11831194
}
1195+
if imgHeight > Config().ImageMaxHeight {
1196+
imgHeight = Config().ImageMaxHeight
1197+
}
11841198
}
11851199
data, notFound, err = this.GetSmallFileByURI(w, r)
11861200
_ = notFound
@@ -1221,12 +1235,18 @@ func (this *Server) DownloadNormalFileByURI(w http.ResponseWriter, r *http.Reque
12211235
if err != nil {
12221236
log.Error(err)
12231237
}
1238+
if imgWidth > Config().ImageMaxWidth {
1239+
imgWidth = Config().ImageMaxWidth
1240+
}
12241241
}
12251242
if height != "" {
12261243
imgHeight, err = strconv.Atoi(height)
12271244
if err != nil {
12281245
log.Error(err)
12291246
}
1247+
if imgHeight > Config().ImageMaxHeight {
1248+
imgHeight = Config().ImageMaxHeight
1249+
}
12301250
}
12311251
if isDownload {
12321252
this.SetDownloadHeader(w, r)
@@ -1358,6 +1378,7 @@ func (this *Server) ResizeImageByBytes(w http.ResponseWriter, data []byte, width
13581378
log.Error(err)
13591379
return
13601380
}
1381+
fmt.Println(width, height)
13611382
img = resize.Resize(width, height, img, resize.Lanczos3)
13621383
if imgType == "jpg" || imgType == "jpeg" {
13631384
jpeg.Encode(w, img, nil)
@@ -4317,6 +4338,12 @@ func (this *Server) initComponent(isReload bool) {
43174338
if Config().WatchChanSize == 0 {
43184339
Config().WatchChanSize = 100000
43194340
}
4341+
if Config().ImageMaxHeight == 0 {
4342+
Config().ImageMaxHeight = 2000
4343+
}
4344+
if Config().ImageMaxWidth == 0 {
4345+
Config().ImageMaxWidth = 2000
4346+
}
43204347
}
43214348

43224349
type HttpHandler struct {

0 commit comments

Comments
 (0)