encryption works

This commit is contained in:
Chris Lu 2020-03-07 11:08:57 -08:00
parent 0375ce2c2e
commit 9228ff192c
3 changed files with 3 additions and 9 deletions

View file

@ -35,7 +35,7 @@ func main() {
targetUrl := fmt.Sprintf("http://%s/%s", assignResult.Url, assignResult.Fid)
_, err = operation.Upload(targetUrl, fmt.Sprintf("test%d", i), false, reader, false, "", nil, assignResult.Auth)
_, err = operation.Upload(targetUrl, fmt.Sprintf("test%d", i), false, reader, false, "bench/test", nil, assignResult.Auth)
if err != nil {
log.Fatalf("upload: %v", err)
}

View file

@ -62,7 +62,7 @@ func doUpload(uploadUrl string, filename string, cipher bool, reader io.Reader,
contentIsGzipped := isGzipped
shouldGzipNow := false
if !isGzipped {
if shouldBeZipped, iAmSure := util.IsGzippableFileType(filepath.Base(filename), mtype); iAmSure && shouldBeZipped {
if shouldBeZipped, iAmSure := util.IsGzippableFileType(filepath.Base(filename), mtype); mtype == "" || iAmSure && shouldBeZipped {
shouldGzipNow = true
contentIsGzipped = true
}

View file

@ -33,21 +33,15 @@ func (fs *FilerServer) encrypt(ctx context.Context, w http.ResponseWriter, r *ht
sizeLimit := int64(fs.option.MaxMB) * 1024 * 1024
pu, err := needle.ParseUpload(r, sizeLimit)
data := pu.Data
uncompressedData := pu.Data
cipherKey := util.GenCipherKey()
if pu.IsGzipped {
uncompressedData = pu.UncompressedData
data, err = util.Encrypt(pu.UncompressedData, cipherKey)
if err != nil {
return nil, fmt.Errorf("encrypt input: %v", err)
}
}
if pu.MimeType == "" {
pu.MimeType = http.DetectContentType(uncompressedData)
}
uploadResult, uploadError := operation.Upload(urlLocation, pu.FileName, true, bytes.NewReader(data), pu.IsGzipped, "", pu.PairMap, auth)
uploadResult, uploadError := operation.Upload(urlLocation, pu.FileName, true, bytes.NewReader(uncompressedData), false, pu.MimeType, pu.PairMap, auth)
if uploadError != nil {
return nil, fmt.Errorf("upload to volume server: %v", uploadError)
}