diff --git a/apps/backend/miogest_handler.go b/apps/backend/miogest_handler.go index 24a2d71..5ea97b2 100644 --- a/apps/backend/miogest_handler.go +++ b/apps/backend/miogest_handler.go @@ -90,15 +90,15 @@ func (m *MiogestHandler) GenerateCategorie() { } // ANNUNCI PARSED -func (m *MiogestHandler) GetAnnunciParsed(p *[]typesdefs.ImagesToProcess) typesdefs.AnnunciParsed { +func (m *MiogestHandler) GetAnnunciParsed(p *[]typesdefs.ImagesToProcess, forceImages bool) typesdefs.AnnunciParsed { // salvo il parsing nello struct nel caso voglio implementare un caching e non fare il parsing ad ogni chiamata - m.AnnunciParsed = m.ParseAnnunci("", p) + m.AnnunciParsed = m.ParseAnnunci("", p, forceImages) return m.AnnunciParsed } // versione per singolo annuncio func (m *MiogestHandler) GetAnnuncioParsed(codFilter string, p *[]typesdefs.ImagesToProcess) typesdefs.AnnunciParsed { - data := m.ParseAnnunci(codFilter, p) + data := m.ParseAnnunci(codFilter, p, false) if len(data.Annuncio) == 0 { return typesdefs.AnnunciParsed{} } @@ -106,7 +106,7 @@ func (m *MiogestHandler) GetAnnuncioParsed(codFilter string, p *[]typesdefs.Imag } -func (m *MiogestHandler) ParseAnnunci(codFilter string, p *[]typesdefs.ImagesToProcess) typesdefs.AnnunciParsed { +func (m *MiogestHandler) ParseAnnunci(codFilter string, p *[]typesdefs.ImagesToProcess, forceImages bool) typesdefs.AnnunciParsed { annunci := m.GetAnnunci() if len(annunci.Annuncio) == 0 { @@ -126,16 +126,26 @@ func (m *MiogestHandler) ParseAnnunci(codFilter string, p *[]typesdefs.ImagesToP image_codes_to_process := []string{} if config.Cfg.Images.Enabled { var err error - image_codes_to_process, err = CodiciToProcessImages(&annunci) - if err != nil { - log.Fatalf("Failed to find images to update: %v", err.Error()) + if forceImages { + // process all images + image_codes_to_process = make([]string, 0, len(annunci.Annuncio)) + for _, annuncio := range annunci.Annuncio { + if annuncio.Codice != nil { + image_codes_to_process = append(image_codes_to_process, *annuncio.Codice) + } + } + } else { + // process only new or updated images + image_codes_to_process, err = CodiciToProcessImages(&annunci) + if err != nil { + log.Fatalf("Failed to find images to update: %v", err.Error()) + } } if codFilter != "" { // if processing single codice, ensure it's in the list if !slices.Contains(image_codes_to_process, codFilter) { image_codes_to_process = append(image_codes_to_process, codFilter) } - } err = ForceClearImages(image_codes_to_process) if err != nil { diff --git a/apps/backend/server.go b/apps/backend/server.go index 4216c70..4d90c2e 100644 --- a/apps/backend/server.go +++ b/apps/backend/server.go @@ -104,14 +104,19 @@ func (s *Server) SetupRoutes() *echo.Echo { }) e.GET("/parse", func(c echo.Context) error { start := time.Now() - var data = s.miogest.GetAnnunciParsed(nil) + var data = s.miogest.GetAnnunciParsed(nil, false) end := time.Now() fmt.Println("time taken:", end.Sub(start).String()) return c.JSONPretty(http.StatusOK, data, " ") }) e.GET("/update", func(c echo.Context) error { + forceImages := false + forceImagesStr := c.QueryParam("forceimages") + if forceImagesStr == "true" { + forceImages = true + } imgPool := []typesdefs.ImagesToProcess{} - var data = s.miogest.GetAnnunciParsed(&imgPool) + var data = s.miogest.GetAnnunciParsed(&imgPool, forceImages) imgRefs, err := ProcessImagePool(&imgPool) if err != nil { return c.String(http.StatusInternalServerError, err.Error()) diff --git a/apps/db/migrations/4_seed_test.up.sql b/apps/db/migrations/4_seed_test.up.sql deleted file mode 100644 index 1c53753..0000000 --- a/apps/db/migrations/4_seed_test.up.sql +++ /dev/null @@ -1,24 +0,0 @@ -INSERT INTO - PUBLIC.USERS ( - username, - email, - "isAdmin", - PASSWORD, - nome, - cognome, - "isVerified", - salt, - telefono - ) -VALUES ( - 'Francesco Infoalloggi'::TEXT, - 'commerciale@infoalloggi.it'::TEXT, - TRUE::BOOLEAN, - 'changeme'::TEXT, - 'Francesco'::TEXT, - 'Infoalloggi'::TEXT, - TRUE::BOOLEAN, - 'a'::TEXT, - '+393407246729'::TEXT - ) -ON CONFLICT (email) DO NOTHING; \ No newline at end of file