add enable_trim_file_name_special_char option

This commit is contained in:
sjqzhang 2024-09-27 10:43:15 +08:00
parent fd58b3d1c7
commit 749a6f14b0
2 changed files with 61 additions and 55 deletions

View File

@ -108,6 +108,8 @@ const (
"extensions": [],
"重试同步失败文件的时间": "单位秒",
"refresh_interval": 1800,
"是否去掉文件名特殊字符":"true:去掉,false不去掉",
"enable_trim_file_name_special_char":true,
"是否自动重命名": "默认不自动重命名,使用原文件名",
"rename_file": false,
"是否支持web上传,方便调试": "默认支持web上传",
@ -174,60 +176,61 @@ const (
)
type GlobalConfig struct {
Addr string `json:"addr"`
Peers []string `json:"peers"`
EnableHttps bool `json:"enable_https"`
Group string `json:"group"`
RenameFile bool `json:"rename_file"`
ShowDir bool `json:"show_dir"`
Extensions []string `json:"extensions"`
RefreshInterval int `json:"refresh_interval"`
EnableWebUpload bool `json:"enable_web_upload"`
DownloadDomain string `json:"download_domain"`
EnableCustomPath bool `json:"enable_custom_path"`
Scenes []string `json:"scenes"`
AlarmReceivers []string `json:"alarm_receivers"`
DefaultScene string `json:"default_scene"`
Mail Mail `json:"mail"`
AlarmUrl string `json:"alarm_url"`
DownloadUseToken bool `json:"download_use_token"`
DownloadTokenExpire int `json:"download_token_expire"`
QueueSize int `json:"queue_size"`
AutoRepair bool `json:"auto_repair"`
Host string `json:"host"`
FileSumArithmetic string `json:"file_sum_arithmetic"`
PeerId string `json:"peer_id"`
SupportGroupManage bool `json:"support_group_manage"`
AdminIps []string `json:"admin_ips"`
AdminKey string `json:"admin_key"`
EnableMergeSmallFile bool `json:"enable_merge_small_file"`
EnableMigrate bool `json:"enable_migrate"`
EnableDistinctFile bool `json:"enable_distinct_file"`
ReadOnly bool `json:"read_only"`
EnableCrossOrigin bool `json:"enable_cross_origin"`
EnableGoogleAuth bool `json:"enable_google_auth"`
AuthUrl string `json:"auth_url"`
EnableDownloadAuth bool `json:"enable_download_auth"`
DefaultDownload bool `json:"default_download"`
EnableTus bool `json:"enable_tus"`
SyncTimeout int64 `json:"sync_timeout"`
EnableFsNotify bool `json:"enable_fsnotify"`
EnableDiskCache bool `json:"enable_disk_cache"`
ConnectTimeout bool `json:"connect_timeout"`
ReadTimeout int `json:"read_timeout"`
WriteTimeout int `json:"write_timeout"`
IdleTimeout int `json:"idle_timeout"`
ReadHeaderTimeout int `json:"read_header_timeout"`
SyncWorker int `json:"sync_worker"`
UploadWorker int `json:"upload_worker"`
UploadQueueSize int `json:"upload_queue_size"`
RetryCount int `json:"retry_count"`
SyncDelay int64 `json:"sync_delay"`
WatchChanSize int `json:"watch_chan_size"`
ImageMaxWidth int `json:"image_max_width"`
ImageMaxHeight int `json:"image_max_height"`
Proxies []Proxy `json:"proxies"`
EnablePprofDebug bool `json:"enable_pprof_debug"`
Addr string `json:"addr"`
Peers []string `json:"peers"`
EnableHttps bool `json:"enable_https"`
Group string `json:"group"`
RenameFile bool `json:"rename_file"`
ShowDir bool `json:"show_dir"`
Extensions []string `json:"extensions"`
RefreshInterval int `json:"refresh_interval"`
EnableWebUpload bool `json:"enable_web_upload"`
DownloadDomain string `json:"download_domain"`
EnableCustomPath bool `json:"enable_custom_path"`
Scenes []string `json:"scenes"`
AlarmReceivers []string `json:"alarm_receivers"`
DefaultScene string `json:"default_scene"`
Mail Mail `json:"mail"`
AlarmUrl string `json:"alarm_url"`
DownloadUseToken bool `json:"download_use_token"`
DownloadTokenExpire int `json:"download_token_expire"`
QueueSize int `json:"queue_size"`
AutoRepair bool `json:"auto_repair"`
Host string `json:"host"`
FileSumArithmetic string `json:"file_sum_arithmetic"`
PeerId string `json:"peer_id"`
SupportGroupManage bool `json:"support_group_manage"`
AdminIps []string `json:"admin_ips"`
AdminKey string `json:"admin_key"`
EnableMergeSmallFile bool `json:"enable_merge_small_file"`
EnableMigrate bool `json:"enable_migrate"`
EnableDistinctFile bool `json:"enable_distinct_file"`
ReadOnly bool `json:"read_only"`
EnableCrossOrigin bool `json:"enable_cross_origin"`
EnableGoogleAuth bool `json:"enable_google_auth"`
AuthUrl string `json:"auth_url"`
EnableDownloadAuth bool `json:"enable_download_auth"`
DefaultDownload bool `json:"default_download"`
EnableTus bool `json:"enable_tus"`
SyncTimeout int64 `json:"sync_timeout"`
EnableFsNotify bool `json:"enable_fsnotify"`
EnableDiskCache bool `json:"enable_disk_cache"`
ConnectTimeout bool `json:"connect_timeout"`
ReadTimeout int `json:"read_timeout"`
WriteTimeout int `json:"write_timeout"`
IdleTimeout int `json:"idle_timeout"`
ReadHeaderTimeout int `json:"read_header_timeout"`
SyncWorker int `json:"sync_worker"`
UploadWorker int `json:"upload_worker"`
UploadQueueSize int `json:"upload_queue_size"`
RetryCount int `json:"retry_count"`
SyncDelay int64 `json:"sync_delay"`
WatchChanSize int `json:"watch_chan_size"`
ImageMaxWidth int `json:"image_max_width"`
ImageMaxHeight int `json:"image_max_height"`
Proxies []Proxy `json:"proxies"`
EnablePprofDebug bool `json:"enable_pprof_debug"`
EnableTrimFileNameSpecialChar bool `json:"enable_trim_file_name_special_char"`
}
type Proxy struct {

View File

@ -408,7 +408,10 @@ func (c *Server) SaveUploadFile(file multipart.File, header *multipart.FileHeade
defer file.Close()
_, fileInfo.Name = filepath.Split(header.Filename)
// trim special char in filename for example: #@%$^&*()_+{}|:"<>?[];',./
fileInfo.Name = c.TrimFileNameSpecialChar(fileInfo.Name)
if Config().EnableTrimFileNameSpecialChar {
fileInfo.Name = c.TrimFileNameSpecialChar(fileInfo.Name)
}
// bugfix for ie upload file contain fullpath
if len(Config().Extensions) > 0 && !c.util.Contains(path.Ext(strings.ToLower(fileInfo.Name)), Config().Extensions) {
return fileInfo, errors.New("(error)file extension mismatch")