Merge remote-tracking branch 'origin/bzz' into bzz

Conflicts:
	bzz/api.go
This commit is contained in:
zelig 2015-06-05 06:35:17 +01:00
commit 6b9ea28eea

View file

@ -2,12 +2,12 @@ package bzz
import ( import (
"bufio" "bufio"
"bytes"
"fmt" "fmt"
"io" "io"
"math/big" "math/big"
// "net"
// "net/http"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
@ -320,16 +320,19 @@ func (self *Api) Upload(lpath, index string) (string, error) {
list[i].Hash = fmt.Sprintf("%064x", hash) list[i].Hash = fmt.Sprintf("%064x", hash)
} }
wg.Wait() wg.Wait()
}
if err == nil {
cmd := exec.Command("file", "--mime-type", "-b", entry.Path)
// cmd := exec.Command("mimetype", "-b", entry.Path)
var out bytes.Buffer
cmd.Stdout = &out
err = cmd.Run()
if err == nil { if err == nil {
list[i].ContentType = strings.TrimSuffix(out.String(), "\n") first512 := make([]byte, 512)
fread, _ := sr.ReadAt(first512, 0)
if fread > 0 {
mimeType := http.DetectContentType(first512[:fread])
if filepath.Ext(entry.Path) == ".css" {
mimeType = "text/css"
}
list[i].ContentType = mimeType
//fmt.Printf("%v %v %v\n", entry.Path, mimeType, filepath.Ext(entry.Path))
}
} }
f.Close()
} }
errors[i] = err errors[i] = err
done <- true done <- true