diff --git a/app/app.go b/app/app.go index fa04d5e..cc42572 100644 --- a/app/app.go +++ b/app/app.go @@ -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) diff --git a/service/result_svc.go b/service/result_svc.go index 59f5ab8..f5521d4 100644 --- a/service/result_svc.go +++ b/service/result_svc.go @@ -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") } diff --git a/service/service.go b/service/service.go index a99ffad..db42bc6 100644 --- a/service/service.go +++ b/service/service.go @@ -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, } } diff --git a/tools/tools.go b/tools/tools.go index 85c0bc5..0ca0e31 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -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())