|
|
@ -17,9 +17,9 @@ const ( |
|
|
|
) |
|
|
|
|
|
|
|
type Needle struct { |
|
|
|
Cookie uint32 "random number to mitigate brute force lookups" |
|
|
|
Id uint64 "needle id" |
|
|
|
Size uint32 "sum of DataSize,Data,NameSize,Name,MimeSize,Mime" |
|
|
|
Cookie uint32 "random number to mitigate brute force lookups" |
|
|
|
Id uint64 "needle id" |
|
|
|
Size uint32 "sum of DataSize,Data,NameSize,Name,MimeSize,Mime" |
|
|
|
|
|
|
|
DataSize uint32 "Data size" //version2
|
|
|
|
Data []byte "The actual file data" |
|
|
@ -50,15 +50,32 @@ func NewNeedle(r *http.Request) (n *Needle, fname string, e error) { |
|
|
|
} |
|
|
|
fname = part.FileName() |
|
|
|
data, _ := ioutil.ReadAll(part) |
|
|
|
//log.Println("uploading file " + part.FileName())
|
|
|
|
dotIndex := strings.LastIndex(fname, ".") |
|
|
|
ext, mtype := "", "" |
|
|
|
if dotIndex > 0 { |
|
|
|
ext := fname[dotIndex:] |
|
|
|
mtype := mime.TypeByExtension(ext) |
|
|
|
if IsGzippable(ext, mtype) { |
|
|
|
data = GzipData(data) |
|
|
|
ext = fname[dotIndex:] |
|
|
|
mtype = mime.TypeByExtension(ext) |
|
|
|
} |
|
|
|
contentType := part.Header.Get("Content-Type") |
|
|
|
if contentType != "" && mtype != contentType && len(contentType) < 256 { |
|
|
|
n.Mime = []byte(contentType) |
|
|
|
mtype = contentType |
|
|
|
} |
|
|
|
if IsGzippable(ext, mtype) { |
|
|
|
data = GzipData(data) |
|
|
|
n.SetGzipped() |
|
|
|
} |
|
|
|
if ext == ".gz" { |
|
|
|
n.SetGzipped() |
|
|
|
} |
|
|
|
if len(fname) < 256 { |
|
|
|
if strings.HasSuffix(fname, ".gz") { |
|
|
|
n.Name = []byte(fname[:len(fname)-3]) |
|
|
|
} else { |
|
|
|
n.Name = []byte(fname) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
n.Data = data |
|
|
|
n.Checksum = NewCRC(data) |
|
|
|
|
|
|
|