Skip to content

Commit

Permalink
Define process images function
Browse files Browse the repository at this point in the history
  • Loading branch information
petyos committed May 2, 2024
1 parent 7a69889 commit 65518f0
Showing 1 changed file with 50 additions and 38 deletions.
88 changes: 50 additions & 38 deletions core/logic_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,48 +256,13 @@ func (e eventsLogic) processWebToolsEvents() {

e.logger.Infof("we loaded %d web tools events", webToolsCount)

var withimage []model.WebToolsEvent
for _, l := range allWebToolsEvents {
if l.LargeImageUploaded != "" {
withimage = append(withimage, l)
}
allWebToolsEvents = withimage
}

contentImagesFromTheDataBase, err := e.app.storage.FindImageItems()
//process the images before the main processing
err = e.processImages(allWebToolsEvents)
if err != nil {
e.logger.Error("Error on finding image items")
e.logger.Errorf("error on processing images - %s", err)
return
}

images, err := e.app.imageAdapter.ProcessImages(allWebToolsEvents)
if err != nil {
e.logger.Error("Error on finding image items")
return
}
for _, t := range contentImagesFromTheDataBase {
for _, l := range images {
if t.ID != l.ID && t.ImageURL != l.ImageURL {
err = e.app.storage.InsertImageItems(l)

}
}
}

// Create a map to store ImageURLs with corresponding IDs
imageURLMap := make(map[string]string)
for _, ciu := range images {
imageURLMap[ciu.ID] = ciu.ImageURL
}

for i := range allWebToolsEvents {
if allWebToolsEvents[i].LargeImageUploaded == "false" {
allWebToolsEvents[i].ImageURL = ""
} else if imageURL, ok := imageURLMap[allWebToolsEvents[i].EventID]; ok {
allWebToolsEvents[i].ImageURL = imageURL
}
}

now := time.Now()

//in transaction
Expand Down Expand Up @@ -360,6 +325,53 @@ func (e eventsLogic) processWebToolsEvents() {
}
}

func (e eventsLogic) processImages(allWebtoolsEvents []model.WebToolsEvent) error {
var withimage []model.WebToolsEvent
for _, l := range allWebtoolsEvents {
if l.LargeImageUploaded != "" {
withimage = append(withimage, l)
}
allWebtoolsEvents = withimage
}

contentImagesFromTheDataBase, err := e.app.storage.FindImageItems()
if err != nil {
e.logger.Error("Error on finding image items")
return err
}

images, err := e.app.imageAdapter.ProcessImages(allWebtoolsEvents)
if err != nil {
e.logger.Error("Error on finding image items")
return err
}
for _, t := range contentImagesFromTheDataBase {
for _, l := range images {
if t.ID != l.ID && t.ImageURL != l.ImageURL {
err = e.app.storage.InsertImageItems(l)

}
}
}

// Create a map to store ImageURLs with corresponding IDs
imageURLMap := make(map[string]string)
for _, ciu := range images {
imageURLMap[ciu.ID] = ciu.ImageURL
}

for i := range allWebtoolsEvents {
if allWebtoolsEvents[i].LargeImageUploaded == "false" {
allWebtoolsEvents[i].ImageURL = ""
} else if imageURL, ok := imageURLMap[allWebtoolsEvents[i].EventID]; ok {
allWebtoolsEvents[i].ImageURL = imageURL
}
}

//TODO
return nil
}

// ignore or modify webtools events
func (e eventsLogic) modifyWebtoolsEventsList(allWebtoolsEvents []model.WebToolsEvent) ([]model.WebToolsEvent, error) {
modifiedList := []model.WebToolsEvent{}
Expand Down

0 comments on commit 65518f0

Please sign in to comment.