Commit a4f21047 authored by Joerg-Holger Panzer's avatar Joerg-Holger Panzer
Browse files

Fix InfoJson creation for externalContent

create infoJson with defaults if images are not accessible
parent dea688de
......@@ -236,6 +236,7 @@ func CreateImageInfoInS3(bucket string, infojsonkey string, imagekey string, doc
b := bytes.Buffer{}
var result *s3.GetObjectOutput
var err error
mw := imagick.NewMagickWand()
attempts := 0
for {
......@@ -244,43 +245,51 @@ func CreateImageInfoInS3(bucket string, infojsonkey string, imagekey string, doc
result, err = s3Client.GetObject(&s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(imagekey),
//Key: aws.String(infoJsonJob.Key),
})
if err != nil {
if strings.Contains(err.Error(), "NoSuchKey") {
// go on: NoSuchKey
return nil, fmt.Errorf("NoSuchKey %s/%s", bucket, imagekey)
break
}
if attempts > 5 {
// any error, retry
time.Sleep(time.Duration(6*attempts) * time.Second)
return nil, fmt.Errorf("unable to load %s/%s, %s", bucket, imagekey, err)
}
continue
}
break
}
defer result.Body.Close()
if _, err := io.Copy(&b, result.Body); err != nil {
if err == nil {
defer result.Body.Close()
if _, err := io.Copy(&b, result.Body); err != nil {
return nil, fmt.Errorf("failed to copy response body for %s/%s, %s", bucket, imagekey, err.Error())
if _, err := io.Copy(&b, result.Body); err != nil {
return nil, fmt.Errorf("failed to copy response body for %s/%s, %s", bucket, imagekey, err.Error())
}
}
}
mw := imagick.NewMagickWand()
defer mw.Destroy()
err = mw.ReadImageBlob(b.Bytes())
if err != nil {
return nil, fmt.Errorf("Failed to create image object %s/%s, due to %s\n", bucket, imagekey, err.Error())
defer mw.Destroy()
err = mw.ReadImageBlob(b.Bytes())
if err != nil {
return nil, fmt.Errorf("Failed to create image object %s/%s, due to %s\n", bucket, imagekey, err.Error())
}
}
var x, y float64
depth := mw.GetImageDepth()
height := mw.GetImageHeight()
width := mw.GetImageWidth()
size, _ := mw.GetImageLength()
x, y, _ = mw.GetImageResolution()
depth := mw.GetImageDepth()
var height uint
var width uint
if size > 0 {
height = mw.GetImageHeight()
width = mw.GetImageWidth()
x, y, _ = mw.GetImageResolution()
} else {
height = 300
width = 300
}
imageInfo := templating.ImageInfo{
Depth: depth,
......
......@@ -124,6 +124,9 @@ func GetESPhysFromPhysStructMap(
} else if physMeta.UseToFileIDMap["DEFAULT"] != "" {
fileID := physMeta.UseToFileIDMap["DEFAULT"]
fileAttr = fileIDToAttrMap[fileID]
} else if physMeta.UseToFileIDMap["THUMBS"] != "" {
fileID := physMeta.UseToFileIDMap["THUMBS"]
fileAttr = fileIDToAttrMap[fileID]
}
if physMeta.UseToFileIDMap["FULLTEXT"] != "" && !isExternal {
......
......@@ -178,7 +178,7 @@ func getMapFromFileSec(fileSec types.Filesec, context string, isExternal bool) m
if (context == "gdz") || (context == "digizeit") {
if (strings.ToLower(fileGrp.Use) == "default") || (strings.ToLower(fileGrp.Use) == "presentation") || (strings.ToLower(fileGrp.Use) == "thumbs") {
reString = "^([\\W\\S]*)/(\\S*).(tif|TIF|gif|GIF|jpg|JPG)$"
reString = "^([\\W\\S]*)/(\\S*).(tif|TIF|gif|GIF|jpg|JPG|png|PNG)$"
re = regexp.MustCompile(reString)
} else if strings.ToLower(fileGrp.Use) == "gdzocr" {
reString = "^([\\W\\S]*)/(\\S*).(xml|txt|html)$"
......@@ -201,8 +201,7 @@ func getMapFromFileSec(fileSec types.Filesec, context string, isExternal bool) m
} else {
if (strings.ToLower(fileGrp.Use) == "default") || (strings.ToLower(fileGrp.Use) == "presentation") || (strings.ToLower(fileGrp.Use) == "thumbs") {
//reString = "^\\S*/(\\S*)$"
reString = "^\\S*/((\\S*).(tif|TIF|gif|GIF|jpg|JPG))$"
reString = "^\\S*/((\\S*).(tif|TIF|gif|GIF|jpg|JPG|png|PNG))$"
re = regexp.MustCompile(reString)
} else {
continue
......
Markdown is supported
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