mirror of
https://github.com/chrislusf/seaweedfs
synced 2024-09-16 22:10:42 +02:00
a little refactoring
This commit is contained in:
parent
8a48baa056
commit
2d7dea1a09
|
@ -149,17 +149,9 @@ func doEachCopy(fileOrDir string, host string, path string) bool {
|
||||||
|
|
||||||
func uploadFileAsOne(filerUrl string, urlPath string, assignResult *operation.AssignResult, f *os.File, fi os.FileInfo) bool {
|
func uploadFileAsOne(filerUrl string, urlPath string, assignResult *operation.AssignResult, f *os.File, fi os.FileInfo) bool {
|
||||||
// upload the file content
|
// upload the file content
|
||||||
ext := strings.ToLower(path.Ext(f.Name()))
|
|
||||||
head := make([]byte, 512)
|
mimeType := detectMimeType(f)
|
||||||
f.Seek(0, 0)
|
isGzipped := isGzipped(f.Name())
|
||||||
n, err := f.Read(head)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("read head of %v: %v\n", f.Name(), err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
f.Seek(0, 0)
|
|
||||||
mimeType := http.DetectContentType(head[:n])
|
|
||||||
isGzipped := ext == ".gz"
|
|
||||||
|
|
||||||
targetUrl := "http://" + assignResult.Url + "/" + assignResult.Fid
|
targetUrl := "http://" + assignResult.Url + "/" + assignResult.Fid
|
||||||
|
|
||||||
|
@ -186,3 +178,20 @@ func uploadFileAsOne(filerUrl string, urlPath string, assignResult *operation.As
|
||||||
func uploadFileInChunks(filerUrl string, path string, assignResult *operation.AssignResult, f *os.File, chunkCount int) bool {
|
func uploadFileInChunks(filerUrl string, path string, assignResult *operation.AssignResult, f *os.File, chunkCount int) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isGzipped(filename string) bool {
|
||||||
|
return strings.ToLower(path.Ext(filename)) == ".gz"
|
||||||
|
}
|
||||||
|
|
||||||
|
func detectMimeType(f *os.File) string {
|
||||||
|
head := make([]byte, 512)
|
||||||
|
f.Seek(0, 0)
|
||||||
|
n, err := f.Read(head)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("read head of %v: %v\n", f.Name(), err)
|
||||||
|
return "application/octet-stream"
|
||||||
|
}
|
||||||
|
f.Seek(0, 0)
|
||||||
|
mimeType := http.DetectContentType(head[:n])
|
||||||
|
return mimeType
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue