Commit b8e2087a authored by Ajit Jagtap's avatar Ajit Jagtap
Browse files

Merge branch 'kunal_DownloadManager' into 'devbranch'

downloadhelpermdl: Export struct and check for "Last-Modified" header

See merge request !100
parents c97054fb e92c27e6
Branches
Tags
2 merge requests!10220Aug Merge Dev to Stg,!100downloadhelpermdl: Export struct and check for "Last-Modified" header
Showing with 18 additions and 14 deletions
......@@ -44,7 +44,7 @@ type DownloadHelper struct {
sourceURL string
destinationPath string
retryCount int
downloadParam DownloadParameter
DownloadParam DownloadParameter
}
// Structure DownloadParameter: with different parameters which can be received for downloading the file
......@@ -66,25 +66,25 @@ func GetDownloadHelper(sourceURL, destinationPath string, retryCount int) *Downl
// AddParamsJWT - method to add jwtToken at runtime
func (dh *DownloadHelper) AddParamsJWT(jwtToken string) *DownloadHelper {
dh.downloadParam.jwtToken = jwtToken
dh.DownloadParam.jwtToken = jwtToken
return dh
}
// AddParamsFileHashed - method to add fileHashedValue at runtime
func (dh *DownloadHelper) AddParamsFileHashed(fileHashedValue string) *DownloadHelper {
dh.downloadParam.fileHashedValue = fileHashedValue
dh.DownloadParam.fileHashedValue = fileHashedValue
return dh
}
// AddParamsFileHashed - method to add fileHashedValue at runtime
func (dh *DownloadHelper) AddParamsCacheBurst(isCacheBurst bool) *DownloadHelper {
dh.downloadParam.isCacheBurst = isCacheBurst
dh.DownloadParam.isCacheBurst = isCacheBurst
return dh
}
// Run all Steps one by one
func (dh *DownloadHelper) Run() *DownloadHelper {
_, dh.downloadParam.DownloadError = DownloadFile(dh)
_, dh.DownloadParam.DownloadError = DownloadFile(dh)
return dh
}
......@@ -109,7 +109,7 @@ func DownloadFile(params *DownloadHelper) (bool, error) {
}
// Cache Burst Implementation
if params.downloadParam.isCacheBurst {
if params.DownloadParam.isCacheBurst {
mkclCacheBurst := strconv.FormatInt(time.Now().UnixNano(), 10)
if strings.Contains(params.sourceURL, "?") {
params.sourceURL = params.sourceURL + "&mkclCacheBurst=" + mkclCacheBurst
......@@ -166,7 +166,7 @@ func downloadFileFromCloud(params *DownloadHelper) error {
// Check hash check enabled or not
destinationPath := ""
if strings.Trim(params.downloadParam.fileHashedValue, EMPTY_STR) != EMPTY_STR {
if strings.Trim(params.DownloadParam.fileHashedValue, EMPTY_STR) != EMPTY_STR {
// With hash check implementation
destinationPath = os.TempDir() + string(os.PathSeparator) + filepath.Base(params.destinationPath)
} else {
......@@ -192,8 +192,8 @@ func downloadFileFromCloud(params *DownloadHelper) error {
}
// Set JWT in request header in case required
if strings.Trim(params.downloadParam.jwtToken, EMPTY_STR) != EMPTY_STR {
req.Header.Add("Authorization", params.downloadParam.jwtToken)
if strings.Trim(params.DownloadParam.jwtToken, EMPTY_STR) != EMPTY_STR {
req.Header.Add("Authorization", params.DownloadParam.jwtToken)
}
// Call http client
......@@ -220,9 +220,13 @@ func downloadFileFromCloud(params *DownloadHelper) error {
// File downloaded successfully
loggermdl.LogDebug("DownloadFile : Download Successful")
timeHeader := resp.Header.Get("Last-Modified")
err = updateModifiedDateAndValidate(timeHeader, destinationPath, params)
if err != nil {
return err
//Last-Modified is not available in case of GRIDFS CDN
if strings.Trim(timeHeader, EMPTY_STR) != EMPTY_STR {
err = updateModifiedDateAndValidate(timeHeader, destinationPath, params)
if err != nil {
return err
}
}
// All operations done successfully
......@@ -270,7 +274,7 @@ func validateDownloadedFile(tempDestinationPath string, params *DownloadHelper)
}
// Check if hash checking requied and then calculate and compare hash of downloaded file
if strings.Trim(params.downloadParam.fileHashedValue, EMPTY_STR) != EMPTY_STR {
if strings.Trim(params.DownloadParam.fileHashedValue, EMPTY_STR) != EMPTY_STR {
// Calculate hash value of downloaded file
hashValue, err := hashmdl.GetAtributeBasedHash(tempDestinationPath)
if errormdl.CheckErr1(err) != nil {
......@@ -279,7 +283,7 @@ func validateDownloadedFile(tempDestinationPath string, params *DownloadHelper)
}
// Compare hash value with provided value
if errormdl.CheckBool1(hashValue == params.downloadParam.fileHashedValue) {
if errormdl.CheckBool1(hashValue == params.DownloadParam.fileHashedValue) {
// Move file from Temp to actual destination
err := filemdl.MoveFile(tempDestinationPath, params.destinationPath)
if errormdl.CheckErr2(err) != nil {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment