added s3prefix for file if this url and do not have hhtps prefix

This commit is contained in:
Pavel 2024-07-18 22:41:49 +03:00
parent 7897dc2cb1
commit cf974729bd
4 changed files with 10 additions and 2 deletions

@ -69,6 +69,7 @@ type Options struct {
TrashLogHost string `env:"TRASH_LOG_HOST" default:"localhost:7113"`
ModuleLogger string `env:"MODULE_LOGGER" default:"core-local"`
ClickHouseCred string `env:"CLICK_HOUSE_CRED" default:"tcp://10.8.0.15:9000/default?sslmode=disable"`
S3Prefix string `env:"S3_PREFIX"`
}
func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.CommonApp, error) {
@ -178,6 +179,7 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
Producer: producer,
ServiceName: options.ServiceName,
ChDAL: chDal,
S3Prefix: options.S3Prefix,
})
svc.Register(app)

@ -177,7 +177,7 @@ func (s *Service) ExportResultsToCSV(ctx *fiber.Ctx) error {
buffer := new(bytes.Buffer)
if err := tools.WriteDataToExcel(buffer, questions, answers); err != nil {
if err := tools.WriteDataToExcel(buffer, questions, answers, s.s3Prefix); err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString("failed to write data to Excel")
}

@ -14,6 +14,7 @@ type Service struct {
producer *brokers.Producer
serviceName string
chDAL *dal.ClickHouseDAL
s3Prefix string
}
type Deps struct {
@ -22,6 +23,7 @@ type Deps struct {
Producer *brokers.Producer
ServiceName string
ChDAL *dal.ClickHouseDAL
S3Prefix string
}
func New(deps Deps) *Service {
@ -31,6 +33,7 @@ func New(deps Deps) *Service {
producer: deps.Producer,
serviceName: deps.ServiceName,
chDAL: deps.ChDAL,
s3Prefix: deps.S3Prefix,
}
}

@ -28,7 +28,7 @@ const (
bucketAnswers = "squizanswer"
)
func WriteDataToExcel(buffer io.Writer, questions []model.Question, answers []model.Answer) error {
func WriteDataToExcel(buffer io.Writer, questions []model.Question, answers []model.Answer, s3Prefix string) error {
file := excelize.NewFile()
sheet := "Sheet1"
@ -130,6 +130,9 @@ func WriteDataToExcel(buffer io.Writer, questions []model.Question, answers []mo
}
} else if tipe != "Text" && q.Type == model.TypeFile {
urle := ExtractImageURL(response[index].Content)
if urle != "" && !strings.HasPrefix(urle, "https") {
urle = s3Prefix + urle
}
display, tooltip := urle, urle
if err := file.SetCellValue(sheet, cell, response[index].Content); err != nil {
fmt.Println(err.Error())