feat: add storage token configuration and update storage request URLs
This commit is contained in:
parent
f006b4f658
commit
020b13db0b
5 changed files with 16 additions and 30 deletions
|
|
@ -28,6 +28,7 @@ type Config struct {
|
|||
}
|
||||
Storage struct {
|
||||
Endpoint string
|
||||
Token string
|
||||
}
|
||||
|
||||
Server struct {
|
||||
|
|
@ -68,6 +69,7 @@ func Load() *Config {
|
|||
|
||||
// Storage config
|
||||
Cfg.Storage.Endpoint = filepath.Join(pwd, "STORAGE_URL")
|
||||
Cfg.Storage.Token = filepath.Join(pwd, "STORAGE_TOKEN")
|
||||
|
||||
// Server config
|
||||
Cfg.Server.Port = getEnvAsInt("PORT", 1323)
|
||||
|
|
|
|||
|
|
@ -22,20 +22,6 @@ import (
|
|||
"github.com/nickalie/go-webpbin"
|
||||
)
|
||||
|
||||
type ImageProcessing struct {
|
||||
ImagesToProcess []typesdefs.ImagesToProcess
|
||||
ProcessedImages []typesdefs.ProcessedImage
|
||||
UploadedImages []typesdefs.UploadedImage
|
||||
}
|
||||
|
||||
func NewImageProcessing() *ImageProcessing {
|
||||
return &ImageProcessing{
|
||||
ImagesToProcess: []typesdefs.ImagesToProcess{},
|
||||
ProcessedImages: []typesdefs.ProcessedImage{},
|
||||
UploadedImages: []typesdefs.UploadedImage{},
|
||||
}
|
||||
}
|
||||
|
||||
func AddToImageProcessing(tmp *typesdefs.AnnuncioParsed, annuncio *typesdefs.AnnuncioXML, p *[]typesdefs.ImagesToProcess) {
|
||||
|
||||
if annuncio.Foto == nil || len(*annuncio.Foto) == 0 {
|
||||
|
|
@ -195,12 +181,12 @@ func Conversion(input string) (string, string, error) {
|
|||
|
||||
err = image_creation(img, width, output, outputdir)
|
||||
if err != nil {
|
||||
return empty, empty, err
|
||||
return empty, empty, fmt.Errorf("error in image creation: %w", err)
|
||||
}
|
||||
|
||||
err = thumbnail_creation(img, output, outputdir)
|
||||
if err != nil {
|
||||
return empty, empty, err
|
||||
return empty, empty, fmt.Errorf("error in thumbnail creation: %w", err)
|
||||
}
|
||||
|
||||
fmt.Println("Conversion completed successfully")
|
||||
|
|
|
|||
|
|
@ -135,11 +135,12 @@ func (m *MiogestHandler) ParseAnnunci(codFilter string, p *[]typesdefs.ImagesToP
|
|||
if !slices.Contains(image_codes_to_process, codFilter) {
|
||||
image_codes_to_process = append(image_codes_to_process, codFilter)
|
||||
}
|
||||
err := ForceClearImages([]string{codFilter})
|
||||
|
||||
}
|
||||
err = ForceClearImages(image_codes_to_process)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to clear images for codice %s: %v", codFilter, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"backend/config"
|
||||
"backend/queries"
|
||||
"backend/typesdefs"
|
||||
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
|
|
@ -29,12 +28,12 @@ func NewServer(cfg *config.Config) (*Server, error) {
|
|||
if miogest == nil {
|
||||
return nil, fmt.Errorf("error connecting to miogest")
|
||||
}
|
||||
|
||||
return &Server{
|
||||
miogest: miogest,
|
||||
config: cfg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) SetupRoutes() *echo.Echo {
|
||||
funcs := map[string]any{
|
||||
"contains": strings.Contains,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"backend/config"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
|
@ -13,11 +14,8 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var EXAMPLE_STORAGE_URL = "http://localhost:8080"
|
||||
var EXAMPLE_STORAGE_TOKEN = "test"
|
||||
|
||||
func DeleteFile(id string) error {
|
||||
req, err := http.NewRequest("DELETE", EXAMPLE_STORAGE_URL+"/delete/"+id+"?token="+EXAMPLE_STORAGE_TOKEN, nil)
|
||||
req, err := http.NewRequest("DELETE", config.Cfg.Storage.Endpoint+"/delete/"+id+"?token="+config.Cfg.Storage.Token, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create delete request: %w", err)
|
||||
}
|
||||
|
|
@ -49,7 +47,7 @@ type FileMetadata struct {
|
|||
|
||||
// func ListFiles() ([]FileMetadata, error) {
|
||||
// //get list of files from api
|
||||
// resp, err := http.Get(EXAMPLE_STORAGE_URL + "/files?token=" + EXAMPLE_STORAGE_TOKEN)
|
||||
// resp, err := http.Get(config.Cfg.Storage.Endpoint + "/files?token=" + config.Cfg.Storage.Token)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
|
@ -77,7 +75,7 @@ type FileMetadata struct {
|
|||
|
||||
func ListBucket(bucketName string) ([]FileMetadata, error) {
|
||||
//get list of files from api
|
||||
resp, err := http.Get(EXAMPLE_STORAGE_URL + "/bucket/" + bucketName + "?token=" + EXAMPLE_STORAGE_TOKEN)
|
||||
resp, err := http.Get(config.Cfg.Storage.Endpoint + "/bucket/" + bucketName + "?token=" + config.Cfg.Storage.Token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -112,7 +110,7 @@ func ListBucket(bucketName string) ([]FileMetadata, error) {
|
|||
// if err != nil {
|
||||
// return nil, nil, err
|
||||
// }
|
||||
// resp, err := http.Post(EXAMPLE_STORAGE_URL+"/files-check?token="+EXAMPLE_STORAGE_TOKEN,
|
||||
// resp, err := http.Post(config.Cfg.Storage.Endpoint+"/files-check?token="+config.Cfg.Storage.Token,
|
||||
// "application/json", bytes.NewBuffer(jsonData))
|
||||
// if err != nil {
|
||||
// return nil, nil, err
|
||||
|
|
@ -171,7 +169,7 @@ func UploadFile(path string) (string, error) {
|
|||
return "", fmt.Errorf("failed to close writer: %w", err)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", EXAMPLE_STORAGE_URL+"/upload?token="+EXAMPLE_STORAGE_TOKEN, &body)
|
||||
req, err := http.NewRequest("POST", config.Cfg.Storage.Endpoint+"/upload?token="+config.Cfg.Storage.Token, &body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create upload request: %w", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue