added s3prefix for file if this url and do not have hhtps prefix
This commit is contained in:
parent
7897dc2cb1
commit
cf974729bd
@ -69,6 +69,7 @@ type Options struct {
|
|||||||
TrashLogHost string `env:"TRASH_LOG_HOST" default:"localhost:7113"`
|
TrashLogHost string `env:"TRASH_LOG_HOST" default:"localhost:7113"`
|
||||||
ModuleLogger string `env:"MODULE_LOGGER" default:"core-local"`
|
ModuleLogger string `env:"MODULE_LOGGER" default:"core-local"`
|
||||||
ClickHouseCred string `env:"CLICK_HOUSE_CRED" default:"tcp://10.8.0.15:9000/default?sslmode=disable"`
|
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) {
|
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,
|
Producer: producer,
|
||||||
ServiceName: options.ServiceName,
|
ServiceName: options.ServiceName,
|
||||||
ChDAL: chDal,
|
ChDAL: chDal,
|
||||||
|
S3Prefix: options.S3Prefix,
|
||||||
})
|
})
|
||||||
|
|
||||||
svc.Register(app)
|
svc.Register(app)
|
||||||
|
@ -177,7 +177,7 @@ func (s *Service) ExportResultsToCSV(ctx *fiber.Ctx) error {
|
|||||||
|
|
||||||
buffer := new(bytes.Buffer)
|
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")
|
return ctx.Status(fiber.StatusInternalServerError).SendString("failed to write data to Excel")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ type Service struct {
|
|||||||
producer *brokers.Producer
|
producer *brokers.Producer
|
||||||
serviceName string
|
serviceName string
|
||||||
chDAL *dal.ClickHouseDAL
|
chDAL *dal.ClickHouseDAL
|
||||||
|
s3Prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Deps struct {
|
type Deps struct {
|
||||||
@ -22,6 +23,7 @@ type Deps struct {
|
|||||||
Producer *brokers.Producer
|
Producer *brokers.Producer
|
||||||
ServiceName string
|
ServiceName string
|
||||||
ChDAL *dal.ClickHouseDAL
|
ChDAL *dal.ClickHouseDAL
|
||||||
|
S3Prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(deps Deps) *Service {
|
func New(deps Deps) *Service {
|
||||||
@ -31,6 +33,7 @@ func New(deps Deps) *Service {
|
|||||||
producer: deps.Producer,
|
producer: deps.Producer,
|
||||||
serviceName: deps.ServiceName,
|
serviceName: deps.ServiceName,
|
||||||
chDAL: deps.ChDAL,
|
chDAL: deps.ChDAL,
|
||||||
|
s3Prefix: deps.S3Prefix,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ const (
|
|||||||
bucketAnswers = "squizanswer"
|
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()
|
file := excelize.NewFile()
|
||||||
sheet := "Sheet1"
|
sheet := "Sheet1"
|
||||||
|
|
||||||
@ -130,6 +130,9 @@ func WriteDataToExcel(buffer io.Writer, questions []model.Question, answers []mo
|
|||||||
}
|
}
|
||||||
} else if tipe != "Text" && q.Type == model.TypeFile {
|
} else if tipe != "Text" && q.Type == model.TypeFile {
|
||||||
urle := ExtractImageURL(response[index].Content)
|
urle := ExtractImageURL(response[index].Content)
|
||||||
|
if urle != "" && !strings.HasPrefix(urle, "https") {
|
||||||
|
urle = s3Prefix + urle
|
||||||
|
}
|
||||||
display, tooltip := urle, urle
|
display, tooltip := urle, urle
|
||||||
if err := file.SetCellValue(sheet, cell, response[index].Content); err != nil {
|
if err := file.SetCellValue(sheet, cell, response[index].Content); err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
|
Loading…
Reference in New Issue
Block a user