Skip to content

Commit

Permalink
deny tus download when enable auth
Browse files Browse the repository at this point in the history
  • Loading branch information
sjqzhang committed Nov 28, 2019
1 parent 9c9fd74 commit 8de8a61
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2173,18 +2173,23 @@ func (this *Server) BuildFileResult(fileInfo *FileInfo, r *http.Request) FileRes
p string
downloadUrl string
domain string
host string
)
host = strings.Replace(Config().Host, "http://", "", -1)
if r != nil {
host = r.Host
}
if !strings.HasPrefix(Config().DownloadDomain, "http") {
if Config().DownloadDomain == "" {
Config().DownloadDomain = fmt.Sprintf("http://%s", r.Host)
Config().DownloadDomain = fmt.Sprintf("http://%s", host)
} else {
Config().DownloadDomain = fmt.Sprintf("http://%s", Config().DownloadDomain)
}
}
if Config().DownloadDomain != "" {
domain = Config().DownloadDomain
} else {
domain = fmt.Sprintf("http://%s", r.Host)
domain = fmt.Sprintf("http://%s", host)
}
outname = fileInfo.Name
if fileInfo.ReName != "" {
Expand All @@ -2196,7 +2201,7 @@ func (this *Server) BuildFileResult(fileInfo *FileInfo, r *http.Request) FileRes
} else {
p = p + "/" + outname
}
downloadUrl = fmt.Sprintf("http://%s/%s", r.Host, p)
downloadUrl = fmt.Sprintf("http://%s/%s", host, p)
if Config().DownloadDomain != "" {
downloadUrl = fmt.Sprintf("%s/%s", Config().DownloadDomain, p)
}
Expand Down Expand Up @@ -3858,6 +3863,11 @@ func (this *Server) initTus() {
log.Error(err)
return nil, err
} else {
if Config().AuthUrl != "" {
fileResult := this.util.JsonEncodePretty(this.BuildFileResult(fi, nil))
bufferReader := bytes.NewBuffer([]byte(fileResult))
return bufferReader, nil
}
fn = fi.Name
if fi.ReName != "" {
fn = fi.ReName
Expand Down

0 comments on commit 8de8a61

Please sign in to comment.